Skip to content

Commit

Permalink
Update isSamePerson() equality for Person class
Browse files Browse the repository at this point in the history
The person equality check returns true if the name or the email
matches. The OR condition complicates the equality check done when
editing a person as it assumes isSamePerson() to have a transitive
relation.

Alternative 1: Improve the way the equality check is done in the edit
command to prevent the above bug. (PRs nus-cs2103-AY2122S2#68, nus-cs2103-AY2122S2#69)

Alternative 2: Simplify the equality check by removing the OR condition.
This is simpler but possibly too strict for the address book domain
i.e., increases the risk of duplicate entries for the same person
creeping into the address book

We decided to go with the alternative 2 because,
* It is important to keep the code base simple, to reduce the initial
learning curve of the students at the start of their project
* Students can introduce a more sophisticated equality check that
matches their product domain later.

Also, let's change the default name in PersonBuilder utility class.
This is because AddCommandIntegrationTest populates its model using
getTypicalPersons() which contains a person with the default name.
This test then creates another person using the default name, to be
added into the model, which is expected to pass. However, the above
update in equality causes this test to fail. Thus we need to change the
default name to a unique name that is not inside getTypicalPersons().
Also, the default email is changed for consistency in naming the
default values, it does not affect current test cases.
  • Loading branch information
aditi2313 authored Feb 24, 2022
1 parent a4d8f8e commit 988c177
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ public class Person {

// Data fields
private final Address address;
private final Remark remark;
private final Set<Tag> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Remark remark, Set<Tag> tags) {
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.remark = remark;
this.tags.addAll(tags);
}

Expand All @@ -54,10 +52,6 @@ public Address getAddress() {
return address;
}

public Remark getRemark() {
return remark;
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
Expand Down Expand Up @@ -116,10 +110,7 @@ public String toString() {
.append("; Email: ")
.append(getEmail())
.append("; Address: ")
.append(getAddress())
.append(" Remark: ")
.append(getRemark());

.append(getAddress());

Set<Tag> tags = getTags();
if (!tags.isEmpty()) {
Expand Down

0 comments on commit 988c177

Please sign in to comment.