diff --git a/docs/tutorials/TracingCode.md b/docs/tutorials/TracingCode.md
index 4fb62a83ef6..148dde99e29 100644
--- a/docs/tutorials/TracingCode.md
+++ b/docs/tutorials/TracingCode.md
@@ -85,7 +85,7 @@ Now let’s set the breakpoint. First, double-click the item to reach the corres
## Tracing the execution path
-Recall from the User Guide that the `edit` command has the format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…` For this tutorial we will be issuing the command `edit 1 n/Alice Yeoh`.
+Recall from the User Guide that the `edit` command has the format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS]…` For this tutorial we will be issuing the command `edit 1 n/Alice Yeoh`.
diff --git a/src/main/java/seedu/address/logic/commands/AddAssignmentsCommand.java b/src/main/java/seedu/address/logic/commands/AddAssignmentsCommand.java
index 23df92e6556..808a16a0883 100644
--- a/src/main/java/seedu/address/logic/commands/AddAssignmentsCommand.java
+++ b/src/main/java/seedu/address/logic/commands/AddAssignmentsCommand.java
@@ -84,7 +84,7 @@ public boolean test(Person person) {
}
Student currPosition = (Student) personToEdit.getPosition();
Student editedPosition = new Student(currPosition.getAttendance(),
- currPosition.getOverallGrade(),
+ "0/0",
currPosition.setAssignments(assignments), filePath1);
diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java
index 299cbeaca3f..853c3823d19 100644
--- a/src/main/java/seedu/address/logic/commands/EditCommand.java
+++ b/src/main/java/seedu/address/logic/commands/EditCommand.java
@@ -50,6 +50,8 @@ public class EditCommand extends Command {
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in TAB.";
+ public static final String MESSAGE_DUPLICATE_PHONE = "This person's Phone already exists in TAB.";
+ public static final String MESSAGE_DUPLICATE_EMAIL = "This person's Email already exists in TAB.";
private final Index index;
private final EditPersonDescriptor editPersonDescriptor;
@@ -82,6 +84,14 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
+ if (!personToEdit.hasSameEmail(editedPerson) && model.hasEmail(editedPerson)) {
+ throw new CommandException(MESSAGE_DUPLICATE_EMAIL);
+ }
+
+ if (!personToEdit.hasSamePhone(editedPerson) && model.hasPhone(editedPerson)) {
+ throw new CommandException(MESSAGE_DUPLICATE_PHONE);
+ }
+
model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java
index 1a943a0781a..594b7ccd7e0 100644
--- a/src/main/java/seedu/address/model/AddressBook.java
+++ b/src/main/java/seedu/address/model/AddressBook.java
@@ -66,6 +66,21 @@ public boolean hasPerson(Person person) {
return persons.contains(person);
}
+ /**
+ * Returns true if a person with the same email as {@code person} exists in the address book.
+ */
+ public boolean hasEmail(Person person) {
+ requireNonNull(person);
+ return persons.containsEmail(person);
+ }
+
+ /**
+ * Returns true if a person with the same phone as {@code person} exists in the address book.
+ */
+ public boolean hasPhone(Person person) {
+ requireNonNull(person);
+ return persons.containsPhone(person);
+ }
/**
* Adds a person to the address book.
* The person must not already exist in the address book.
diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java
index 3ec9f1076cf..ce3814d4169 100644
--- a/src/main/java/seedu/address/model/Model.java
+++ b/src/main/java/seedu/address/model/Model.java
@@ -79,6 +79,16 @@ public interface Model {
*/
boolean hasPerson(Person person);
+ /**
+ * Returns true if a person with the same email as {@code person} exists in the address book.
+ */
+ boolean hasEmail(Person person);
+
+ /**
+ * Returns true if a person with the same phone as {@code person} exists in the address book.
+ */
+ boolean hasPhone(Person person);
+
/**
* Deletes the given person.
* The person must exist in the address book.
diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java
index ef8ae748b70..ae70755ce05 100644
--- a/src/main/java/seedu/address/model/ModelManager.java
+++ b/src/main/java/seedu/address/model/ModelManager.java
@@ -128,6 +128,18 @@ public boolean hasPerson(Person person) {
return addressBook.hasPerson(person);
}
+ @Override
+ public boolean hasPhone(Person person) {
+ requireNonNull(person);
+ return addressBook.hasPhone(person);
+ }
+
+ @Override
+ public boolean hasEmail(Person person) {
+ requireNonNull(person);
+ return addressBook.hasEmail(person);
+ }
+
@Override
public void deletePerson(Person target) {
addressBook.removePerson(target);
diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java
index 91c2a52cdcf..9a25e316622 100644
--- a/src/main/java/seedu/address/model/person/Person.java
+++ b/src/main/java/seedu/address/model/person/Person.java
@@ -93,9 +93,21 @@ public boolean isSamePerson(Person otherPerson) {
}
return otherPerson != null
- && (otherPerson.getName().equals(getName())
- || otherPerson.getEmail().equals(getEmail())
- || otherPerson.getPhone().equals(getPhone()));
+ && otherPerson.getName().equals(getName());
+ }
+
+ /**
+ * Returns true if both persons have the same phone.
+ */
+ public boolean hasSamePhone(Person otherPerson) {
+ return phone.equals(otherPerson.getPhone());
+ }
+
+ /**
+ * Returns true if both persons have the same email.
+ */
+ public boolean hasSameEmail(Person otherPerson) {
+ return email.equals(otherPerson.getEmail());
}
/**
diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java
index 0fee4fe57e6..cd9c99de694 100644
--- a/src/main/java/seedu/address/model/person/UniquePersonList.java
+++ b/src/main/java/seedu/address/model/person/UniquePersonList.java
@@ -36,6 +36,22 @@ public boolean contains(Person toCheck) {
return internalList.stream().anyMatch(toCheck::isSamePerson);
}
+ /**
+ * Returns true if the list contains an equivalent email as the given argument.
+ */
+ public boolean containsEmail(Person toCheck) {
+ requireNonNull(toCheck);
+ return internalList.stream().anyMatch(toCheck::hasSameEmail);
+ }
+
+ /**
+ * Returns true if the list contains an equivalent phone as the given argument.
+ */
+ public boolean containsPhone(Person toCheck) {
+ requireNonNull(toCheck);
+ return internalList.stream().anyMatch(toCheck::hasSamePhone);
+ }
+
/**
* Adds a person to the list.
* The person must not already exist in the list.
diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java
index d2ec50e792c..d2fbe6612e6 100644
--- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java
+++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java
@@ -158,6 +158,16 @@ public boolean hasPerson(Person person) {
throw new AssertionError("This method should not be called.");
}
+ @Override
+ public boolean hasEmail(Person person) {
+ throw new AssertionError("This method should not be called.");
+ }
+
+ @Override
+ public boolean hasPhone(Person person) {
+ throw new AssertionError("This method should not be called.");
+ }
+
@Override
public void deletePerson(Person target) {
throw new AssertionError("This method should not be called.");
diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java
index 6dba0b4fc0d..181dcecec58 100644
--- a/src/test/java/seedu/address/model/person/PersonTest.java
+++ b/src/test/java/seedu/address/model/person/PersonTest.java
@@ -36,18 +36,13 @@ public void isSamePerson() {
.withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND).build();
assertTrue(ALICE.isSamePerson(editedAlice));
- // different name, all other attributes same -> returns true
+ // different name, all other attributes same -> returns false
editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build();
- assertTrue(ALICE.isSamePerson(editedAlice));
+ assertFalse(ALICE.isSamePerson(editedAlice));
- // name differs in case, all other attributes same -> returns true
+ // name differs in case, all other attributes same -> returns false
Person editedBob = new PersonBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build();
- assertTrue(BOB.isSamePerson(editedBob));
-
- // name has trailing spaces, all other attributes same -> returns true
- String nameWithTrailingSpaces = VALID_NAME_BOB + " ";
- editedBob = new PersonBuilder(BOB).withName(nameWithTrailingSpaces).build();
- assertTrue(BOB.isSamePerson(editedBob));
+ assertFalse(BOB.isSamePerson(editedBob));
}
@Test