Skip to content

Commit

Permalink
Change Model#addPerson(...) signature to ReadOnlyPerson
Browse files Browse the repository at this point in the history
Model#addPerson(Person) accepts a mutable Person object. Outside
classes are able to modify the Person object after inserting it into
the model.

Only Model should be able to modify the Person objects that it owns.

Let's change addPerson()'s signature from Person to ReadOnlyPerson, so
that the internal Person list is forced to duplicate this object,
satisfying our new constraint.
  • Loading branch information
yamgent committed May 19, 2017
1 parent 1d9a07f commit 9e158dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Set;

import seedu.address.commons.core.UnmodifiableObservableList;
import seedu.address.model.person.Person;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.person.UniquePersonList;
import seedu.address.model.person.UniquePersonList.DuplicatePersonException;
Expand All @@ -22,7 +21,7 @@ public interface Model {
void deletePerson(ReadOnlyPerson target) throws UniquePersonList.PersonNotFoundException;

/** Adds the given person */
void addPerson(Person person) throws UniquePersonList.DuplicatePersonException;
void addPerson(ReadOnlyPerson person) throws UniquePersonList.DuplicatePersonException;

/**
* Updates the person located at {@code filteredPersonListIndex} with {@code editedPerson}.
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import seedu.address.commons.events.model.AddressBookChangedEvent;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.commons.util.StringUtil;
import seedu.address.model.person.Person;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.person.UniquePersonList;
import seedu.address.model.person.UniquePersonList.PersonNotFoundException;
Expand Down Expand Up @@ -65,7 +64,7 @@ public synchronized void deletePerson(ReadOnlyPerson target) throws PersonNotFou
}

@Override
public synchronized void addPerson(Person person) throws UniquePersonList.DuplicatePersonException {
public synchronized void addPerson(ReadOnlyPerson person) throws UniquePersonList.DuplicatePersonException {
addressBook.addPerson(person);
updateFilteredListToShowAll();
indicateAddressBookChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private AddCommand getAddCommandForPerson(Person person, Model model) throws Ill
*/
private class ModelStub implements Model {
@Override
public void addPerson(Person person) throws DuplicatePersonException {
public void addPerson(ReadOnlyPerson person) throws DuplicatePersonException {
fail("This method should not be called.");
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public void updateFilteredPersonList(Set<String> keywords) {
*/
private class ModelStubThrowingDuplicatePersonException extends ModelStub {
@Override
public void addPerson(Person person) throws DuplicatePersonException {
public void addPerson(ReadOnlyPerson person) throws DuplicatePersonException {
throw new DuplicatePersonException();
}
}
Expand All @@ -129,8 +129,8 @@ private class ModelStubAcceptingPersonAdded extends ModelStub {
final ArrayList<Person> personsAdded = new ArrayList<>();

@Override
public void addPerson(Person person) throws DuplicatePersonException {
personsAdded.add(person);
public void addPerson(ReadOnlyPerson person) throws DuplicatePersonException {
personsAdded.add(new Person(person));
}
}

Expand Down

0 comments on commit 9e158dd

Please sign in to comment.