forked from nus-cs2103-AY2122S1/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
18 changed files
with
489 additions
and
176 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
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,30 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.ui.Ui; | ||
|
||
public class ByeCommand extends Command { | ||
final static String cmd = "bye"; | ||
final static String usage = "exit app"; | ||
final static String format = "bye"; | ||
|
||
public ByeCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
return ui.showBye(); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,50 +1,23 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.exception.*; | ||
import duke.storage.Storage; | ||
import duke.ui.Ui; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Stores description of usage and format of command. | ||
*/ | ||
public class Command { | ||
String cmd; | ||
String fn; | ||
String format; | ||
public abstract class Command { | ||
|
||
/** | ||
* Constructs Command object | ||
* | ||
* @param cmd command | ||
* @param fn description of usage | ||
* @param format format | ||
*/ | ||
public Command(String cmd, String fn, String format) { | ||
this.cmd = cmd; | ||
this.fn = fn; | ||
this.format = format; | ||
} | ||
|
||
/** | ||
* Returns command | ||
* | ||
* @return command | ||
*/ | ||
public String getCmd() { | ||
return this.cmd; | ||
} | ||
public Command() {} | ||
|
||
/** | ||
* Returns description of usage | ||
* | ||
* @return description of usage | ||
*/ | ||
public String getFn() { | ||
return this.fn; | ||
} | ||
|
||
/** | ||
* Returns format | ||
* | ||
* @return format | ||
*/ | ||
public String getFormat() { | ||
return this.format; | ||
} | ||
public abstract String execute(TaskList tasks, Ui ui, Storage storage); | ||
} |
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,44 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.task.Deadline; | ||
import duke.ui.Ui; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class DeadlineCommand extends Command { | ||
final static String cmd = "deadline"; | ||
final static String usage = "add tasks that need to be done before a specific date & time"; | ||
final static String format = "deadline {task name} /by {yyyy-MM-dd HH:mm}"; | ||
|
||
private String name; | ||
private LocalDateTime by; | ||
|
||
public DeadlineCommand(String name, LocalDateTime by) { | ||
this.name = name; | ||
this.by = by; | ||
} | ||
|
||
public DeadlineCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
Deadline deadline = new Deadline(name, by); | ||
tasks.addTask(deadline); | ||
storage.updateData(tasks); | ||
return ui.showTaskAdded(deadline, tasks.getSize()); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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,40 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.task.Task; | ||
import duke.ui.Ui; | ||
|
||
public class DeleteCommand extends Command { | ||
final static String cmd = "delete"; | ||
final static String usage = "deletes specified task"; | ||
final static String format = "delete {task number}"; | ||
|
||
private int taskNum; | ||
|
||
public DeleteCommand(int taskNum) { | ||
this.taskNum = taskNum; | ||
} | ||
|
||
public DeleteCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
Task task = tasks.getTask(taskNum); | ||
tasks.deleteTask(task); | ||
storage.updateData(tasks); | ||
return ui.showTaskDeleted(task, tasks.getSize()); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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,40 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.task.Task; | ||
import duke.ui.Ui; | ||
|
||
public class DoneCommand extends Command { | ||
final static String cmd = "done"; | ||
final static String usage = "marks specified task as done"; | ||
final static String format = "done {task number}"; | ||
|
||
private int taskNum; | ||
|
||
public DoneCommand(int taskNum) { | ||
this.taskNum = taskNum; | ||
} | ||
|
||
public DoneCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
Task task = tasks.getTask(this.taskNum); | ||
task.markAsDone(); | ||
storage.updateData(tasks); | ||
return ui.showTaskDone(task); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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,44 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.task.Event; | ||
import duke.ui.Ui; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class EventCommand extends Command { | ||
final static String cmd = "event"; | ||
final static String usage = "add tasks that need that starts at a specific time"; | ||
final static String format = "event {task name} /by {yyyy-MM-dd HH:mm}"; | ||
|
||
private String name; | ||
private LocalDateTime at; | ||
|
||
public EventCommand(String name, LocalDateTime at) { | ||
this.name = name; | ||
this.at = at; | ||
}; | ||
|
||
public EventCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
Event event = new Event(name, at); | ||
tasks.addTask(event); | ||
storage.updateData(tasks); | ||
return ui.showTaskAdded(event, tasks.getSize()); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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,37 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.ui.Ui; | ||
|
||
public class FindCommand extends Command { | ||
final static String cmd = "find"; | ||
final static String usage = "find a task by searching for a keyword"; | ||
final static String format = "find {keyword}"; | ||
|
||
private String keyword; | ||
|
||
public FindCommand(String keyword) { | ||
this.keyword = keyword; | ||
} | ||
|
||
public FindCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
TaskList t = tasks.matchTasks(keyword); | ||
return ui.showTaskList(t, "find"); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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,30 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.storage.Storage; | ||
import duke.ui.Ui; | ||
|
||
public class HelpCommand extends Command { | ||
final static String cmd = "help"; | ||
final static String usage = "shows list of all commands & usages"; | ||
final static String format = "help"; | ||
|
||
public HelpCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
return ui.showAfterHelp(); | ||
} | ||
|
||
public static String getCmd() { | ||
return cmd; | ||
} | ||
|
||
public static String getUsage() { | ||
return usage; | ||
} | ||
|
||
public static String getFormat() { | ||
return format; | ||
} | ||
} |
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,21 @@ | ||
package duke.command; | ||
|
||
import duke.data.TaskList; | ||
import duke.exception.DukeException; | ||
import duke.exception.InvalidEntryException; | ||
import duke.storage.Storage; | ||
import duke.ui.Ui; | ||
|
||
public class InvalidCommand extends Command { | ||
|
||
public InvalidCommand() {} | ||
|
||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) { | ||
try { | ||
throw new InvalidEntryException("error"); | ||
} catch (DukeException e) { | ||
return e.getError(); | ||
} | ||
} | ||
} |
Oops, something went wrong.