From 5ffbc0e7b1ce0ad578ad2f9bb98132c50d5a0ed1 Mon Sep 17 00:00:00 2001 From: KrashKart Date: Thu, 10 Oct 2024 00:05:21 +0800 Subject: [PATCH] Add AbstractFindCommand Temporary so the code does not break --- .../logic/commands/AbstractFindCommand.java | 58 +++++++++++++++++++ .../address/logic/commands/FindCommand.java | 4 +- 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/AbstractFindCommand.java diff --git a/src/main/java/seedu/address/logic/commands/AbstractFindCommand.java b/src/main/java/seedu/address/logic/commands/AbstractFindCommand.java new file mode 100644 index 00000000000..082b2b6a25e --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/AbstractFindCommand.java @@ -0,0 +1,58 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.Messages; +import seedu.address.model.Model; +import seedu.address.model.person.ContainsKeywordsPredicate; + +/** + * Finds and lists all persons in address book whose name contains any of the argument keywords. + * Keyword matching is case-insensitive. + */ +abstract public class AbstractFindCommand extends Command { + + public static final String COMMAND_WORD = "find"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names, contacts or emails " + + "contain any of the specified keywords (case-insensitive) and displays them as a list with indices.\n" + + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + + "Example: " + COMMAND_WORD + " alice bob charlie"; + + private final ContainsKeywordsPredicate predicate; + + public AbstractFindCommand(ContainsKeywordsPredicate predicate) { + this.predicate = predicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredPersonList(this.predicate); + return new CommandResult( + String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof AbstractFindCommand)) { + return false; + } + + AbstractFindCommand otherFindCommand = (AbstractFindCommand) other; + return this.predicate.equals(otherFindCommand.predicate); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("predicate", this.predicate) + .toString(); + } +} diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index 5eb1886d12c..8595cd020f8 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -9,9 +9,9 @@ /** * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case insensitive. + * Keyword matching is case-insensitive. */ -abstract public class FindCommand extends Command { +public class FindCommand extends Command { public static final String COMMAND_WORD = "find";