Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Rename Model#getFilteredPersonList() and Logic#getFilteredPersonList() #1013

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface Logic {
*/
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
/** Returns an unmodifiable view of the filtered list of persons to be displayed. */
ObservableList<Person> getDisplayPersonList();

/**
* Returns an unmodifiable view of the list of commands entered by the user.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public ReadOnlyAddressBook getAddressBook() {
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
public ObservableList<Person> getDisplayPersonList() {
return model.getDisplayPersonList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
List<Person> lastShownList = model.getDisplayPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
List<Person> lastShownList = model.getDisplayPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getDisplayPersonList().size()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SelectCommand(Index targetIndex) {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

List<Person> filteredPersonList = model.getFilteredPersonList();
List<Person> filteredPersonList = model.getDisplayPersonList();

if (targetIndex.getZeroBased() >= filteredPersonList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public interface Model {
*/
void setPerson(Person target, Person editedPerson);

/** Returns an unmodifiable view of the filtered person list */
ObservableList<Person> getFilteredPersonList();
/** Returns an unmodifiable view of the filtered list of persons to be displayed. */
ObservableList<Person> getDisplayPersonList();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void setPerson(Person target, Person editedPerson) {
* {@code versionedAddressBook}
*/
@Override
public ObservableList<Person> getFilteredPersonList() {
public ObservableList<Person> getDisplayPersonList() {
return filteredPersons;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void fillInnerParts() {
browserPanel = new BrowserPanel(logic.selectedPersonProperty());
browserPlaceholder.getChildren().add(browserPanel.getRoot());

personListPanel = new PersonListPanel(logic.getFilteredPersonList(), logic.selectedPersonProperty(),
personListPanel = new PersonListPanel(logic.getDisplayPersonList(), logic.selectedPersonProperty(),
logic::setSelectedPerson);
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Path getStorageSaveLocation() {
*/
public Model getModel() {
Model copy = new ModelManager((model.getAddressBook()), new UserPrefs());
ModelHelper.setFilteredList(copy, model.getFilteredPersonList());
ModelHelper.setFilteredList(copy, model.getDisplayPersonList());
return copy;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void execute_storageThrowsIoException_throwsCommandException() {

@Test
public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException() {
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredPersonList().remove(0));
assertThrows(UnsupportedOperationException.class, () -> logic.getDisplayPersonList().remove(0));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void setPerson(Person target, Person editedPerson) {
}

@Override
public ObservableList<Person> getFilteredPersonList() {
public ObservableList<Person> getDisplayPersonList() {
throw new AssertionError("This method should not be called.");
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public static void assertCommandFailure(Command command, Model actualModel, Comm
// we are unable to defensively copy the model for comparison later, so we can
// only do so by copying its components.
AddressBook expectedAddressBook = new AddressBook(actualModel.getAddressBook());
List<Person> expectedFilteredList = new ArrayList<>(actualModel.getFilteredPersonList());
List<Person> expectedFilteredList = new ArrayList<>(actualModel.getDisplayPersonList());
Person expectedSelectedPerson = actualModel.getSelectedPerson();

CommandHistory expectedCommandHistory = new CommandHistory(actualCommandHistory);

assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel, actualCommandHistory));
assertEquals(expectedAddressBook, actualModel.getAddressBook());
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
assertEquals(expectedFilteredList, actualModel.getDisplayPersonList());
assertEquals(expectedSelectedPerson, actualModel.getSelectedPerson());
assertEquals(expectedCommandHistory, actualCommandHistory);
}
Expand All @@ -127,20 +127,20 @@ public static void assertCommandFailure(Command command, Model actualModel, Comm
* {@code model}'s address book.
*/
public static void showPersonAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredPersonList().size());
assertTrue(targetIndex.getZeroBased() < model.getDisplayPersonList().size());

Person person = model.getFilteredPersonList().get(targetIndex.getZeroBased());
Person person = model.getDisplayPersonList().get(targetIndex.getZeroBased());
final String[] splitName = person.getName().fullName.split("\\s+");
model.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));

assertEquals(1, model.getFilteredPersonList().size());
assertEquals(1, model.getDisplayPersonList().size());
}

/**
* Deletes the first person in {@code model}'s filtered list from {@code model}'s address book.
*/
public static void deleteFirstPerson(Model model) {
Person firstPerson = model.getFilteredPersonList().get(0);
Person firstPerson = model.getDisplayPersonList().get(0);
model.deletePerson(firstPerson);
model.commitAddressBook();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DeleteCommandTest {

@Test
public void execute_validIndexUnfilteredList_success() {
Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToDelete = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete);
Expand All @@ -45,7 +45,7 @@ public void execute_validIndexUnfilteredList_success() {

@Test
public void execute_invalidIndexUnfilteredList_throwsCommandException() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
Index outOfBoundIndex = Index.fromOneBased(model.getDisplayPersonList().size() + 1);
DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex);

assertCommandFailure(deleteCommand, model, commandHistory, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand All @@ -55,7 +55,7 @@ public void execute_invalidIndexUnfilteredList_throwsCommandException() {
public void execute_validIndexFilteredList_success() {
showPersonAtIndex(model, INDEX_FIRST_PERSON);

Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToDelete = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete);
Expand Down Expand Up @@ -83,7 +83,7 @@ public void execute_invalidIndexFilteredList_throwsCommandException() {

@Test
public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception {
Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToDelete = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.deletePerson(personToDelete);
Expand All @@ -103,7 +103,7 @@ public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception

@Test
public void executeUndoRedo_invalidIndexUnfilteredList_failure() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
Index outOfBoundIndex = Index.fromOneBased(model.getDisplayPersonList().size() + 1);
DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex);

// execution failed -> address book state not added into model
Expand All @@ -127,7 +127,7 @@ public void executeUndoRedo_validIndexFilteredList_samePersonDeleted() throws Ex
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());

showPersonAtIndex(model, INDEX_SECOND_PERSON);
Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToDelete = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
expectedModel.deletePerson(personToDelete);
expectedModel.commitAddressBook();

Expand All @@ -138,7 +138,7 @@ public void executeUndoRedo_validIndexFilteredList_samePersonDeleted() throws Ex
expectedModel.undoAddressBook();
assertCommandSuccess(new UndoCommand(), model, commandHistory, UndoCommand.MESSAGE_SUCCESS, expectedModel);

assertNotEquals(personToDelete, model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()));
assertNotEquals(personToDelete, model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased()));
// redo -> deletes same second person in unfiltered person list
expectedModel.redoAddressBook();
assertCommandSuccess(new RedoCommand(), model, commandHistory, RedoCommand.MESSAGE_SUCCESS, expectedModel);
Expand Down Expand Up @@ -172,6 +172,6 @@ public void equals() {
private void showNoPerson(Model model) {
model.updateFilteredPersonList(p -> false);

assertTrue(model.getFilteredPersonList().isEmpty());
assertTrue(model.getDisplayPersonList().isEmpty());
}
}
24 changes: 12 additions & 12 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedPerson);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson);
expectedModel.setPerson(model.getDisplayPersonList().get(0), editedPerson);
expectedModel.commitAddressBook();

assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}

@Test
public void execute_someFieldsSpecifiedUnfilteredList_success() {
Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size());
Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased());
Index indexLastPerson = Index.fromOneBased(model.getDisplayPersonList().size());
Person lastPerson = model.getDisplayPersonList().get(indexLastPerson.getZeroBased());

PersonBuilder personInList = new PersonBuilder(lastPerson);
Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
Expand All @@ -77,7 +77,7 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
@Test
public void execute_noFieldSpecifiedUnfilteredList_success() {
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, new EditPersonDescriptor());
Person editedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person editedPerson = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());

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

Expand All @@ -91,23 +91,23 @@ public void execute_noFieldSpecifiedUnfilteredList_success() {
public void execute_filteredList_success() {
showPersonAtIndex(model, INDEX_FIRST_PERSON);

Person personInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personInFilteredList = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person editedPerson = new PersonBuilder(personInFilteredList).withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON,
new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build());

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

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson);
expectedModel.setPerson(model.getDisplayPersonList().get(0), editedPerson);
expectedModel.commitAddressBook();

assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}

@Test
public void execute_duplicatePersonUnfilteredList_failure() {
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person firstPerson = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).build();
EditCommand editCommand = new EditCommand(INDEX_SECOND_PERSON, descriptor);

Expand All @@ -128,7 +128,7 @@ public void execute_duplicatePersonFilteredList_failure() {

@Test
public void execute_invalidPersonIndexUnfilteredList_failure() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
Index outOfBoundIndex = Index.fromOneBased(model.getDisplayPersonList().size() + 1);
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor);

Expand All @@ -155,7 +155,7 @@ public void execute_invalidPersonIndexFilteredList_failure() {
@Test
public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception {
Person editedPerson = new PersonBuilder().build();
Person personToEdit = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToEdit = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor);
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
Expand All @@ -176,7 +176,7 @@ public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception

@Test
public void executeUndoRedo_invalidIndexUnfilteredList_failure() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
Index outOfBoundIndex = Index.fromOneBased(model.getDisplayPersonList().size() + 1);
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor);

Expand All @@ -203,7 +203,7 @@ public void executeUndoRedo_validIndexFilteredList_samePersonEdited() throws Exc
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());

showPersonAtIndex(model, INDEX_SECOND_PERSON);
Person personToEdit = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToEdit = model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
expectedModel.setPerson(personToEdit, editedPerson);
expectedModel.commitAddressBook();

Expand All @@ -214,7 +214,7 @@ public void executeUndoRedo_validIndexFilteredList_samePersonEdited() throws Exc
expectedModel.undoAddressBook();
assertCommandSuccess(new UndoCommand(), model, commandHistory, UndoCommand.MESSAGE_SUCCESS, expectedModel);

assertNotEquals(model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()), personToEdit);
assertNotEquals(model.getDisplayPersonList().get(INDEX_FIRST_PERSON.getZeroBased()), personToEdit);
// redo -> edits same second person in unfiltered person list
expectedModel.redoAddressBook();
assertCommandSuccess(new RedoCommand(), model, commandHistory, RedoCommand.MESSAGE_SUCCESS, expectedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void execute_zeroKeywords_noPersonFound() {
FindCommand command = new FindCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(command, model, commandHistory, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredPersonList());
assertEquals(Collections.emptyList(), model.getDisplayPersonList());
}

@Test
Expand All @@ -73,7 +73,7 @@ public void execute_multipleKeywords_multiplePersonsFound() {
FindCommand command = new FindCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(command, model, commandHistory, expectedMessage, expectedModel);
assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList());
assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getDisplayPersonList());
}

/**
Expand Down
Loading