-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathParser.java
More file actions
46 lines (42 loc) · 1.73 KB
/
Parser.java
File metadata and controls
46 lines (42 loc) · 1.73 KB
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
package duke;
import duke.commands.Command;
import duke.commands.ListCommand;
import duke.commands.AddCommand;
import duke.commands.FindCommand;
import duke.commands.NoCommand;
import duke.commands.DoneCommand;
import duke.commands.DeleteCommand;
import duke.tasks.TaskList;
import duke.tasks.TaskType;
public class Parser {
public final String LIST = "list";
public final String TODO = "todo";
public final String DEADLINE = "deadline";
public final String EVENT = "event";
public final String FIND = "find";
public final String DONE = "done";
public final String DELETE = "delete";
public final String BYE = "bye";
//executes program and updates task list according to user command
public Command parseCommand(TaskList taskList, String line) {
final String[] splitLine = line.split(" ", 2);
final String command = splitLine[0];
final String userCommand = line.replaceAll("^" + command + " ", "");
if (command.equals(LIST)) {
return new ListCommand(taskList);
} else if (command.equals(TODO)) {
return new AddCommand(taskList, userCommand, TaskType.TODO);
} else if (command.equals(DEADLINE)) {
return new AddCommand(taskList, userCommand, TaskType.DEADLINE);
} else if (command.equals(EVENT)) {
return new AddCommand(taskList, userCommand, TaskType.EVENT);
} else if (command.equals(FIND)) {
return new FindCommand(taskList, userCommand);
} else if (command.equals(DONE)) {
return new DoneCommand(taskList, userCommand);
} else if (command.equals(DELETE)) {
return new DeleteCommand(taskList, userCommand);
}
return new NoCommand(taskList);
}
}