forked from nus-cs2103-AY1920S1/addressbook-level3
/
Command.java
51 lines (43 loc) · 1.65 KB
/
Command.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
package io.xpire.logic.commands;
import static io.xpire.commons.core.Messages.MESSAGE_EMPTY_LIST;
import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.logic.parser.exceptions.ParseException;
import io.xpire.model.Model;
import io.xpire.model.state.StateManager;
/**
* Represents a command with hidden internal logic and the ability to be executed.
*/
public abstract class Command {
private boolean showInHistory = false;
/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @param stackManager {@code StackManager} which manages the state of each command.
* @return feedback message of the operation result for display.
* @throws CommandException If an error occurs during command execution.
*/
public abstract CommandResult execute(Model model,
StateManager stackManager) throws CommandException, ParseException;
/**
* Denotes if the command should be stored in history.
*
* @return whether the command should be kept in CommandHistory.
*/
public boolean isShowInHistory() {
return this.showInHistory;
}
/**
* Sets showInHistory.
*
* @param showInHistory appropriate boolean value for showInHistory.
*/
public void setShowInHistory(boolean showInHistory) {
this.showInHistory = showInHistory;
}
protected void requireNonEmptyCurrentList(Model model) throws CommandException {
if (model.getCurrentList().isEmpty()) {
throw new CommandException(MESSAGE_EMPTY_LIST);
}
}
}