From 18359282ba1eb3029e2380d3a348db25e40b7da1 Mon Sep 17 00:00:00 2001 From: "YAMIDARK\\Jun An" Date: Tue, 9 Jan 2018 00:49:01 +0800 Subject: [PATCH] Model interface: Add method to get predicate of filteredPersonList The Model interface does not contain any method to get the predicate of its filteredPersonList. This prevents other classes from getting the predicate if necessary. Let's add a method in Model to get the predicate of its filteredPersonList --- src/main/java/seedu/address/model/Model.java | 3 +++ src/main/java/seedu/address/model/ModelManager.java | 5 +++++ .../seedu/address/logic/commands/AddCommandTest.java | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 9c6aa4e766a0..1b0121562e45 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -39,6 +39,9 @@ void updatePerson(ReadOnlyPerson target, ReadOnlyPerson editedPerson) /** Returns an unmodifiable view of the filtered person list */ ObservableList getFilteredPersonList(); + /** Returns the predicate used in the filtered person list */ + Predicate getFilteredPersonListPredicate(); + /** * Updates the filter of the filtered person list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 095c831cfbf8..fd9942950a2e 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -92,6 +92,11 @@ public ObservableList getFilteredPersonList() { return FXCollections.unmodifiableObservableList(filteredPersons); } + @Override + public Predicate getFilteredPersonListPredicate() { + return (Predicate) filteredPersons.getPredicate(); + } + @Override public void updateFilteredPersonList(Predicate predicate) { requireNonNull(predicate); diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index b327ef2d805b..52aee4b5356a 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -129,6 +129,12 @@ public ObservableList getFilteredPersonList() { return null; } + @Override + public Predicate getFilteredPersonListPredicate() { + fail("This method should not be called."); + return null; + } + @Override public void updateFilteredPersonList(Predicate predicate) { fail("This method should not be called."); @@ -148,6 +154,9 @@ public void addPerson(ReadOnlyPerson person) throws DuplicatePersonException { public ReadOnlyAddressBook getAddressBook() { return new AddressBook(); } + + @Override + public Predicate getFilteredPersonListPredicate() { return PREDICATE_SHOW_ALL_PERSONS; } } /** @@ -165,6 +174,9 @@ public void addPerson(ReadOnlyPerson person) throws DuplicatePersonException { public ReadOnlyAddressBook getAddressBook() { return new AddressBook(); } + + @Override + public Predicate getFilteredPersonListPredicate() { return PREDICATE_SHOW_ALL_PERSONS; } } }