Skip to content

Commit

Permalink
Merge pull request #83 from jovyntls/reminders-find-command
Browse files Browse the repository at this point in the history
Add Find command for Reminders
  • Loading branch information
okyntary authored Oct 18, 2021
2 parents 02180b9 + 3a1eea5 commit a7f06b1
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!";

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,14 +12,15 @@ 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
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);
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;


/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ReminderFindCommand> {

/**
* 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)));
}

}
9 changes: 8 additions & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
Predicate<Cca> PREDICATE_SHOW_ALL_CCAS = unused -> true;
Predicate<Reminder> PREDICATE_SHOW_ALL_REMINDERS = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
Expand Down Expand Up @@ -116,11 +117,17 @@ public interface Model {
void updateFilteredPersonList(Predicate<Person> 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<Cca> 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<Reminder> predicate);

/**
* Enrols a person into a CCA
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,10 @@ public boolean equals(Object obj) {
public ObservableList<Reminder> getFilteredReminderList() {
return filteredReminders;
}

@Override
public void updateFilteredReminderList(Predicate<Reminder> predicate) {
requireNonNull(predicate);
filteredReminders.setPredicate(predicate);
}
}
Original file line number Diff line number Diff line change
@@ -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<Reminder> {
private final List<String> keywords;

public ReminderNameContainsKeywordsPredicate(List<String> 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
}

}

0 comments on commit a7f06b1

Please sign in to comment.