From 7cfb0266b873bfa3c60fb9dd73b856a91a653378 Mon Sep 17 00:00:00 2001 From: rexkoh425 Date: Wed, 9 Oct 2024 17:32:45 +0800 Subject: [PATCH] update javadoc code quality --- .../java/thethinker/command/TheThinker.java | 2 +- .../exceptions/FormattingException.java | 2 +- src/main/java/thethinker/file/FileLoader.java | 6 +-- src/main/java/thethinker/file/NewFile.java | 6 ++- .../java/thethinker/parser/DateParser.java | 18 +++++---- .../thethinker/parser/DeadlineParser.java | 4 +- .../java/thethinker/parser/EventParser.java | 6 +-- .../java/thethinker/parser/TodoParser.java | 4 +- .../thethinker/parser/UserInputParser.java | 12 +++--- src/main/java/thethinker/tasks/TaskList.java | 37 ++++++++++++++++--- src/main/java/thethinker/ui/CommandLine.java | 8 ++-- 11 files changed, 68 insertions(+), 37 deletions(-) diff --git a/src/main/java/thethinker/command/TheThinker.java b/src/main/java/thethinker/command/TheThinker.java index e4d810eaf..4ae1c0bdb 100644 --- a/src/main/java/thethinker/command/TheThinker.java +++ b/src/main/java/thethinker/command/TheThinker.java @@ -7,7 +7,7 @@ /** * Class which contains the main function. - * Loads file , polls for user input till bye command is received + * Loads file , polls for user input till bye command is received. * If default file and user's newly input file is not valid , program ends. */ public class TheThinker{ diff --git a/src/main/java/thethinker/exceptions/FormattingException.java b/src/main/java/thethinker/exceptions/FormattingException.java index d0801fe6e..9881ae80d 100644 --- a/src/main/java/thethinker/exceptions/FormattingException.java +++ b/src/main/java/thethinker/exceptions/FormattingException.java @@ -1,7 +1,7 @@ package thethinker.exceptions; /** - * This exception is thrown whenever there are formatting errors in the command given by the user + * This exception is thrown whenever there are formatting errors in the command given by the user. */ public class FormattingException extends Exception{ diff --git a/src/main/java/thethinker/file/FileLoader.java b/src/main/java/thethinker/file/FileLoader.java index a2016749b..96060b59c 100644 --- a/src/main/java/thethinker/file/FileLoader.java +++ b/src/main/java/thethinker/file/FileLoader.java @@ -7,7 +7,7 @@ import java.io.IOException; /** - * Handles file loading operations when at the start of program + * Handles file loading operations when at the start of program. */ public class FileLoader { @@ -16,7 +16,7 @@ public class FileLoader { /** * Loads default filepath and check if it exists. - * If file does not exist , create a new file based on user input + * If file does not exist , create a new file based on user input. * * @throws FileNotFoundException If file creation failed. */ @@ -95,7 +95,7 @@ private static void createFolder(File directoryName) { } /** - * Get user input on whether they want to save task to a file + * Gets user input on whether they want to save task to a file. */ public static boolean shouldSaveTask() { UiControl.printSeparation(); diff --git a/src/main/java/thethinker/file/NewFile.java b/src/main/java/thethinker/file/NewFile.java index a5c9e1fe9..5ba1bb7c5 100644 --- a/src/main/java/thethinker/file/NewFile.java +++ b/src/main/java/thethinker/file/NewFile.java @@ -29,7 +29,7 @@ public boolean isFileExist() { } /** - * Read content of a file and adds all task to current task list. + * Reads content of a file and adds all task to current task list. * * @throws FileNotFoundException If the filepath is invalid. */ @@ -87,6 +87,8 @@ private void addTaskAccordingToFileData(String[] parameters) { } /** + * Writes all the task to the specified file. + * * @throws IOException If the filepath is invalid. */ public void writeTaskListToFile() throws IOException { @@ -97,7 +99,7 @@ public void writeTaskListToFile() throws IOException { } /** - * Converts task list into a load file format + * Converts task list into a load file format. * If TaskList is empty , an empty string will be returned. * * @return A single string of task list in file format. diff --git a/src/main/java/thethinker/parser/DateParser.java b/src/main/java/thethinker/parser/DateParser.java index a75c062fc..6e9f01815 100644 --- a/src/main/java/thethinker/parser/DateParser.java +++ b/src/main/java/thethinker/parser/DateParser.java @@ -27,7 +27,7 @@ private static String toString(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 + * @param date deadline of task extracted from user input. * @return date of string type with format e.g. 15 October 2019 , 6 pm. * */ @@ -66,9 +66,9 @@ private static int isValidDay(String day) { } /** - * Compares date according to the deadline of each task types. + * Checks if date matches according to the deadline of each task types. * - * @param task Task to compare + * @param task Task to compare. * @param specifiedDate date in format of dd/MM/yyyy. */ public static boolean isMatchingDateByType(Task task , String specifiedDate) { @@ -95,8 +95,10 @@ private static DateTimeFormatter getDateFormat(String date) { } /** - * @param taskDate Deadline corresponding to the task - * @param specifiedDate Queried date in any format + * Checks if the user given date and task date matches. + * + * @param taskDate Deadline corresponding to the task. + * @param specifiedDate Queried date in any format. */ private static boolean isMatchingDate(String taskDate , String specifiedDate) { @@ -155,10 +157,10 @@ private static boolean isResultDateTimeFormat(String dateStr) { } /** - * Parse date after get command and checks if queried date is of dd/mm/yyyy format + * Parses date after get command and checks if queried date is of dd/mm/yyyy format. * - * @return date in dd/MM/yyyy format - * @throws FormattingException If date is missing or in the wrong format(i.e. not dd/mm/yyyy) + * @return date in dd/MM/yyyy format. + * @throws FormattingException If date is missing or in the wrong format(i.e. not dd/mm/yyyy). */ public static String parseDateAfterGet() throws FormattingException { final int LENGTH_OF_GET = 3; diff --git a/src/main/java/thethinker/parser/DeadlineParser.java b/src/main/java/thethinker/parser/DeadlineParser.java index 078109b35..f5e2319f1 100644 --- a/src/main/java/thethinker/parser/DeadlineParser.java +++ b/src/main/java/thethinker/parser/DeadlineParser.java @@ -11,9 +11,9 @@ public class DeadlineParser extends UserInputParser{ public static final String DEADLINE_FORMAT = "Please follow format : deadline [task] /by [time]"; /** - * Parse user input based on the format of Deadline and create Deadline object. + * Parses user input based on the format of Deadline and create Deadline object. * - * @throws FormattingException If /by , task description , deadline is missing from user input + * @throws FormattingException If /by , task description , deadline is missing from user input. */ public static Deadline parseDeadline() throws FormattingException { diff --git a/src/main/java/thethinker/parser/EventParser.java b/src/main/java/thethinker/parser/EventParser.java index ce34d16b5..b84125f94 100644 --- a/src/main/java/thethinker/parser/EventParser.java +++ b/src/main/java/thethinker/parser/EventParser.java @@ -11,10 +11,10 @@ public class EventParser extends UserInputParser{ public static final String EVENT_FORMAT = "Please follow format : event [task] /from [start time] /to [end time]"; /** - * Parse user input based on the format of Event and use the result to create Event object. + * Parses user input based on the format of Event and use the result to create Event object. * - * @throws FormattingException If /from , /to , task description , start time and end time - * is missing from user input. If /to is in front of /from. + * @throws FormattingException If /from, /to, task description, start and end time is missing from user input. + * If /to is in front of /from. */ public static Event parseEvent() throws FormattingException { diff --git a/src/main/java/thethinker/parser/TodoParser.java b/src/main/java/thethinker/parser/TodoParser.java index 656d6c913..ddaf3f360 100644 --- a/src/main/java/thethinker/parser/TodoParser.java +++ b/src/main/java/thethinker/parser/TodoParser.java @@ -10,9 +10,9 @@ public class TodoParser extends UserInputParser{ public static final String TODO_FORMAT = "Please follow format : todo [task]"; /** - * Parse user input based on the format of To-do and create To-do object + * Parses user input based on the format of To-do and create To-do object. * - * @throws FormattingException if task description is not provided in user input + * @throws FormattingException if task description is not provided in user input. */ public static Task parseTodo() throws FormattingException { diff --git a/src/main/java/thethinker/parser/UserInputParser.java b/src/main/java/thethinker/parser/UserInputParser.java index a6943001e..e6d755f28 100644 --- a/src/main/java/thethinker/parser/UserInputParser.java +++ b/src/main/java/thethinker/parser/UserInputParser.java @@ -5,7 +5,7 @@ /** * Handles the parsing of input other than to-do , deadline , event and date related parsing. - * Parsing of To-do , deadline , event and date are done by their respective parsers + * Parsing of To-do , deadline , event and date are done by their respective parsers. */ public class UserInputParser { @@ -26,9 +26,9 @@ public static String parseUserAction() { } /** - * Used to obtain task number after inputting commands that require task number + * Obtains task number after inputting commands that require task number. * - * @return Task number + * @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. */ @@ -51,8 +51,10 @@ public static int parseNumberAfterTask(String task) throws NumberFormatException } /** - * @return keyword after removing space on the side - * @throws FormattingException If no keyword is provided or keyword is more than one word + * Extracts single word from user input after "find". + * + * @return keyword after removing space on the side. + * @throws FormattingException If no keyword is provided or keyword is more than one word. */ public static String parseKeywordAfterFind() throws FormattingException { diff --git a/src/main/java/thethinker/tasks/TaskList.java b/src/main/java/thethinker/tasks/TaskList.java index fc52c4a72..c4b7b7e3f 100644 --- a/src/main/java/thethinker/tasks/TaskList.java +++ b/src/main/java/thethinker/tasks/TaskList.java @@ -17,14 +17,19 @@ public static void addTask(Task task) { } /** - * Adds task to task list without printing any information to the console compared to addTask() + * Adds task to task list without printing any information to the console. */ public static void addTaskWithoutResponse(Task task) { listOfTasks.add(task); listLength++; } - public static void deleteTask(int taskNumber) { + /** + * Deletes task from current task list. + * + * @throws IndexOutOfBoundsException If number given is more than task list length. + */ + public static void deleteTask(int taskNumber) throws IndexOutOfBoundsException{ Task taskToRemove = listOfTasks.get(taskNumber-1); listLength--; @@ -35,15 +40,25 @@ public static void deleteTask(int taskNumber) { System.out.printf("Now you have %d tasks in the list.\n" , listLength); } - public static void setAsDone(int listNumber) throws IndexOutOfBoundsException { - Task currentTask = listOfTasks.get(listNumber-1); + /** + * Marks task from current task list. + * + * @throws IndexOutOfBoundsException If number given is more than task list length. + */ + public static void setAsDone(int taskNumber) throws IndexOutOfBoundsException { + Task currentTask = listOfTasks.get(taskNumber-1); System.out.println("Nice! I've marked this task as done:"); System.out.printf(" [%c][X] " + currentTask.getTaskDescription() + "\n" , currentTask.getTaskType()); currentTask.setMarkedAsDone(true); } - public static void setAsNotDone(int listNumber) throws IndexOutOfBoundsException { - Task currentTask = listOfTasks.get(listNumber-1); + /** + * Unmarks task from current task list. + * + * @throws IndexOutOfBoundsException If number given is more than task list length. + */ + public static void setAsNotDone(int taskNumber) throws IndexOutOfBoundsException { + Task currentTask = listOfTasks.get(taskNumber-1); System.out.println("OK, I've marked this task as not done yet:"); System.out.printf(" [%c][ ] " + currentTask.getTaskDescription() + "\n" , currentTask.getTaskType()); currentTask.setMarkedAsDone(false); @@ -57,6 +72,11 @@ public static void listTasks() { } } + /** + * Lists all the task with deadline same as date given. + * + * @param date should be dd/MM/yyyy format. + */ public static void listTasksOfDate(String date){ System.out.println("Here are the tasks in your list in " + date + " :"); int counter = 0; @@ -74,6 +94,11 @@ public static void listTasksOfDate(String date){ } } + /** + * Lists all the task in Task List which contains the keyword. + * + * @param keyword one single word only. + */ public static void listTasksOfKeyword(String keyword) { System.out.println("Here are the matching tasks in your list:"); diff --git a/src/main/java/thethinker/ui/CommandLine.java b/src/main/java/thethinker/ui/CommandLine.java index 4079a119f..ba217c01b 100644 --- a/src/main/java/thethinker/ui/CommandLine.java +++ b/src/main/java/thethinker/ui/CommandLine.java @@ -10,8 +10,8 @@ public interface CommandLine { /** - * Checks for user input and do corresponding command - * and write task to file till bye command. + * Checks for user input and do corresponding command. + * Write task to file till bye command. */ static void pollForUserInputTillBye(boolean isWriteTask) { String userAction; @@ -33,7 +33,7 @@ static void pollForUserInputTillBye(boolean isWriteTask) { /** * Checks for user input and do corresponding command and write task to file. * - * @return the original trimmed user action + * @return the original trimmed user action. */ private static String getUserActionAndDoTask() { String userInput = UserInputParser.getUserInput(); @@ -43,7 +43,7 @@ private static String getUserActionAndDoTask() { } /** - * Do corresponding actions depending on the command by the user. + * Selects task to do according to the command by the user. * * @param userAction the first word of the user input. */