From ea3fce825953597e1af95a0631ad1dfc6db55a97 Mon Sep 17 00:00:00 2001 From: ChanWeiJie Date: Sat, 29 Jan 2022 10:35:06 +0800 Subject: [PATCH] Add checkstyle.xml and suppressions.xml Created a new config and checkstyle folder to store both xml files. Updated the coding standard of respective java files with respect to the output of the xml files. --- config/checkstyle/checkstyle.xml | 403 ++++++++++++++++++ config/checkstyle/suppressions.xml | 10 + src/main/java/duke/command/AddCommand.java | 2 +- src/main/java/duke/command/Command.java | 4 +- src/main/java/duke/command/ExitCommand.java | 4 +- src/main/java/duke/command/FindCommand.java | 2 +- src/main/java/duke/command/MarkCommand.java | 2 +- src/main/java/duke/command/PrintCommand.java | 2 +- src/main/java/duke/command/UnmarkCommand.java | 2 +- .../java/duke/exception/DukeException.java | 2 +- src/main/java/duke/functionality/Parser.java | 26 +- src/main/java/duke/functionality/Storage.java | 21 +- .../java/duke/functionality/TaskList.java | 16 +- src/main/java/duke/functionality/Ui.java | 12 +- src/main/java/duke/main/Duke.java | 6 +- .../java/duke/functionality/ParserTest.java | 31 +- src/test/java/duke/task/TaskTest.java | 6 +- 17 files changed, 489 insertions(+), 62 deletions(-) create mode 100644 config/checkstyle/checkstyle.xml create mode 100644 config/checkstyle/suppressions.xml diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..4c001417ae --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..39efb6e4ac --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/src/main/java/duke/command/AddCommand.java b/src/main/java/duke/command/AddCommand.java index b710bb1d1a..ea7081de94 100644 --- a/src/main/java/duke/command/AddCommand.java +++ b/src/main/java/duke/command/AddCommand.java @@ -1,7 +1,7 @@ package duke.command; -import duke.task.Task; import duke.functionality.TaskList; +import duke.task.Task; /** * Represents the add command. A AddCommand object corresponds to adding that specified task diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index 48229c19d3..a305d8afac 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -1,12 +1,12 @@ package duke.command; -import duke.task.Task; import duke.functionality.TaskList; +import duke.task.Task; /** * Represents the commands inputted by a user. The Command class cannot be instantiated as it is an abstract class. */ -public abstract class Command{ +public abstract class Command { protected Task task; protected Integer index; protected String word; diff --git a/src/main/java/duke/command/ExitCommand.java b/src/main/java/duke/command/ExitCommand.java index 0c0940eb71..a09d3501ec 100644 --- a/src/main/java/duke/command/ExitCommand.java +++ b/src/main/java/duke/command/ExitCommand.java @@ -5,13 +5,13 @@ /** * Represents the exit command. A ExitCommand object corresponds to exiting the Duke program. */ -public class ExitCommand extends Command{ +public class ExitCommand extends Command { /** * Constructor for ExitCommand class. */ public ExitCommand() { - super(null, null,null); + super(null, null, null); } /** diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java index 079e3fde2f..0edc671e60 100644 --- a/src/main/java/duke/command/FindCommand.java +++ b/src/main/java/duke/command/FindCommand.java @@ -6,7 +6,7 @@ * Represents the find command. A FindCommand object corresponds to finding similar tasks * in the taskList of TaskList class. */ -public class FindCommand extends Command{ +public class FindCommand extends Command { /** * Constructor of FindCommand. diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java index 8ce98dba8f..159a96c802 100644 --- a/src/main/java/duke/command/MarkCommand.java +++ b/src/main/java/duke/command/MarkCommand.java @@ -12,7 +12,7 @@ public class MarkCommand extends Command { * @param number an indicator to the index of the taskList in TaskList class. */ public MarkCommand(Integer number) { - super(null, number,null); + super(null, number, null); } /** diff --git a/src/main/java/duke/command/PrintCommand.java b/src/main/java/duke/command/PrintCommand.java index 63d0c2d8f2..0a2943ba48 100644 --- a/src/main/java/duke/command/PrintCommand.java +++ b/src/main/java/duke/command/PrintCommand.java @@ -5,7 +5,7 @@ /** * Represents the print command. A PrintCommand object allows users to see all task in Duke TaskBot. */ -public class PrintCommand extends Command{ +public class PrintCommand extends Command { /** * Constructor for PrintCommand class. diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java index 1cdf8cfb0a..3e1b0401cb 100644 --- a/src/main/java/duke/command/UnmarkCommand.java +++ b/src/main/java/duke/command/UnmarkCommand.java @@ -6,7 +6,7 @@ * Represents the unmark command. A UnmarkCommand object allows users to set the corresponding task as * not done. */ -public class UnmarkCommand extends Command{ +public class UnmarkCommand extends Command { /** * Constructor for the UnmarkCommand class. diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java index f875022086..899b5a130f 100644 --- a/src/main/java/duke/exception/DukeException.java +++ b/src/main/java/duke/exception/DukeException.java @@ -4,7 +4,7 @@ * Represents the Exceptions the Duke program would handle. A DukeException object corresponds * to the exceptions specified and handled by Duke. */ -public class DukeException extends Exception{ +public class DukeException extends Exception { /** * Constructor for DukeException class. diff --git a/src/main/java/duke/functionality/Parser.java b/src/main/java/duke/functionality/Parser.java index 0573e791a7..0429e78085 100644 --- a/src/main/java/duke/functionality/Parser.java +++ b/src/main/java/duke/functionality/Parser.java @@ -5,14 +5,20 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; - -import duke.command.*; +import duke.command.AddCommand; +import duke.command.Command; +import duke.command.DeleteCommand; +import duke.command.ExitCommand; +import duke.command.FindCommand; +import duke.command.MarkCommand; +import duke.command.PrintCommand; +import duke.command.UnmarkCommand; import duke.exception.DukeException; +import duke.exception.IncompleteCommandException; +import duke.exception.InvalidCommandException; import duke.task.Deadline; import duke.task.Event; import duke.task.Todo; -import duke.exception.IncompleteCommandException; -import duke.exception.InvalidCommandException; /** * Represents the Parsing capabilities of the Duke project. A Parse object corresponds @@ -29,8 +35,8 @@ public class Parser { * @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"); + public static LocalDate formatDate(String input) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate date = LocalDate.parse(input, dtf); return date; } @@ -41,7 +47,7 @@ public static LocalDate formatDate(String input){ * @return formatted time. */ public static LocalTime formatTime(String input) { - DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm"); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmm"); LocalTime time = LocalTime.parse(input, dtf); return time; } @@ -52,7 +58,7 @@ public static LocalTime formatTime(String input) { * @return date but as a String. */ public static String dateToString(LocalDate input) { - DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyy-MM-dd"); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String date = input.format(dtf); return date; } @@ -63,7 +69,7 @@ public static String dateToString(LocalDate input) { * @return time but as a String. */ public static String timeToString(LocalTime input) { - DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm"); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmm"); String time = input.format(dtf); return time; } @@ -144,7 +150,7 @@ public static Command parse(String input) throws DukeException { } else if (command.equals("delete")) { return new DeleteCommand(Integer.parseInt(inputSplit[1])); - } else if(command.equals("find")) { + } else if (command.equals("find")) { return new FindCommand(inputSplit[1]); } else { diff --git a/src/main/java/duke/functionality/Storage.java b/src/main/java/duke/functionality/Storage.java index b153caa0cb..d51b71ea50 100644 --- a/src/main/java/duke/functionality/Storage.java +++ b/src/main/java/duke/functionality/Storage.java @@ -1,16 +1,15 @@ package duke.functionality; -import duke.task.Deadline; -import duke.task.Event; -import duke.task.Task; -import duke.task.Todo; - -import java.util.Scanner; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.util.Scanner; + +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; /** * Represents the Storage capabilities of the Duke project. A Storage object corresponds @@ -25,7 +24,7 @@ public class Storage { * @param pwd user's current working directory. * @param path path to "/data/TaskData.txt". */ - public Storage(String pwd, String path){ + public Storage(String pwd, String path) { Storage.pwd = pwd; Storage.path = path; } @@ -110,13 +109,13 @@ public static String craftOutput(Task task) { String output = ""; String doneIcon = task.getStatusIcon(); if (task instanceof Todo) { - if(doneIcon.equals("X")) { + if (doneIcon.equals("X")) { output = "T|1|" + task.getDescription(); } else { output = "T|0|" + task.getDescription(); } } else if (task instanceof Deadline) { - if(doneIcon.equals("X")) { + if (doneIcon.equals("X")) { output = "D|1|" + task.getDescription() + "|" + Parser.dateToString(((Deadline) task).getDate()) + "|" + Parser.timeToString(((Deadline) task).getTime()); } else { @@ -124,7 +123,7 @@ public static String craftOutput(Task task) { + "|" + Parser.timeToString(((Deadline) task).getTime()); } } else if (task instanceof Event) { - if(doneIcon.equals("X")) { + if (doneIcon.equals("X")) { output = "E|1|" + task.getDescription() + "|" + Parser.dateToString(((Event) task).getDate()) + "|" + Parser.timeToString(((Event) task).getStartTime()) + "|" + Parser.timeToString(((Event) task).getEndTime()); diff --git a/src/main/java/duke/functionality/TaskList.java b/src/main/java/duke/functionality/TaskList.java index 08cad2eac4..797e8fee13 100644 --- a/src/main/java/duke/functionality/TaskList.java +++ b/src/main/java/duke/functionality/TaskList.java @@ -36,7 +36,7 @@ public void deleteTask(int taskNum) { * @param taskNum an indicator to the index of taskList. */ public void markTask(int taskNum) { - String message = "Nice! I've marked this task as done:\n" ; + String message = "Nice! I've marked this task as done:\n"; int actualTaskNum = taskNum - 1; //minus 1 as list index is from 0 Task task = taskList.get(actualTaskNum); // get the task from the array task.setTaskDone(); @@ -60,11 +60,11 @@ public void unMarkTask(int taskNum) { /** * Returns nothing, but prints out all task in taskList. */ - public void printList(){ + public void printList() { String message = "Here are the tasks in your list:"; System.out.println(message); - for(int i = 0; i < numOfTask; i++){ + for (int i = 0; i < numOfTask; i++) { String output = i + 1 + "." + taskList.get(i).toString(); System.out.println(output); } @@ -82,19 +82,23 @@ public void addToList(Task task) { System.out.println(message + task.toString() + "\nNow you have " + numOfTask + " tasks in the list."); } + /** + * Returns nothing, but prints all task that contains that matches the specified word. + * @param word keyword input from user + */ public void findWord(String word) { String message = "Here are the matching tasks in your list:\n"; System.out.print(message); int counter = 1; - for(int i = 0; i < numOfTask; i++) { + for (int i = 0; i < numOfTask; i++) { Task task = taskList.get(i); - if(task.getDescription().contains(word)) { + if (task.getDescription().contains(word)) { String output = counter + "." + task; counter++; System.out.println(output); } } - if(counter == 1) { + if (counter == 1) { System.out.println("OOPS!, there are no matching task with the word provided."); } } diff --git a/src/main/java/duke/functionality/Ui.java b/src/main/java/duke/functionality/Ui.java index 7b925a1e67..7c7c235b52 100644 --- a/src/main/java/duke/functionality/Ui.java +++ b/src/main/java/duke/functionality/Ui.java @@ -1,16 +1,16 @@ package duke.functionality; -import duke.exception.BlankCommandException; - import java.util.Scanner; +import duke.exception.BlankCommandException; + /** * Represents the User Interface of the Duke project. A Ui object corresponds * to all user interface displays. Such as the messages. */ public class Ui { - private final String GREETING = "Hello! I'm TaskJamie\nWhat can i do for you?"; - private final String ENDING = "Bye. Hope to see you again soon!"; + private static final String GREETING = "Hello! I'm TaskJamie\nWhat can i do for you?"; + private static final String ENDING = "Bye. Hope to see you again soon!"; /** * Returns nothing, but prints out the greeting message of Duke TaskBot. @@ -36,7 +36,9 @@ public void showError(String error) { /** * Returns nothing, but prints out the error messages when loading in the text file. */ - public void showLoadingError(String error) { System.out.println(error); } + public void showLoadingError(String error) { + System.out.println(error); + } /** * Returns a full command gotten from user input. diff --git a/src/main/java/duke/main/Duke.java b/src/main/java/duke/main/Duke.java index bf4e6f2239..67cf1733be 100644 --- a/src/main/java/duke/main/Duke.java +++ b/src/main/java/duke/main/Duke.java @@ -3,11 +3,11 @@ import java.io.IOException; import duke.command.Command; +import duke.exception.DukeException; import duke.functionality.Parser; import duke.functionality.Storage; import duke.functionality.TaskList; import duke.functionality.Ui; -import duke.exception.DukeException; /** * Represents the starting point of the Duke project. A Duke object corresponds @@ -41,7 +41,7 @@ public Duke(String pwd, String filePath) { public void run() { this.ui.showGreeting(); boolean isExit = false; - while(!isExit) { + while (!isExit) { try { String fullCommand = ui.readCommand(); Command c = Parser.parse(fullCommand); @@ -60,6 +60,6 @@ public void run() { */ public static void main(String[] args) { String home = System.getProperty("user.home"); - new Duke(home,"/data/TaskData.txt").run(); + new Duke(home, "/data/TaskData.txt").run(); } } diff --git a/src/test/java/duke/functionality/ParserTest.java b/src/test/java/duke/functionality/ParserTest.java index 81a673d796..20cc551272 100644 --- a/src/test/java/duke/functionality/ParserTest.java +++ b/src/test/java/duke/functionality/ParserTest.java @@ -1,37 +1,38 @@ package duke.functionality; -import duke.exception.DukeException; - -import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; +import org.junit.jupiter.api.Test; + +import duke.exception.DukeException; + public class ParserTest { @Test public void testInvalidCommandException() { try { assertEquals(0, Parser.parse("blah")); - } catch (DukeException e ) { + } catch (DukeException e) { assertEquals("OOPS!!! I'm sorry, but I don't know what that means :-(", e.getMessage()); } } @Test - public void testIncompleteCommandException(){ + public void testIncompleteCommandException() { try { assertEquals(0, Parser.parse("todo")); - } catch (DukeException e ) { + } catch (DukeException e) { assertEquals("OOPS!!! The description of a todo cannot be empty.", e.getMessage()); } } @Test - public void dateToString_validDate_success(){ - DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyy-MM-dd"); + public void dateToString_validDate_success() { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate test1 = LocalDate.parse("2020-06-06", dtf); assertEquals("2020-06-06", Parser.dateToString(test1)); @@ -40,12 +41,12 @@ public void dateToString_validDate_success(){ } @Test - public void timeToString_validTime_success(){ - DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm"); - LocalTime test1 = LocalTime.parse("1800",dtf); - assertEquals("1800",Parser.timeToString(test1)); + public void timeToString_validTime_success() { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmm"); + LocalTime test1 = LocalTime.parse("1800", dtf); + assertEquals("1800", Parser.timeToString(test1)); - LocalTime test2 = LocalTime.parse("2400",dtf); - assertEquals("0000",Parser.timeToString(test2)); + LocalTime test2 = LocalTime.parse("2400", dtf); + assertEquals("0000", Parser.timeToString(test2)); } -} \ No newline at end of file +} diff --git a/src/test/java/duke/task/TaskTest.java b/src/test/java/duke/task/TaskTest.java index b691b0aa66..ab4fbe0144 100644 --- a/src/test/java/duke/task/TaskTest.java +++ b/src/test/java/duke/task/TaskTest.java @@ -1,8 +1,10 @@ package duke.task; -import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; + + public class TaskTest { @Test @@ -25,4 +27,4 @@ public void testSetters() { temp.setTaskNotDone(); assertEquals(" ", temp.getStatusIcon()); } -} \ No newline at end of file +}