forked from nus-cs2113-AY2324S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package duke; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Parser { | ||
public static final String[] validCommands = | ||
{"list", "mark", "unmark", "todo", "deadline", "event", "bye", "delete"}; | ||
protected TaskList taskList; | ||
|
||
public Parser(TaskList taskList) { | ||
this.taskList = taskList; | ||
} | ||
|
||
public List<Task> getList() { | ||
return taskList.getTaskList(); | ||
} | ||
|
||
public void executeCommand(String command, String argument) | ||
throws MissingParamsException, DukeException.EndListException, | ||
DukeException.InvalidCommandException, DukeException.InvalidIntegerException, | ||
DukeException.IntegerOutOfBoundsException { | ||
if (command.equalsIgnoreCase("bye")) { | ||
throw new DukeException.EndListException(); | ||
} | ||
|
||
if (Arrays.stream(validCommands).noneMatch(command::equals)){ | ||
throw new DukeException.InvalidCommandException(); | ||
} | ||
|
||
switch (command) { | ||
case "list": | ||
taskList.printList(); | ||
break; | ||
case "mark": | ||
taskList.markTask(argument, true); | ||
break; | ||
case "unmark": | ||
taskList.markTask(argument, false); | ||
break; | ||
case "todo": | ||
taskList.addToDo(argument); | ||
break; | ||
case "deadline": | ||
taskList.addDeadline(argument); | ||
break; | ||
case "event": | ||
taskList.addEvent(argument); | ||
break; | ||
case "delete": | ||
taskList.deleteTask(argument); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters