From 27e81875cb1b2eea9f05265f5e5490a02caac992 Mon Sep 17 00:00:00 2001 From: Shruthiiii03 Date: Mon, 11 Nov 2024 16:18:13 +0800 Subject: [PATCH 1/4] Update equality check for person --- .../java/seedu/address/model/person/Person.java | 11 ++++++----- .../duplicatePersonAddressBook.json | 2 +- .../seedu/address/model/person/PersonTest.java | 17 ++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 16e234f5410..31d27277997 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -190,16 +190,17 @@ public HashMap getAttendances() { } /** - * Returns true if both persons have the same name. + * Returns true if both persons have the same register number and class. * This defines a weaker notion of equality between two persons. */ public boolean isSamePerson(Person otherPerson) { - if (otherPerson == this) { - return true; + if (otherPerson == null) { + return false; } - return otherPerson != null - && otherPerson.getName().equals(getName()); + boolean sameClass = (otherPerson.getStudentClass().equals(this.getStudentClass())); + boolean sameRegNo = (otherPerson.getRegisterNumber().equals(this.getRegisterNumber())); + return sameClass && sameRegNo; } /** diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index d8d460af696..e20bde036f4 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -1,6 +1,6 @@ { "persons": [ { - "name": "Alice Pauline", + "name": "Alice Jaline", "phone": "94351253", "email": "alice@example.com", "address": "123, Jurong West Ave 6, #08-111", diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java index 43102725ab9..85de968a443 100644 --- a/src/test/java/seedu/address/model/person/PersonTest.java +++ b/src/test/java/seedu/address/model/person/PersonTest.java @@ -35,24 +35,19 @@ public void isSamePerson() { // null -> returns false assertFalse(ALICE.isSamePerson(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).withRegisterNumber(VALID_REGISTER_NUMBER_BOB).withSex(VALID_SEX_BOB) .withStudentClass(VALID_STUDENT_CLASS_BOB).withTags(VALID_TAG_HUSBAND).build(); - assertTrue(ALICE.isSamePerson(editedAlice)); + assertFalse(ALICE.isSamePerson(editedAlice)); - // different name, all other attributes same -> returns false + // same class and register number -> returns true editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build(); - assertFalse(ALICE.isSamePerson(editedAlice)); + assertTrue(ALICE.isSamePerson(editedAlice)); - // name differs in case, all other attributes same -> returns false + // name differs in case, same class and register number -> returns true Person editedBob = new PersonBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build(); - assertFalse(BOB.isSamePerson(editedBob)); - - // name has trailing spaces, all other attributes same -> returns false - String nameWithTrailingSpaces = VALID_NAME_BOB + " "; - editedBob = new PersonBuilder(BOB).withName(nameWithTrailingSpaces).build(); - assertFalse(BOB.isSamePerson(editedBob)); + assertTrue(BOB.isSamePerson(editedBob)); } @Test From b911dae67af1bc19f961c8f665f19ad3f35983b5 Mon Sep 17 00:00:00 2001 From: Shruthiiii03 Date: Mon, 11 Nov 2024 17:51:49 +0800 Subject: [PATCH 2/4] Update equality for person --- .../seedu/address/model/person/Person.java | 7 ++++-- .../address/model/person/PersonTest.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 31d27277997..32225974aa2 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -190,7 +190,7 @@ public HashMap getAttendances() { } /** - * Returns true if both persons have the same register number and class. + * Returns true if both persons have the same register number and class, or same phone numbers, or same emails. * This defines a weaker notion of equality between two persons. */ public boolean isSamePerson(Person otherPerson) { @@ -200,7 +200,10 @@ public boolean isSamePerson(Person otherPerson) { boolean sameClass = (otherPerson.getStudentClass().equals(this.getStudentClass())); boolean sameRegNo = (otherPerson.getRegisterNumber().equals(this.getRegisterNumber())); - return sameClass && sameRegNo; + boolean samePhone = (otherPerson.getPhone().equals(this.getPhone())); + boolean sameEmail = (otherPerson.getEmail().equals(this.getEmail())); + + return sameClass && sameRegNo || samePhone || sameEmail; } /** diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java index 85de968a443..2e5c16add6b 100644 --- a/src/test/java/seedu/address/model/person/PersonTest.java +++ b/src/test/java/seedu/address/model/person/PersonTest.java @@ -4,15 +4,19 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_REGISTER_NUMBER_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_REGISTER_NUMBER_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_SEX_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_STUDENT_CLASS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.AMY; import static seedu.address.testutil.TypicalPersons.BOB; import org.junit.jupiter.api.Test; @@ -48,6 +52,24 @@ public void isSamePerson() { // name differs in case, same class and register number -> returns true Person editedBob = new PersonBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build(); assertTrue(BOB.isSamePerson(editedBob)); + + // same phone numbers, other attributes different -> return true + Person diffPhoneBob = new PersonBuilder(BOB).withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_BOB) + .withAddress(VALID_ADDRESS_BOB).withRegisterNumber(VALID_REGISTER_NUMBER_BOB).withSex(VALID_SEX_BOB) + .withStudentClass(VALID_STUDENT_CLASS_BOB).withTags(VALID_TAG_HUSBAND).build(); + assertTrue(AMY.isSamePerson(diffPhoneBob)); + + // same emails -> return true + Person diffEmailBob = new PersonBuilder(BOB).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY) + .withAddress(VALID_ADDRESS_BOB).withRegisterNumber(VALID_REGISTER_NUMBER_BOB).withSex(VALID_SEX_BOB) + .withStudentClass(VALID_STUDENT_CLASS_BOB).withTags(VALID_TAG_HUSBAND).build(); + assertTrue(AMY.isSamePerson(diffEmailBob)); + + // diff register number and phone number and email -> return false + Person diffPerson = new PersonBuilder(BOB).withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY) + .withAddress(VALID_ADDRESS_BOB).withRegisterNumber(VALID_REGISTER_NUMBER_AMY).withSex(VALID_SEX_BOB) + .withStudentClass(VALID_STUDENT_CLASS_BOB).withTags(VALID_TAG_HUSBAND).build(); + assertFalse(BOB.isSamePerson(diffPerson)); } @Test From d863f7d8ba18512074ed86503da9366d3fcfb94b Mon Sep 17 00:00:00 2001 From: Shruthiiii03 Date: Mon, 11 Nov 2024 18:58:00 +0800 Subject: [PATCH 3/4] Add brackets for conditions --- src/main/java/seedu/address/model/person/Person.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 32225974aa2..103d36e08da 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -203,7 +203,7 @@ public boolean isSamePerson(Person otherPerson) { boolean samePhone = (otherPerson.getPhone().equals(this.getPhone())); boolean sameEmail = (otherPerson.getEmail().equals(this.getEmail())); - return sameClass && sameRegNo || samePhone || sameEmail; + return (sameClass && sameRegNo) || samePhone || sameEmail; } /** From aee76834c3e4d9b2ea2ac602828b277a934549fd Mon Sep 17 00:00:00 2001 From: Shruthiiii03 Date: Mon, 11 Nov 2024 21:42:55 +0800 Subject: [PATCH 4/4] Improve naming of variables --- src/main/java/seedu/address/model/person/Person.java | 10 +++++----- .../duplicatePersonAddressBook.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 103d36e08da..58c9ea65637 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -198,12 +198,12 @@ public boolean isSamePerson(Person otherPerson) { return false; } - boolean sameClass = (otherPerson.getStudentClass().equals(this.getStudentClass())); - boolean sameRegNo = (otherPerson.getRegisterNumber().equals(this.getRegisterNumber())); - boolean samePhone = (otherPerson.getPhone().equals(this.getPhone())); - boolean sameEmail = (otherPerson.getEmail().equals(this.getEmail())); + boolean isSameClass = (otherPerson.getStudentClass().equals(this.getStudentClass())); + boolean isSameRegNo = (otherPerson.getRegisterNumber().equals(this.getRegisterNumber())); + boolean isSamePhone = (otherPerson.getPhone().equals(this.getPhone())); + boolean isSameEmail = (otherPerson.getEmail().equals(this.getEmail())); - return (sameClass && sameRegNo) || samePhone || sameEmail; + return (isSameClass && isSameRegNo) || isSamePhone || isSameEmail; } /** diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index e20bde036f4..d8d460af696 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -1,6 +1,6 @@ { "persons": [ { - "name": "Alice Jaline", + "name": "Alice Pauline", "phone": "94351253", "email": "alice@example.com", "address": "123, Jurong West Ave 6, #08-111",