Skip to content

Commit 3a1eea5

Browse files
committed
Add reminder find command
1 parent 8d29ea8 commit 3a1eea5

9 files changed

Lines changed: 131 additions & 5 deletions

File tree

src/main/java/seedu/address/commons/core/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public class Messages {
1212
public static final String MESSAGE_INVALID_REMINDER_DISPLAYED_INDEX = "The reminder index provided is invalid :(";
1313
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
1414
public static final String MESSAGE_CCAS_LISTED_OVERVIEW = "%1$d CCAs listed!";
15+
public static final String MESSAGE_REMINDERS_LISTED_OVERVIEW = "%1$d reminders listed!";
1516

1617
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package seedu.address.logic.commands;
22

33
import static java.util.Objects.requireNonNull;
4-
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CCAS;
5-
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
4+
import static seedu.address.model.Model.*;
65

76
import seedu.address.model.Model;
87

@@ -13,14 +12,15 @@ public class ListCommand extends Command {
1312

1413
public static final String COMMAND_WORD = "list";
1514

16-
public static final String MESSAGE_SUCCESS = "Listed all persons and CCAs";
15+
public static final String MESSAGE_SUCCESS = "Listed all persons, CCAs and reminders";
1716

1817

1918
@Override
2019
public CommandResult execute(Model model) {
2120
requireNonNull(model);
2221
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
2322
model.updateFilteredCcaList(PREDICATE_SHOW_ALL_CCAS);
23+
model.updateFilteredReminderList(PREDICATE_SHOW_ALL_REMINDERS);
2424
return new CommandResult(MESSAGE_SUCCESS);
2525
}
2626
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package seedu.address.logic.commands.reminder;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import seedu.address.commons.core.Messages;
6+
import seedu.address.logic.commands.Command;
7+
import seedu.address.logic.commands.CommandResult;
8+
import seedu.address.model.Model;
9+
import seedu.address.model.reminder.ReminderNameContainsKeywordsPredicate;
10+
11+
/**
12+
* Finds and lists all persons in address book whose name contains any of the argument keywords.
13+
* Keyword matching is case insensitive.
14+
*/
15+
public class ReminderFindCommand extends Command {
16+
17+
public static final String COMMAND_WORD = "findr";
18+
19+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all reminders whose titles contain any of "
20+
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
21+
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
22+
+ "Example: " + COMMAND_WORD + " meeting";
23+
24+
private final ReminderNameContainsKeywordsPredicate predicate;
25+
26+
public ReminderFindCommand(ReminderNameContainsKeywordsPredicate predicate) {
27+
this.predicate = predicate;
28+
}
29+
30+
@Override
31+
public CommandResult execute(Model model) {
32+
requireNonNull(model);
33+
model.updateFilteredReminderList(predicate);
34+
return new CommandResult(
35+
String.format(Messages.MESSAGE_REMINDERS_LISTED_OVERVIEW, model.getFilteredReminderList().size()));
36+
}
37+
38+
@Override
39+
public boolean equals(Object other) {
40+
return other == this // short circuit if same object
41+
|| (other instanceof ReminderFindCommand // instanceof handles nulls
42+
&& predicate.equals(((ReminderFindCommand) other).predicate)); // state check
43+
}
44+
}
Binary file not shown.

src/main/java/seedu/address/logic/parser/AddressBookParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
44
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
5-
65
import java.util.regex.Matcher;
76
import java.util.regex.Pattern;
87

@@ -23,6 +22,7 @@
2322
import seedu.address.logic.commands.person.PersonFindCommand;
2423
import seedu.address.logic.commands.reminder.ReminderAddCommand;
2524
import seedu.address.logic.commands.reminder.ReminderDeleteCommand;
25+
import seedu.address.logic.commands.reminder.ReminderFindCommand;
2626
import seedu.address.logic.parser.cca.CcaAddCommandParser;
2727
import seedu.address.logic.parser.cca.CcaDeleteCommandParser;
2828
import seedu.address.logic.parser.cca.CcaEnrolCommandParser;
@@ -35,6 +35,7 @@
3535
import seedu.address.logic.parser.person.PersonFindCommandParser;
3636
import seedu.address.logic.parser.reminder.ReminderAddCommandParser;
3737
import seedu.address.logic.parser.reminder.ReminderDeleteCommandParser;
38+
import seedu.address.logic.parser.reminder.ReminderFindCommandParser;
3839

3940

4041
/**
@@ -111,6 +112,9 @@ public Command parseCommand(String userInput) throws ParseException {
111112

112113
case ReminderDeleteCommand.COMMAND_WORD:
113114
return new ReminderDeleteCommandParser().parse(arguments);
115+
116+
case ReminderFindCommand.COMMAND_WORD:
117+
return new ReminderFindCommandParser().parse(arguments);
114118

115119
default:
116120
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package seedu.address.logic.parser.reminder;
2+
3+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4+
import java.util.Arrays;
5+
6+
import seedu.address.logic.commands.reminder.ReminderFindCommand;
7+
import seedu.address.logic.parser.Parser;
8+
import seedu.address.logic.parser.exceptions.ParseException;
9+
import seedu.address.model.reminder.ReminderNameContainsKeywordsPredicate;
10+
11+
/**
12+
* Parses input arguments and creates a new ReminderFindCommand object
13+
*/
14+
public class ReminderFindCommandParser implements Parser<ReminderFindCommand> {
15+
16+
/**
17+
* Parses the given {@code String} of arguments in the context of the ReminderFindCommand
18+
* and returns a ReminderFindCommand object for execution.
19+
* @throws ParseException if the user input does not conform the expected format
20+
*/
21+
public ReminderFindCommand parse(String args) throws ParseException {
22+
String trimmedArgs = args.trim();
23+
if (trimmedArgs.isEmpty()) {
24+
throw new ParseException(
25+
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderFindCommand.MESSAGE_USAGE));
26+
}
27+
28+
String[] nameKeywords = trimmedArgs.split("\\s+");
29+
30+
return new ReminderFindCommand(new ReminderNameContainsKeywordsPredicate(Arrays.asList(nameKeywords)));
31+
}
32+
33+
}

src/main/java/seedu/address/model/Model.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface Model {
1616
/** {@code Predicate} that always evaluate to true */
1717
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
1818
Predicate<Cca> PREDICATE_SHOW_ALL_CCAS = unused -> true;
19+
Predicate<Reminder> PREDICATE_SHOW_ALL_REMINDERS = unused -> true;
1920

2021
/**
2122
* Replaces user prefs data with the data in {@code userPrefs}.
@@ -116,11 +117,17 @@ public interface Model {
116117
void updateFilteredPersonList(Predicate<Person> predicate);
117118

118119
/**
119-
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
120+
* Updates the filter of the filtered CCA list to filter by the given {@code predicate}.
120121
* @throws NullPointerException if {@code predicate} is null.
121122
*/
122123
void updateFilteredCcaList(Predicate<Cca> predicate);
123124

125+
/**
126+
* Updates the filter of the filtered reminder list to filter by the given {@code predicate}.
127+
* @throws NullPointerException if {@code predicate} is null.
128+
*/
129+
void updateFilteredReminderList(Predicate<Reminder> predicate);
130+
124131
/**
125132
* Enrols a person into a CCA
126133
*/

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,10 @@ public boolean equals(Object obj) {
262262
public ObservableList<Reminder> getFilteredReminderList() {
263263
return filteredReminders;
264264
}
265+
266+
@Override
267+
public void updateFilteredReminderList(Predicate<Reminder> predicate) {
268+
requireNonNull(predicate);
269+
filteredReminders.setPredicate(predicate);
270+
}
265271
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package seedu.address.model.reminder;
2+
3+
import java.util.List;
4+
import java.util.function.Predicate;
5+
6+
import seedu.address.commons.util.StringUtil;
7+
8+
/**
9+
* Tests that a {@code Reminder}'s {@code CcaName} matches any of the keywords given.
10+
*/
11+
public class ReminderNameContainsKeywordsPredicate implements Predicate<Reminder> {
12+
private final List<String> keywords;
13+
14+
public ReminderNameContainsKeywordsPredicate(List<String> keywords) {
15+
this.keywords = keywords;
16+
}
17+
18+
@Override
19+
public boolean test(Reminder reminder) {
20+
return keywords.stream()
21+
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(reminder.getName().fullName, keyword));
22+
}
23+
24+
@Override
25+
public boolean equals(Object other) {
26+
return other == this // short circuit if same object
27+
|| (other instanceof ReminderNameContainsKeywordsPredicate // instanceof handles nulls
28+
&& keywords.equals(((ReminderNameContainsKeywordsPredicate) other).keywords)); // state check
29+
}
30+
31+
}

0 commit comments

Comments
 (0)