forked from nus-cs2103-AY1920S1/addressbook-level3
/
DisplayScheduleBetweenCommand.java
52 lines (43 loc) · 2 KB
/
DisplayScheduleBetweenCommand.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
44
45
46
47
48
49
50
51
52
/*
@@author shihaoyap
*/
package seedu.address.logic.commands.schedule;
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.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.event.EventContainsKeyDateRangePredicate;
import seedu.address.ui.MainWindow;
/**
* Finds and lists all events in event list that is between the 2 specified dates
* Keyword matching is case insensitive and in the following format dd/MM/yyyy.
*/
public class DisplayScheduleBetweenCommand extends Command {
public static final String COMMAND_WORD = "display_schedule_between";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all events that "
+ "occurs between the 2 dates specified. \n"
+ "Example: " + COMMAND_WORD + " start/02/12/2019 end/05/12/2019";
private final EventContainsKeyDateRangePredicate predicate;
public DisplayScheduleBetweenCommand(EventContainsKeyDateRangePredicate predicate) {
this.predicate = predicate;
}
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
if (MainWindow.isFinanceTab() || MainWindow.isStatsTab()) {
throw new CommandException(Messages.MESSAGE_WRONG_TAB);
}
model.updateFilteredScheduledEventList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW,
model.getFilteredScheduledEventList().size()), "Schedule_Update", "");
}
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DisplayScheduleBetweenCommand // instanceof handles nulls
&& predicate.equals(((DisplayScheduleBetweenCommand) other).predicate)); // state check
}
}