Skip to content

Commit

Permalink
Merge pull request #60 from chrisjohntan/add-check-duplicate-phone
Browse files Browse the repository at this point in the history
Check for duplicate phone number
  • Loading branch information
KrashKart authored Oct 10, 2024
2 parents ad8652e + e5c45ec commit 779c744
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 20 additions & 5 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,34 @@ public boolean isSamePerson(Person otherPerson) {
}

/**
* Returns true if both person have the same email address.
* This is to check for duplicates in emails in the contact list.
* Checks for duplicates in emails in the contact list.
* @param otherPerson The Person object to compare against.
* @return True if both persons have the same email address.
*/
public boolean hasSameEmail(Person otherPerson) {
return otherPerson != null && otherPerson.getEmail().equals(this.getEmail());
}

/**
* Returns true if two contacts are considered as duplicates.
* This is to avoid adding duplicate contact in the contact list.
* Checks for duplicates in phone numbers in the contact list.
* @param otherPerson The Person object to compare against.
* @return True if both persons have the same phone number.
*/
public boolean hasSamePhoneNumber(Person otherPerson) {
return otherPerson != null && otherPerson.getPhone().equals(this.getPhone());
}

/**
* Checks for duplicated contact information between Person instances.
* This is to avoid adding duplicate contacts in the contact list.
* Checked fields: name, phone, email.
* @param otherPerson The Person object to compare against.
* @return True if two contacts are considered as duplicates.
*/
public boolean hasDuplicateInfo(Person otherPerson) {
return this.isSamePerson(otherPerson) || this.hasSameEmail(otherPerson);
return this.isSamePerson(otherPerson)
|| this.hasSameEmail(otherPerson)
|| this.hasSamePhoneNumber(otherPerson);
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,16 @@ public void execute_filteredList_success() {
Person personInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());

Person editedPerson = new PersonBuilder(personInFilteredList)
.withName(VALID_NAME_BOB).withEmail(VALID_EMAIL_BOB).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON,
new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).withEmail(VALID_EMAIL_BOB).build());
.withName(VALID_NAME_BOB)
.withEmail(VALID_EMAIL_BOB)
.withPhone(VALID_PHONE_BOB).build();
EditCommand editCommand = new EditCommand(
INDEX_FIRST_PERSON,
new EditPersonDescriptorBuilder()
.withName(VALID_NAME_BOB)
.withEmail(VALID_EMAIL_BOB)
.withPhone(VALID_PHONE_BOB).build()
);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

Expand Down

0 comments on commit 779c744

Please sign in to comment.