Skip to content

Commit

Permalink
Merge branch 'branch-A-JavaDoc'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanWeiJie committed Jan 23, 2022
2 parents 231d286 + 7fc7334 commit 273eacb
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 5 deletions.
17 changes: 16 additions & 1 deletion src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

import duke.task.Task;
import duke.functionality.TaskList;

/**
* Represents the add command. A <code>AddCommand</code> object corresponds to adding that specified task
* to the taskList in the TaskList class.
*/
public class AddCommand extends Command {

/**
* Constructor of AddCommand class.
* @param t task object created from user input.
*/
public AddCommand(Task t){
super(t, null);
}

/**
* Returns nothing, but adds the specified task in the taskList in TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.addToList(super.task);
}

/**
* Returns false as the Command is not an ExitCommand.
* @return false.
*/
@Override
public boolean isExit() {
return false;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,32 @@
import duke.task.Task;
import duke.functionality.TaskList;

/**
* Represents the commands inputted by a user. The Command class cannot be instantiated as it is an abstract class.
*/
public abstract class Command{
protected Task task;
protected Integer index;

/**
* Constructor of Command class.
* @param t task object created from user input.
* @param number an indicator to the index of the taskList in TaskList class.
*/
public Command(Task t, Integer number) {
this.task = t;
this.index = number;
}

/**
* Returns nothing, but used to execute the respective methods in TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
public abstract void execute(TaskList tasks);

/**
* Returns a boolean depending on the input command of the user.
* @return returns true if Command is an ExitCommand, eg: "bye". Else returns false.
*/
public abstract boolean isExit();
}
16 changes: 16 additions & 0 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@

import duke.functionality.TaskList;

/**
* Represents the delete command. A <code>DeleteCommand</code> object corresponds to deleting that specified task
* to the taskList in the TaskList class.
*/
public class DeleteCommand extends Command {

/**
* Constructor for DeleteCommand class.
* @param number an indicator to the index of the taskList in TaskList class.
*/
public DeleteCommand(Integer number) {

super(null, number);
}

/**
* Returns nothing, but deletes the specified task in the taskList in TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.deleteTask(super.index);
}

/**
* Returns false as the Command is not an ExitCommand.
* @return false.
*/
@Override
public boolean isExit() {
return false;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

import duke.functionality.TaskList;

/**
* Represents the exit command. A <code>ExitCommand</code> object corresponds to exiting the Duke program.
*/
public class ExitCommand extends Command{

/**
* Constructor for ExitCommand class.
*/
public ExitCommand() {
super(null, null);
}

/**
* Returns nothing & does not execute anything.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
@Override
public void execute(TaskList tasks) { }

/**
* Returns true as the Command is an ExitCommand.
* @return true.
*/
@Override
public boolean isExit() {
return true;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/duke/command/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@

import duke.functionality.TaskList;

/**
* Represents the mark command. A <code>MarkCommand</code> object allows users to set the corresponding task as done.
*/
public class MarkCommand extends Command {

/**
* Constructor for MarkCommand class.
* @param number an indicator to the index of the taskList in TaskList class.
*/
public MarkCommand(Integer number) {
super(null, number);
}

/**
* Returns nothing, but marks the corresponding task in the taskList in TaskList class as done.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.markTask(super.index);
}

/**
* Returns false as the Command is not an ExitCommand.
* @return false.
*/
@Override
public boolean isExit() {
return false;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/duke/command/PrintCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@

import duke.functionality.TaskList;

/**
* Represents the print command. A <code>PrintCommand</code> object allows users to see all task in Duke TaskBot.
*/
public class PrintCommand extends Command{

/**
* Constructor for PrintCommand class.
*/
public PrintCommand() {
super(null, null);
}

/**
* Returns nothing, but prints out all the task in the taskList in TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.printList();
}

/**
* Returns false as the Command is not an ExitCommand.
* @return false.
*/
@Override
public boolean isExit() {
return false;
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/duke/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
package duke.command;

import duke.functionality.TaskList;

/**
* Represents the unmark command. A <code>UnmarkCommand</code> object allows users to set the corresponding task as
* not done.
*/
public class UnmarkCommand extends Command{

/**
* Constructor for the UnmarkCommand class.
* @param number an indicator to the index of the taskList in TaskList class.
*/
public UnmarkCommand(Integer number) {
super(null, number);
}

/**
* Returns nothing, but marks the corresponding task in the taskList in TaskList class as not done.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.unMarkTask(super.index);
}

/**
* Returns false as the Command is not an ExitCommand.
* @return false.
*/
@Override
public boolean isExit() {
return false;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/duke/exception/BlankCommandException.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package duke.exception;

/**
* Represents the BlankCommandException the Duke program would handle. A <code> BlankCommandException </code>
* object corresponds to a blank command inputted by a user. Eg, " ".
*/
public class BlankCommandException extends DukeException {

/**
* Constructor for BlankCommandException class.
*/
public BlankCommandException() {
super("OOPS!!! I'm sorry, but I do not accept empty commands! :-(");
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/duke/exception/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package duke.exception;

/**
* Represents the Exceptions the Duke program would handle. A <code> DukeException </code> object corresponds
* to the exceptions specified and handled by Duke.
*/
public class DukeException extends Exception{

/**
* Constructor for DukeException class.
* @param description the error message provided for the exception.
*/
public DukeException(String description) {
super(description);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/duke/exception/IncompleteCommandException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package duke.exception;

/**
* Represents the IncompleteCommandException the Duke program would handle. A <code> IncompleteCommandException </code>
* object corresponds to a incomplete command inputted by a user. Eg, event sleep /at.
*/
public class IncompleteCommandException extends DukeException {

/**
* Constructor for IncompleteCommandException class.
* @param command the respective task the user has inputted eg,todo/event/deadline.
*/
public IncompleteCommandException(String command) {
super("OOPS!!! The description of a " + command + " cannot be empty.");
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/duke/exception/InvalidCommandException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package duke.exception;

/**
* Represents the InvalidCommandException the Duke program would handle. A <code> InvalidCommandException </code>
* object corresponds to an invalid command inputted by a user. Eg, blah.
*/
public class InvalidCommandException extends DukeException {

/**
* Constructor for InvalidCommandException class.
*/
public InvalidCommandException() {
super("OOPS!!! I'm sorry, but I don't know what that means :-(");
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/duke/functionality/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,67 @@
import duke.exception.IncompleteCommandException;
import duke.exception.InvalidCommandException;

/**
* Represents the Parsing capabilities of the Duke project. A <code> Parse </code> object corresponds
* to the actions taken to parse and format user inputs.
*/
public class Parser {

private static final int EVENT_OFFSET = 5;
private static final int TODO_OFFSET = 4;
private static final int DEADLINE_OFFSET = 8;
private static final int INPUT_OFFSET = 3;

/**
* Returns the formatted date.
* @param input date specified by user input. Eg, "2020-06-06".
* @return formatted date.
*/
public static LocalDate formatDate(String input){
DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyy-MM-dd");
LocalDate date = LocalDate.parse(input, dtf);
return date;
}

/**
* Returns the formatted time.
* @param input time specified by user input. Eg, "1800".
* @return formatted time.
*/
public static LocalTime formatTime(String input) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm");
LocalTime time = LocalTime.parse(input, dtf);
return time;
}

/**
* Returns the date.
* @param input formatted date. Eg, "2020-06-06".
* @return date but as a String.
*/
public static String dateToString(LocalDate input) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyy-MM-dd");
String date = input.format(dtf);
return date;
}

/**
* Returns the time.
* @param input formatted time Eg, "1800".
* @return time but as a String.
*/
public static String timeToString(LocalTime input) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm");
String time = input.format(dtf);
return time;
}

/**
* Returns the respective command from user input.
* @param input user input. Eg, "todo run".
* @return the command.
* @throws DukeException when user input for date and time are not of the correct form.
*/
public static Command parse(String input) throws DukeException {
String[] inputSplit = input.split(" "); //split input by space
String command = inputSplit[0];
Expand Down
Loading

0 comments on commit 273eacb

Please sign in to comment.