From 370e8c275f1278a177fcbb4449896cd181728196 Mon Sep 17 00:00:00 2001 From: rexkoh425 Date: Mon, 23 Sep 2024 21:45:38 +0800 Subject: [PATCH 1/4] update javadoc for Date class --- src/main/java/TheThinker/Parser/Date.java | 44 +++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/main/java/TheThinker/Parser/Date.java b/src/main/java/TheThinker/Parser/Date.java index bb3e651d5..f8530a87b 100644 --- a/src/main/java/TheThinker/Parser/Date.java +++ b/src/main/java/TheThinker/Parser/Date.java @@ -6,11 +6,11 @@ import java.time.LocalDate; import java.time.format.DateTimeParseException; -public class Date { +public interface Date { - public static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm"); - public static DateTimeFormatter resultDateTimeFormatter = DateTimeFormatter.ofPattern("dd MMMM yyyy , h a"); - public static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm"); + DateTimeFormatter resultDateTimeFormatter = DateTimeFormatter.ofPattern("dd MMMM yyyy , h a"); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); private static LocalDateTime parseIntoDateTimeObject(String date){ return LocalDateTime.parse(date, dateTimeFormatter); @@ -21,7 +21,15 @@ private static String toString(String date) { return dateObject.format(resultDateTimeFormatter); // -> Oct 15 2019 } - public static String convertDateFormat(String date) { + /** + * Converts date from format of dd/MM/yyyy HHmm to dd MMMM yyyy , h a. + * If date is not of dd/MM/yyyy HHmm format, the original string is returned. + * + * @param date deadline of task extracted from user input + * @return date of string type with format e.g. 15 October 2019 , 6 pm. + * + */ + static String convertDateFormat(String date) { String[] dateParameters = date.split("/"); if(dateParameters.length != 3 || !isDateTimeFormat(date)) { return date; @@ -50,7 +58,15 @@ private static int isValidDay(String day) { return dayInt; } - public static boolean isMatchingDate(String specifiedDate , String taskDate) { + /** + * Returns boolean if day , month and year of both parameters are same , ignoring time. + * + * @param specifiedDate date in format of dd/MM/yyyy. + * @param taskDate date in format of dd MMMM yyyy , h a. + * @return boolean + * + */ + private static boolean isMatchingDate(String specifiedDate , String taskDate) { LocalDate parsedDate = LocalDate.parse(specifiedDate, dateFormatter); LocalDateTime parsedDateTime = LocalDateTime.parse(taskDate, resultDateTimeFormatter); return parsedDate.getMonthValue() == parsedDateTime.getMonthValue() && @@ -58,14 +74,22 @@ public static boolean isMatchingDate(String specifiedDate , String taskDate) { parsedDate.getYear() == parsedDateTime.getYear(); } - public static boolean isMatchingDateByType(Task task , String specifiedDate){ + /** + * Returns true if day , month and year matches according to deadlines by task type. + * If task type is not event or deadline, return false. + * + * @param task Object of type task and subclasses. + * @param specifiedDate date in format of dd/MM/yyyy. + * @return boolean + */ + static boolean isMatchingDateByType(Task task , String specifiedDate){ if((task.getTaskType() == 'D' || task.getTaskType() == 'E') && isResultDateTimeFormat(task.getTaskDate())){ return isMatchingDate(specifiedDate , task.getTaskDate()); } return false; } - public static boolean isDateOnlyFormat(String dateStr){ + static boolean isDateOnlyFormat(String dateStr){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); try { @@ -76,7 +100,7 @@ public static boolean isDateOnlyFormat(String dateStr){ } } - public static boolean isDateTimeFormat(String dateStr){ + static boolean isDateTimeFormat(String dateStr){ try { LocalDate date = LocalDate.parse(dateStr, dateTimeFormatter); @@ -86,7 +110,7 @@ public static boolean isDateTimeFormat(String dateStr){ } } - public static boolean isResultDateTimeFormat(String dateStr){ + static boolean isResultDateTimeFormat(String dateStr){ try { LocalDate date = LocalDate.parse(dateStr, resultDateTimeFormatter); From 3d31c086b79998f6b116e88f2cd13106d022b332 Mon Sep 17 00:00:00 2001 From: rexkoh425 Date: Mon, 23 Sep 2024 22:23:49 +0800 Subject: [PATCH 2/4] update javadoc for UserInputParser --- .../TheThinker/Parser/UserInputParser.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/TheThinker/Parser/UserInputParser.java b/src/main/java/TheThinker/Parser/UserInputParser.java index 12e4e3ebd..5e224278a 100644 --- a/src/main/java/TheThinker/Parser/UserInputParser.java +++ b/src/main/java/TheThinker/Parser/UserInputParser.java @@ -9,6 +9,7 @@ import java.util.Scanner; public class UserInputParser { + public static String userInput; public static final Scanner scanner = new Scanner(System.in); public static final int LENGTH_OF_TODO = 4; @@ -23,6 +24,12 @@ public class UserInputParser { public static final String GET_FORMAT = "Please follow format : get [dd/mm/yyyy]"; public static final String FIND_FORMAT = "Please follow format : find [keyword]"; + /** + * Parse user input based on the format of To-do and use the result to create To-do object + * + * @return To-do Object + * @throws FormattingException if task description is not provided in user input + */ public static Task parseTodo() throws FormattingException { String taskDescription = userInput.substring(LENGTH_OF_TODO).trim(); @@ -34,6 +41,13 @@ public static Task parseTodo() throws FormattingException { return new Todo(taskDescription); } + /** + * Parse user input based on the format of Event and use the result to create Event object. + * + * @return Event Object. + * @throws FormattingException If /from , /to , task description , start time and end time + * is missing from user input + */ public static Event parseEvent() throws FormattingException{ String remainingTaskDescription = userInput.substring(LENGTH_OF_EVENT).trim(); @@ -71,6 +85,12 @@ public static Event parseEvent() throws FormattingException{ return new Event(taskDescription , startTime, endTime); } + /** + * Parse user input based on the format of Deadline and use the result to create Deadline object. + * + * @return Deadline Object. + * @throws FormattingException If /by , task description , deadline is missing from user input + */ public static Deadline parseDeadline() throws FormattingException{ String remainingTaskDescription = userInput.substring(LENGTH_OF_DEADLINE).trim(); @@ -106,6 +126,13 @@ public static String parseUserAction(){ return wordsInUserInput[0]; } + /** + * Parses the task number after unmark or mark command + * + * @return Task number + * @throws NumberFormatException If task number string provided is not a number. + * @throws FormattingException If no task or multiple task number is provided. + */ public static int parseNumberAfterTask() throws NumberFormatException , FormattingException{ String[] parsedInputs = userInput.split(" "); @@ -121,6 +148,12 @@ public static int parseNumberAfterTask() throws NumberFormatException , Formatti return Integer.parseInt(numberToMark); } + /** + * Parse date after get command + * + * @return date in dd/MM/yyyy format + * @throws FormattingException If date is missing or in the wrong format + */ public static String parseDateAfterGet() throws FormattingException{ String[] parsedInputs = userInput.split(" "); if(parsedInputs.length != 2){ From afc0062a4c5525b7f19ae29cec00ebf964ca229e Mon Sep 17 00:00:00 2001 From: rexkoh425 Date: Mon, 23 Sep 2024 22:54:38 +0800 Subject: [PATCH 3/4] update javadoc for Task package --- src/main/java/TheThinker/Tasks/Deadline.java | 6 ++++++ src/main/java/TheThinker/Tasks/Event.java | 6 ++++++ src/main/java/TheThinker/Tasks/Task.java | 4 ++++ src/main/java/TheThinker/Tasks/TaskList.java | 1 - src/main/java/TheThinker/Tasks/Todo.java | 4 ++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/TheThinker/Tasks/Deadline.java b/src/main/java/TheThinker/Tasks/Deadline.java index a77c2f3ab..027b0f8ee 100644 --- a/src/main/java/TheThinker/Tasks/Deadline.java +++ b/src/main/java/TheThinker/Tasks/Deadline.java @@ -1,5 +1,11 @@ package TheThinker.Tasks; +/** + * Represents a deadline type task. A deadline object contains + * task type , task description , + * deadline of format dd/MMMM/yyyy h a. + * + */ public class Deadline extends Task{ public String deadline; diff --git a/src/main/java/TheThinker/Tasks/Event.java b/src/main/java/TheThinker/Tasks/Event.java index 8e49b9237..084110993 100644 --- a/src/main/java/TheThinker/Tasks/Event.java +++ b/src/main/java/TheThinker/Tasks/Event.java @@ -1,5 +1,11 @@ package TheThinker.Tasks; +/** + * Represents an event type task. An event object contains + * task type , task description , + * start time and end time of format dd/MMMM/yyyy h a. + * + */ public class Event extends Task{ public String startTime; public String endTime; diff --git a/src/main/java/TheThinker/Tasks/Task.java b/src/main/java/TheThinker/Tasks/Task.java index 5aa916ad1..69c3040a7 100644 --- a/src/main/java/TheThinker/Tasks/Task.java +++ b/src/main/java/TheThinker/Tasks/Task.java @@ -1,5 +1,9 @@ package TheThinker.Tasks; +/** + * Represents an event type task. A Task object contains + * task type , task description. + */ public class Task { public String taskDescription; public boolean isMarkedAsDone; diff --git a/src/main/java/TheThinker/Tasks/TaskList.java b/src/main/java/TheThinker/Tasks/TaskList.java index 174cfd884..6f6bbf8b4 100644 --- a/src/main/java/TheThinker/Tasks/TaskList.java +++ b/src/main/java/TheThinker/Tasks/TaskList.java @@ -1,7 +1,6 @@ package TheThinker.Tasks; import TheThinker.Parser.Date; - import java.util.ArrayList; public class TaskList { diff --git a/src/main/java/TheThinker/Tasks/Todo.java b/src/main/java/TheThinker/Tasks/Todo.java index 1335f8962..6fde0b373 100644 --- a/src/main/java/TheThinker/Tasks/Todo.java +++ b/src/main/java/TheThinker/Tasks/Todo.java @@ -1,5 +1,9 @@ package TheThinker.Tasks; +/** + * Represents a to-do type task. A to-do object contains + * task type , task description. + */ public class Todo extends Task{ public Todo(String taskDescription){ From 29fde76b5d9734d4ecb50f100cb4cf590b70b751 Mon Sep 17 00:00:00 2001 From: rexkoh425 Date: Mon, 23 Sep 2024 23:54:48 +0800 Subject: [PATCH 4/4] update javadoc for Ui package --- src/main/java/TheThinker/Ui/CommandLine.java | 25 +++++++++++++++++--- src/main/java/TheThinker/Ui/UiControl.java | 17 +++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/TheThinker/Ui/CommandLine.java b/src/main/java/TheThinker/Ui/CommandLine.java index 303582d58..1fa6d4096 100644 --- a/src/main/java/TheThinker/Ui/CommandLine.java +++ b/src/main/java/TheThinker/Ui/CommandLine.java @@ -6,9 +6,18 @@ import TheThinker.Tasks.TaskList; import java.io.IOException; -public class CommandLine { - - public static void pollForUserInputTillBye(NewFile data) { +/** + * CommandLine handles all the commandLine related method + */ +public interface CommandLine { + + /** + * Checks for user input and do corresponding command + * and write task to file till bye command. + * + * @param data File created to accept task input + */ + static void pollForUserInputTillBye(NewFile data) { String userInput; do{ userInput = getUserInputAndDoTask(); @@ -20,6 +29,11 @@ public static void pollForUserInputTillBye(NewFile data) { }while(!userInput.equals("bye")); } + /** + * Checks for user input and do corresponding command and write task to file. + * + * @return the original trimmed user input + */ private static String getUserInputAndDoTask() { String userInput; userInput = UserInputParser.getUserInput(); @@ -28,6 +42,11 @@ private static String getUserInputAndDoTask() { return userInput; } + /** + * Do corresponding actions depending on the command by the user. + * + * @param userAction the first word of the user input. + */ private static void doTaskAccordingToUserAction(String userAction){ UiControl.printSeparation(); try { diff --git a/src/main/java/TheThinker/Ui/UiControl.java b/src/main/java/TheThinker/Ui/UiControl.java index abe0957c7..38292b966 100644 --- a/src/main/java/TheThinker/Ui/UiControl.java +++ b/src/main/java/TheThinker/Ui/UiControl.java @@ -2,24 +2,27 @@ import TheThinker.Command.TheThinker; -public class UiControl { +/** + * Interface controls all the Ui methods + */ +public interface UiControl { - public static void printGreeting() { + static void printGreeting() { UiControl.printSeparation(); System.out.println("Hello! I'm " + TheThinker.NAME); System.out.println("What can I do for you?"); UiControl.printSeparation(); } - public static void printBye() { + static void printBye() { System.out.println("Bye. Hope to see you again soon!"); } - public static void printSeparation() { + static void printSeparation() { System.out.println("_".repeat(60)); } - public static void printHelp(){ + static void printHelp(){ System.out.println("Formats for the commands are : "); System.out.println("mark : mark [number]"); System.out.println("unmark : unmark [number]"); @@ -31,7 +34,7 @@ public static void printHelp(){ System.out.println("find : find [keyword]"); } - public static void printCommands(){ + static void printCommands(){ System.out.println("Command entered is not valid. Available commands are"); String[] commands = {"mark" , "unmark" , "todo" , "delete", "event" , "deadline" , "list" , "bye" , "get" , "find", "help (get format)"}; for(String command : commands){ @@ -39,7 +42,7 @@ public static void printCommands(){ } } - public static void printLoadingText(){ + static void printLoadingText(){ System.out.println("Loading file now........"); } }