forked from nusCS2113-AY1819S1/addressbook-level4
/
FindAddressCommand.java
43 lines (34 loc) · 1.65 KB
/
FindAddressCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package seedu.address.logic.commands;
import static java.util.Objects.requireNonNull;
import seedu.address.commons.core.Messages;
import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;
import seedu.address.model.person.AddressContainsKeywordsPredicate;
/**
* Finds and lists all persons in address book whose address contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class FindAddressCommand extends Command {
public static final String COMMAND_WORD = "findaddress";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose address contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " College Geylang Kio ";
private final AddressContainsKeywordsPredicate predicate;
public FindAddressCommand(AddressContainsKeywordsPredicate predicate) {
this.predicate = predicate;
}
@Override
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()));
}
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof FindAddressCommand // instanceof handles nulls
&& predicate.equals(((FindAddressCommand) other).predicate)); // state check
}
}