Skip to content

Commit

Permalink
Fix Javadocs, userguide
Browse files Browse the repository at this point in the history
  • Loading branch information
koh-jx committed Sep 16, 2021
1 parent 2224bd6 commit b957ff3
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 88 deletions.
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ Using the command with no arguments displays the index numbers of all tasks, to

**Example usage (with and without optional arguments):**

`list` - Standard list command (no arguments)
`list` - List all items (no arguments)

`list /date DD/MM/YYYY` - Search for tasks at date

`list /name taskname` - Search for tasks with name
`list /name taskname` - Search for tasks that contains name

Arguments can be stacked, order of arguments does not matter.

`list /name taskname /date DD/MM/YYYY` - Search for tasks with specified name AND date
`list /name taskname /date DD/MM/YYYY` - Search for tasks that contains specified name AND date


* `DD/MM/YYYY` - Date and month can be 1-2 digits long
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package duke.command;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import duke.ui.Ui;

/**
Expand All @@ -28,9 +24,9 @@ public abstract class Command {
*/
@Override
public String toString() {
assert commandName != null: "Command Name cannot be null";
assert description != null: "Description cannot be null";
assert arguments != null: "Arguments cannot be null";
assert commandName != null : "Command Name cannot be null";
assert description != null : "Description cannot be null";
assert arguments != null : "Arguments cannot be null";

StringBuilder argString = new StringBuilder();
for (String arg : arguments) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/CommandAddDeadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.format.DateTimeParseException;

import duke.ui.Ui;
import duke.util.DukeParser;
import duke.util.DateTimeUtils;
import task.TaskDeadline;
import task.TaskList;

Expand Down Expand Up @@ -42,7 +42,7 @@ public String execute() {
try {
return taskList.add(new TaskDeadline(
input[0],
DukeParser.getDate(input[1]),
DateTimeUtils.getDate(input[1]),
input[2],
false,
LocalDateTime.now()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/CommandAddEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.format.DateTimeParseException;

import duke.ui.Ui;
import duke.util.DukeParser;
import duke.util.DateTimeUtils;
import task.TaskEvent;
import task.TaskList;

Expand Down Expand Up @@ -42,7 +42,7 @@ public String execute() {
try {
return taskList.add(new TaskEvent(
input[0],
DukeParser.getDate(input[1]),
DateTimeUtils.getDate(input[1]),
input[2],
false,
LocalDateTime.now()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/CommandAddTodo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package duke.command;

import java.time.LocalDateTime;

import task.TaskList;
import task.TaskTodo;

import java.time.LocalDateTime;

/**
* Command to add a to-do.
*/
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/duke/command/CommandExit.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package duke.command;

import duke.ui.Ui;
import javafx.application.Platform;

import java.util.Timer;
import java.util.TimerTask;

import duke.ui.Ui;
import javafx.application.Platform;

/**
* Command to exit program.
*/
Expand All @@ -26,7 +26,9 @@ public CommandExit() {
@Override
public String execute() {
new Timer().schedule(new TimerTask() {
public void run () { Platform.exit(); }
public void run () {
Platform.exit();
}
}, 2000);

return Ui.goodByeMessage();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/command/CommandList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.function.Predicate;

import duke.ui.Ui;
import duke.util.DukeParser;
import duke.util.DateTimeUtils;
import task.Task;
import task.TaskList;

Expand Down Expand Up @@ -93,7 +93,7 @@ private ArrayList<Predicate<Task>> listStringToFilter(String stringToParse)
.toLowerCase().contains(arg.toLowerCase()));
break;
case ("date"):
LocalDate date = DukeParser.getDate(arg);
LocalDate date = DateTimeUtils.getDate(arg);
results.add(task -> task.isDate(date));
break;
default:
Expand All @@ -105,7 +105,7 @@ private ArrayList<Predicate<Task>> listStringToFilter(String stringToParse)
}

private String getCommand(String str)
throws IllegalArgumentException{
throws IllegalArgumentException {
int index = getCommandArgumentSplitIndex(str);
return str.substring(0, index);
}
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/duke/command/CommandSort.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package duke.command;

import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.function.Predicate;

import duke.ui.Ui;
import task.Task;
import task.TaskList;

/**
* Command to sort the tasklist
* Command to sort the task list
*/
public class CommandSort extends Command {

Expand All @@ -21,18 +19,18 @@ public class CommandSort extends Command {
/**
* Constructor for this command.
*
* @param taskList Task list to list.
* @param taskList Task list to sort.
* @param sortFilters Un-parsed list of filters.
*/
public CommandSort(TaskList taskList, String sortFilters) {
this.commandName = "sort /name /date";
this.description = "Sorts list based on arguments provided. Having no arguments would default to" +
" sorting by /name. If there is more than 1 argument, the list will be sorted by the first." +
"followed by the second, etc...";
this.description = "Sorts list based on arguments provided. Having no arguments would default to"
+ " sorting by /name. If there is more than 1 argument, the list will be sorted by the first."
+ "followed by the second, etc...";
this.arguments = new String[]{
"/name Optional argument to sort by name",
"/date Optional argument to sort by date",
"/done Optional argument to sort by completion status"
"/name Optional argument to sort by name",
"/date Optional argument to sort by date",
"/done Optional argument to sort by completion status"
};

this.taskList = taskList;
Expand All @@ -41,7 +39,6 @@ public CommandSort(TaskList taskList, String sortFilters) {

/**
* Lists out tasks based on given filters.
* TODO
*/
@Override
public String execute() {
Expand All @@ -57,7 +54,7 @@ public String execute() {
* Gets arguments from a multi-argument string.
*
* @param stringToParse String to parse.
* @return Arraylist with all filters to use to display list.
* @return Arraylist with all filters to use to sort list.
* @throws DateTimeParseException Thrown if error in parsing dates.
* @throws IllegalArgumentException Thrown if an argument is in a wrong format.
*/
Expand Down Expand Up @@ -123,4 +120,4 @@ private Comparator<Task> createDoneComparator() {
private Comparator<Task> createAddedComparator() {
return Comparator.comparing(Task::getAdded);
}
}
}
11 changes: 2 additions & 9 deletions src/main/java/duke/ui/ErrorDialog.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package duke.ui;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.io.IOException;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;

import java.io.IOException;
import java.util.Collections;

/**
* This control represents a dialog box consisting of an error message to be displayed
* more prominently than a normal message.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class MainWindow extends AnchorPane {
*/
@FXML
public void initialize() {
assert this.getClass().getResourceAsStream(USER_IMAGE_LOCATION) != null:" User Image not found";
assert this.getClass().getResourceAsStream(USER_IMAGE_LOCATION) != null:" Duke Image not found";
assert this.getClass().getResourceAsStream(USER_IMAGE_LOCATION) != null : " User Image not found";
assert this.getClass().getResourceAsStream(USER_IMAGE_LOCATION) != null : " Duke Image not found";

userImage = new Image(this.getClass().getResourceAsStream(USER_IMAGE_LOCATION));
dukeImage = new Image(this.getClass().getResourceAsStream(DUKE_IMAGE_LOCATION));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/duke/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public static String messageListSize(int size) {
: "There are " + size + " tasks in your list";
}

/**
* Displays message when toggling the completion status of a task.
*
* @param isDone New status of task.
* @param task Task in question.
* @return Corresponding message string.
*/
public static String messageToggleDone(boolean isDone, Task task) {
return (isDone
? "Sugoi! Duke-san marked this task as done!"
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/duke/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package duke.util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class DateTimeUtils {

/**
* Takes in a String date and returns its corresponding LocalDate object.
*
* @param date String date in format DD/MM/YYYY, with 1-2 digits from Day and Month.
* @return LocalDate object with the corresponding day, month and year.
* @throws DateTimeParseException Thrown if date passed is an invalid one.
*/
public static LocalDate getDate(String date) throws DateTimeParseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
return LocalDate.parse(date, formatter);
}

/**
* Checks if a time is in an invalid format
*
* @param time Time to check
* @return False if the time is valid, true if invalid (outside the range of 0000-2359)
*/
public static boolean checkInvalidTime(String time) {
if (time.equals("")) {
return false;
}

int timeInt = Integer.parseInt(time);
return (timeInt >= 2400 || timeInt < 0);
}
}
31 changes: 12 additions & 19 deletions src/main/java/duke/util/DukeParser.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package duke.util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import duke.command.*;
import duke.command.Command;
import duke.command.CommandAddDeadline;
import duke.command.CommandAddEvent;
import duke.command.CommandAddTodo;
import duke.command.CommandDelete;
import duke.command.CommandDone;
import duke.command.CommandExit;
import duke.command.CommandHelp;
import duke.command.CommandInvalid;
import duke.command.CommandList;
import duke.command.CommandSort;
import task.TaskList;

/**
Expand Down Expand Up @@ -46,7 +53,7 @@ public DukeParser(TaskList tasks) {
* @param input String input from the Listener given by the User.
*/
public Command parseInput(String input) {
assert input != null: "Input to parse cannot be null";
assert input != null : "Input to parse cannot be null";

if (input.equals("gubbai")) {
return new CommandExit();
Expand Down Expand Up @@ -87,18 +94,4 @@ public Command parseInput(String input) {
return new CommandInvalid(input);
}
}

/**
* Takes in a String date and returns its corresponding LocalDate object.
*
* @param date String date in format DD/MM/YYYY, with 1-2 digits from Day and Month.
* @return LocalDate object with the corresponding day, month and year.
* @throws DateTimeParseException Thrown if date passed is an invalid one.
*/
public static LocalDate getDate(String date) throws DateTimeParseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
return LocalDate.parse(date, formatter);
}


}
6 changes: 3 additions & 3 deletions src/main/java/duke/util/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ private static Task stringToTask(String task) throws ParseException {
switch (taskType) {
case "T":
// Create new To-do
assert args.length == 3: "Invalid loaded task";
assert args.length == 3 : "Invalid loaded task";
return new TaskTodo(args[2], args[1].equals("1"), LocalDateTime.parse(args[3]));
case "D":
// Create new Deadline
assert args.length == 5 || args.length == 6: "Invalid loaded task";
assert args.length == 5 || args.length == 6 : "Invalid loaded task";
return args.length == 5
? new TaskDeadline(args[2], LocalDate.parse(args[3]), null,
!args[1].equals("0"), LocalDateTime.parse(args[4]))
: new TaskDeadline(args[2], LocalDate.parse(args[3]), args[4],
!args[1].equals("0"), LocalDateTime.parse(args[5]));
case "E":
// Create new Event
assert args.length == 5 || args.length == 6: "Invalid loaded task";
assert args.length == 5 || args.length == 6 : "Invalid loaded task";
return args.length == 5
? new TaskEvent(args[2], LocalDate.parse(args[3]), null,
!args[1].equals("0"), LocalDateTime.parse(args[4]))
Expand Down
Loading

0 comments on commit b957ff3

Please sign in to comment.