From 13c5a22062913b1fc61156c6ce2898e59378df31 Mon Sep 17 00:00:00 2001 From: Jaehyeok Choi <77jack0105@gmail.com> Date: Tue, 5 Nov 2024 20:22:50 +0800 Subject: [PATCH] Adjust person duplicate --- .../java/seedu/address/model/person/Name.java | 3 ++- .../address/model/person/PersonDescriptor.java | 6 ++++-- .../seedu/address/model/person/PersonTest.java | 17 +++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/person/Name.java index d8f5e31cede..41f2aacb758 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/person/Name.java @@ -56,7 +56,8 @@ public boolean equals(Object other) { } Name otherName = (Name) other; - return fullName.equals(otherName.fullName); + return fullName.replaceAll("\\s+", "") + .equalsIgnoreCase(otherName.fullName.replaceAll("\\s+", "")); } @Override diff --git a/src/main/java/seedu/address/model/person/PersonDescriptor.java b/src/main/java/seedu/address/model/person/PersonDescriptor.java index 3ecf50d390b..22f683b8a7b 100644 --- a/src/main/java/seedu/address/model/person/PersonDescriptor.java +++ b/src/main/java/seedu/address/model/person/PersonDescriptor.java @@ -75,7 +75,8 @@ public boolean isSamePerson(PersonDescriptor otherPerson) { } return otherPerson != null - && otherPerson.getName().equals(getName()); + && otherPerson.getName().equals(getName()) + && otherPerson.getPhone().equals((getPhone())); } /** @@ -84,7 +85,8 @@ public boolean isSamePerson(PersonDescriptor otherPerson) { */ public boolean isSamePerson(Person otherPerson) { return otherPerson != null - && otherPerson.getName().equals(getName()); + && otherPerson.getName().equals(getName()) + && otherPerson.getPhone().equals(getPhone()); } /** diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java index e48c2baa9a5..c92dd571df4 100644 --- a/src/test/java/seedu/address/model/person/PersonTest.java +++ b/src/test/java/seedu/address/model/person/PersonTest.java @@ -35,23 +35,28 @@ public void isSamePerson() { // null -> returns false assertFalse(ALICE.isSamePerson((PersonDescriptor) null)); - // same name, all other attributes different -> returns true + // same name, all other attributes different -> returns False Person editedAlice = new PersonBuilder(ALICE).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB) .withAddress(VALID_ADDRESS_BOB).withStatus(VALID_STATUS_BOB).withTags(VALID_TAG_HUSBAND).build(); - assertTrue(ALICE.isSamePerson(editedAlice)); + assertFalse(ALICE.isSamePerson(editedAlice)); + + // same name, same phone, all other attributes different -> returns true + Person editedAliceNewPhone = new PersonBuilder(ALICE).withEmail(VALID_EMAIL_BOB) + .withAddress(VALID_ADDRESS_BOB).withStatus(VALID_STATUS_BOB).withTags(VALID_TAG_HUSBAND).build(); + assertTrue(ALICE.isSamePerson(editedAliceNewPhone)); // different name, all other attributes same -> returns false editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build(); assertFalse(ALICE.isSamePerson(editedAlice)); - // name differs in case, all other attributes same -> returns false + // name differs in case, all other attributes same -> returns true Person editedBob = new PersonBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build(); - assertFalse(BOB.isSamePerson(editedBob)); + assertTrue(BOB.isSamePerson(editedBob)); - // name has trailing spaces, all other attributes same -> returns false + // name has trailing spaces, all other attributes same -> returns true String nameWithTrailingSpaces = VALID_NAME_BOB + " "; editedBob = new PersonBuilder(BOB).withName(nameWithTrailingSpaces).build(); - assertFalse(BOB.isSamePerson(editedBob)); + assertTrue(BOB.isSamePerson(editedBob)); } @Test