diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 83427be5cef..68431b37271 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -12,5 +12,6 @@ public class Messages { public static final String MESSAGE_INVALID_REMINDER_DISPLAYED_INDEX = "The reminder index provided is invalid :("; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; public static final String MESSAGE_CCAS_LISTED_OVERVIEW = "%1$d CCAs listed!"; + public static final String MESSAGE_REMINDERS_LISTED_OVERVIEW = "%1$d reminders listed!"; } diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 818802b9f35..e76c3083a79 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -1,8 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CCAS; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static seedu.address.model.Model.*; import seedu.address.model.Model; @@ -13,7 +12,7 @@ public class ListCommand extends Command { public static final String COMMAND_WORD = "list"; - public static final String MESSAGE_SUCCESS = "Listed all persons and CCAs"; + public static final String MESSAGE_SUCCESS = "Listed all persons, CCAs and reminders"; @Override @@ -21,6 +20,7 @@ public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); model.updateFilteredCcaList(PREDICATE_SHOW_ALL_CCAS); + model.updateFilteredReminderList(PREDICATE_SHOW_ALL_REMINDERS); return new CommandResult(MESSAGE_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/commands/reminder/ReminderFindCommand.java b/src/main/java/seedu/address/logic/commands/reminder/ReminderFindCommand.java new file mode 100644 index 00000000000..a57598338e9 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/reminder/ReminderFindCommand.java @@ -0,0 +1,44 @@ +package seedu.address.logic.commands.reminder; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.model.Model; +import seedu.address.model.reminder.ReminderNameContainsKeywordsPredicate; + +/** + * Finds and lists all persons in address book whose name contains any of the argument keywords. + * Keyword matching is case insensitive. + */ +public class ReminderFindCommand extends Command { + + public static final String COMMAND_WORD = "findr"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all reminders whose titles 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 + " meeting"; + + private final ReminderNameContainsKeywordsPredicate predicate; + + public ReminderFindCommand(ReminderNameContainsKeywordsPredicate predicate) { + this.predicate = predicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredReminderList(predicate); + return new CommandResult( + String.format(Messages.MESSAGE_REMINDERS_LISTED_OVERVIEW, model.getFilteredReminderList().size())); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReminderFindCommand // instanceof handles nulls + && predicate.equals(((ReminderFindCommand) other).predicate)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/parser/.AddressBookParser.java.swp b/src/main/java/seedu/address/logic/parser/.AddressBookParser.java.swp deleted file mode 100644 index 7de3748ea39..00000000000 Binary files a/src/main/java/seedu/address/logic/parser/.AddressBookParser.java.swp and /dev/null differ diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 3d0d0a27ebc..7a55fd42173 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -2,7 +2,6 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; - import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -23,6 +22,7 @@ import seedu.address.logic.commands.person.PersonFindCommand; import seedu.address.logic.commands.reminder.ReminderAddCommand; import seedu.address.logic.commands.reminder.ReminderDeleteCommand; +import seedu.address.logic.commands.reminder.ReminderFindCommand; import seedu.address.logic.parser.cca.CcaAddCommandParser; import seedu.address.logic.parser.cca.CcaDeleteCommandParser; import seedu.address.logic.parser.cca.CcaEnrolCommandParser; @@ -35,6 +35,7 @@ import seedu.address.logic.parser.person.PersonFindCommandParser; import seedu.address.logic.parser.reminder.ReminderAddCommandParser; import seedu.address.logic.parser.reminder.ReminderDeleteCommandParser; +import seedu.address.logic.parser.reminder.ReminderFindCommandParser; /** @@ -111,6 +112,9 @@ public Command parseCommand(String userInput) throws ParseException { case ReminderDeleteCommand.COMMAND_WORD: return new ReminderDeleteCommandParser().parse(arguments); + + case ReminderFindCommand.COMMAND_WORD: + return new ReminderFindCommandParser().parse(arguments); default: throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/reminder/ReminderFindCommandParser.java b/src/main/java/seedu/address/logic/parser/reminder/ReminderFindCommandParser.java new file mode 100644 index 00000000000..a4362afc116 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/reminder/ReminderFindCommandParser.java @@ -0,0 +1,33 @@ +package seedu.address.logic.parser.reminder; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import java.util.Arrays; + +import seedu.address.logic.commands.reminder.ReminderFindCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.reminder.ReminderNameContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new ReminderFindCommand object + */ +public class ReminderFindCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the ReminderFindCommand + * and returns a ReminderFindCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public ReminderFindCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderFindCommand.MESSAGE_USAGE)); + } + + String[] nameKeywords = trimmedArgs.split("\\s+"); + + return new ReminderFindCommand(new ReminderNameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + } + +} diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 96b96a712fc..c48120cb30b 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -16,6 +16,7 @@ public interface Model { /** {@code Predicate} that always evaluate to true */ Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; Predicate PREDICATE_SHOW_ALL_CCAS = unused -> true; + Predicate PREDICATE_SHOW_ALL_REMINDERS = unused -> true; /** * Replaces user prefs data with the data in {@code userPrefs}. @@ -116,11 +117,17 @@ public interface Model { void updateFilteredPersonList(Predicate predicate); /** - * Updates the filter of the filtered person list to filter by the given {@code predicate}. + * Updates the filter of the filtered CCA list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredCcaList(Predicate predicate); + /** + * Updates the filter of the filtered reminder list to filter by the given {@code predicate}. + * @throws NullPointerException if {@code predicate} is null. + */ + void updateFilteredReminderList(Predicate predicate); + /** * Enrols a person into a CCA */ diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 0bd17fe4fda..b218da7b413 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -262,4 +262,10 @@ public boolean equals(Object obj) { public ObservableList getFilteredReminderList() { return filteredReminders; } + + @Override + public void updateFilteredReminderList(Predicate predicate) { + requireNonNull(predicate); + filteredReminders.setPredicate(predicate); + } } diff --git a/src/main/java/seedu/address/model/reminder/ReminderNameContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/reminder/ReminderNameContainsKeywordsPredicate.java new file mode 100644 index 00000000000..c018b0b10a2 --- /dev/null +++ b/src/main/java/seedu/address/model/reminder/ReminderNameContainsKeywordsPredicate.java @@ -0,0 +1,31 @@ +package seedu.address.model.reminder; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.address.commons.util.StringUtil; + +/** + * Tests that a {@code Reminder}'s {@code CcaName} matches any of the keywords given. + */ +public class ReminderNameContainsKeywordsPredicate implements Predicate { + private final List keywords; + + public ReminderNameContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Reminder reminder) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(reminder.getName().fullName, keyword)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReminderNameContainsKeywordsPredicate // instanceof handles nulls + && keywords.equals(((ReminderNameContainsKeywordsPredicate) other).keywords)); // state check + } + +}