forked from nus-cs2103-AY1920S1/addressbook-level3
/
EventCommand.java
59 lines (47 loc) Β· 1.74 KB
/
EventCommand.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
53
54
55
56
57
58
59
package seedu.address.logic.commands;
import static java.util.Objects.requireNonNull;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.feature.Feature;
import seedu.address.model.performance.Event;
/**
* Adds an event for the performance recording.
*/
public class EventCommand extends Command {
public static final String COMMAND_WORD = "event";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a new event with the specified name";
public static final String MESSAGE_SUCCESS = "Event Created: %1$s";
public static final String MESSAGE_DUPLICATE_EVENT = "%1$s event already exists in Athletick.";
private final Event toAdd;
/**
* Creates an EventCommand to add the specified event.
*/
public EventCommand(Event event) {
requireNonNull(event);
toAdd = event;
}
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
if (model.hasEvent(toAdd)) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_EVENT, toAdd.getName()));
}
model.addEvent(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.getName()),
new Feature("performance"), model);
}
@Override
public boolean isUndoable() {
return false;
}
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof EventCommand // instanceof handles nulls
&& toAdd.equals(((EventCommand) other).toAdd));
}
@Override
public String toString() {
return "Add Event Command";
}
}