diff --git a/build.gradle b/build.gradle index a388517ae1..9c00a7e1e5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'application' + id 'checkstyle' id 'com.github.johnrengelman.shadow' version '7.1.2' } @@ -28,7 +29,7 @@ test { } application { - mainClass.set("seedu.duke.Duke") + mainClass.set("duke.Duke") } shadowJar { @@ -40,3 +41,7 @@ shadowJar { run{ standardInput = System.in } + +checkstyle { + toolVersion = '10.2' +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..acac1a8e28 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..135ea49ee0 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 1aa1e7977c..60dc37c7bc 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -35,7 +35,7 @@ public void run() { } } } - public static void main(String[] args){ + public static void main(String[] args) { new Duke("data/tasks.txt").run(); } -} \ No newline at end of file +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 058ca2879a..0fcaf968fc 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,6 +1,12 @@ package duke; -import duke.command.*; +import duke.command.AddCommand; +import duke.command.Command; +import duke.command.DeleteCommand; +import duke.command.ExitCommand; +import duke.command.ListCommand; +import duke.command.MarkCommand; +import duke.command.UnmarkCommand; import duke.exception.InvalidArgumentException; import duke.task.Deadline; import duke.task.Event; @@ -14,51 +20,51 @@ public enum CommandType { public static Command parse(String userInput) throws InvalidArgumentException { CommandType commandType = parseCommand(userInput); switch (commandType) { - case LIST: - return new ListCommand(); + case LIST: + return new ListCommand(); - case DELETE: - // Extract the index to delete - int deleteIndex = Integer.parseInt(userInput.split(" ")[1]); - return new DeleteCommand(deleteIndex); + case DELETE: + // Extract the index to delete + int deleteIndex = Integer.parseInt(userInput.split(" ")[1]); + return new DeleteCommand(deleteIndex); - case MARK: - // Extract the index to mark - int markIndex = Integer.parseInt(userInput.split(" ")[1]); - return new MarkCommand(markIndex); + case MARK: + // Extract the index to mark + int markIndex = Integer.parseInt(userInput.split(" ")[1]); + return new MarkCommand(markIndex); - case UNMARK: - // Extract the index to unmark - int unmarkIndex = Integer.parseInt(userInput.split(" ")[1]); - return new UnmarkCommand(unmarkIndex); + case UNMARK: + // Extract the index to unmark + int unmarkIndex = Integer.parseInt(userInput.split(" ")[1]); + return new UnmarkCommand(unmarkIndex); - case ADD: - if (userInput.startsWith("todo")) { - String taskName = userInput.substring(5).trim(); - return new AddCommand(new Todo(taskName)); - } else { - String trim = userInput.substring(userInput.indexOf(' ') + 1).trim(); - if (userInput.startsWith("deadline")) { - int deadlineIndex = trim.indexOf("/by"); - String taskDeadline = trim.substring(deadlineIndex + 4).trim(); - String taskName = trim.substring(0, deadlineIndex).trim(); - return new AddCommand(new Deadline(taskName, taskDeadline)); - } else if (userInput.startsWith("event")) { - int fromIndex = trim.indexOf("/from"); - int toIndex = trim.indexOf("/to"); - String taskFrom = trim.substring(fromIndex + 6, toIndex - 1).trim(); - String taskTo = trim.substring(toIndex + 4).trim(); - String taskName = trim.substring(0, fromIndex).trim(); - return new AddCommand(new Event(taskName, taskFrom, taskTo)); - } + case ADD: + if (userInput.startsWith("todo")) { + String taskName = userInput.substring(5).trim(); + return new AddCommand(new Todo(taskName)); + } else { + String trim = userInput.substring(userInput.indexOf(' ') + 1).trim(); + if (userInput.startsWith("deadline")) { + int deadlineIndex = trim.indexOf("/by"); + String taskDeadline = trim.substring(deadlineIndex + 4).trim(); + String taskName = trim.substring(0, deadlineIndex).trim(); + return new AddCommand(new Deadline(taskName, taskDeadline)); + } else if (userInput.startsWith("event")) { + int fromIndex = trim.indexOf("/from"); + int toIndex = trim.indexOf("/to"); + String taskFrom = trim.substring(fromIndex + 6, toIndex - 1).trim(); + String taskTo = trim.substring(toIndex + 4).trim(); + String taskName = trim.substring(0, fromIndex).trim(); + return new AddCommand(new Event(taskName, taskFrom, taskTo)); } - break; + } + break; - case BYE: - return new ExitCommand(); + case BYE: + return new ExitCommand(); - default: - throw new InvalidArgumentException(); + default: + throw new InvalidArgumentException(); } return null; diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 5a8e8dfb81..5707c71587 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,11 +1,5 @@ package duke; -import duke.exception.InvalidArgumentException; -import duke.task.Deadline; -import duke.task.Event; -import duke.task.Task; -import duke.task.Todo; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; @@ -14,6 +8,12 @@ import java.util.List; import java.util.Scanner; +import duke.exception.InvalidArgumentException; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + public class Storage { private final String filePath; @@ -57,7 +57,7 @@ public void save(TaskList list) { System.out.println("An error occurred while saving tasks to disk."); } } - private static Task parseFromFile(String line) throws InvalidArgumentException{ + private static Task parseFromFile(String line) throws InvalidArgumentException { String[] parts = line.split(" \\| "); String type = parts[0]; boolean isDone = parts[1].equals("1"); @@ -66,22 +66,22 @@ private static Task parseFromFile(String line) throws InvalidArgumentException{ Task task; switch (type) { - case "T": - task = new Todo(description); - break; - case "D": - String deadline = parts[3]; - task = new Deadline(description, deadline); - break; - case "E": - String eventTime = parts[3]; - int toIndex = eventTime.indexOf("to"); - String from = eventTime.substring(0, toIndex).trim(); - String to = eventTime.substring(toIndex + 2).trim(); - task = new Event(description, from, to); - break; - default: - throw new InvalidArgumentException(); + case "T": + task = new Todo(description); + break; + case "D": + String deadline = parts[3]; + task = new Deadline(description, deadline); + break; + case "E": + String eventTime = parts[3]; + int toIndex = eventTime.indexOf("to"); + String from = eventTime.substring(0, toIndex).trim(); + String to = eventTime.substring(toIndex + 2).trim(); + task = new Event(description, from, to); + break; + default: + throw new InvalidArgumentException(); } if (isDone) { diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 3ab7e4ad0b..afbc423b1d 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -1,12 +1,12 @@ package duke; -import duke.task.Task; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; -public class TaskList implements Iterable{ +import duke.task.Task; + +public class TaskList implements Iterable { private List tasks; public TaskList() { diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index d50234c64c..c1419bc871 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -1,23 +1,23 @@ package duke; -import duke.task.Task; - import java.util.Scanner; +import duke.task.Task; + public class Ui { - String logo = " ___ _ ___ ________ __ ____ __________ ____ _ __\n" - + " / | / | / / | / / __ \\ \\/ / / __ \\ /_ __/ __ \\/ __ \\/ | / /\n" - + " / /| | / |/ / |/ / / / /\\ /_____/ / / /_____/ / / /_/ / / / / |/ / \n" - + " / ___ |/ /| / /| / /_/ / / /_____/ /_/ /_____/ / / _, _/ /_/ / /| / \n" - + "/_/ |_/_/ |_/_/ |_/\\____/ /_/ \\____/ /_/ /_/ |_|\\____/_/ |_/ \n"; - String horizontalLine = "__________________________________________________________________________"; - String byeMessage = "Bye. Hope to see you again soon!"; + private String horizontalLine = "__________________________________________________________________________"; public void showWelcome() { + String logo = " ___ _ ___ ________ __ ____ __________ ____ _ __\n" + + " / | / | / / | / / __ \\ \\/ / / __ \\ /_ __/ __ \\/ __ \\/ | / /\n" + + " / /| | / |/ / |/ / / / /\\ /_____/ / / /_____/ / / /_/ / / / / |/ / \n" + + " / ___ |/ /| / /| / /_/ / / /_____/ /_/ /_____/ / / _, _/ /_/ / /| / \n" + + "/_/ |_/_/ |_/_/ |_/\\____/ /_/ \\____/ /_/ /_/ |_|\\____/_/ |_/ \n"; System.out.println(horizontalLine + logo + "Hello! I'm ANNOY-O-TRON!\nWhat can I do for you?\n" + horizontalLine); } public void showBye() { + String byeMessage = "Bye. Hope to see you again soon!"; System.out.println(byeMessage); } public void showLine() { diff --git a/src/main/java/duke/command/AddCommand.java b/src/main/java/duke/command/AddCommand.java index 4187ff1a91..7ed6277337 100644 --- a/src/main/java/duke/command/AddCommand.java +++ b/src/main/java/duke/command/AddCommand.java @@ -5,7 +5,7 @@ import duke.Ui; import duke.task.Task; -public class AddCommand extends Command{ +public class AddCommand extends Command { private Task task; public AddCommand(Task task) { diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java index cb875cc323..fcb5eb7350 100644 --- a/src/main/java/duke/command/DeleteCommand.java +++ b/src/main/java/duke/command/DeleteCommand.java @@ -19,4 +19,4 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { ui.showNumberOfTasks(tasks); storage.save(tasks); } -} \ No newline at end of file +} diff --git a/src/main/java/duke/command/ExitCommand.java b/src/main/java/duke/command/ExitCommand.java index 4de7b54d76..44b817cb4e 100644 --- a/src/main/java/duke/command/ExitCommand.java +++ b/src/main/java/duke/command/ExitCommand.java @@ -3,7 +3,6 @@ import duke.Storage; import duke.TaskList; import duke.Ui; -import duke.command.Command; public class ExitCommand extends Command { public ExitCommand() { diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java index 4e667a36c4..07503ad336 100644 --- a/src/main/java/duke/command/ListCommand.java +++ b/src/main/java/duke/command/ListCommand.java @@ -3,7 +3,6 @@ import duke.Storage; import duke.TaskList; import duke.Ui; -import duke.command.Command; public class ListCommand extends Command { @Override diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java index c1fa9f516f..271c320023 100644 --- a/src/main/java/duke/command/MarkCommand.java +++ b/src/main/java/duke/command/MarkCommand.java @@ -3,7 +3,6 @@ import duke.Storage; import duke.TaskList; import duke.Ui; -import duke.command.Command; import duke.task.Task; public class MarkCommand extends Command { diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java index 829ee265af..92b82275ba 100644 --- a/src/main/java/duke/command/UnmarkCommand.java +++ b/src/main/java/duke/command/UnmarkCommand.java @@ -3,7 +3,6 @@ import duke.Storage; import duke.TaskList; import duke.Ui; -import duke.command.Command; import duke.task.Task; public class UnmarkCommand extends Command { diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java index cc86b9129d..2a9671b53b 100644 --- a/src/main/java/duke/exception/DukeException.java +++ b/src/main/java/duke/exception/DukeException.java @@ -1,6 +1,6 @@ package duke.exception; -public class DukeException extends Exception{ +public class DukeException extends Exception { public DukeException(String errorMessage) { super("☹ OOPS!!! " + errorMessage); } diff --git a/src/main/java/duke/exception/EmptyDescriptionException.java b/src/main/java/duke/exception/EmptyDescriptionException.java index c97079d761..d7726297c3 100644 --- a/src/main/java/duke/exception/EmptyDescriptionException.java +++ b/src/main/java/duke/exception/EmptyDescriptionException.java @@ -1,7 +1,5 @@ package duke.exception; -import duke.exception.DukeException; - public class EmptyDescriptionException extends DukeException { public EmptyDescriptionException() { super("The description of a todo cannot be empty."); diff --git a/src/main/java/duke/exception/InvalidArgumentException.java b/src/main/java/duke/exception/InvalidArgumentException.java index 8ee02222d8..423ba3dde4 100644 --- a/src/main/java/duke/exception/InvalidArgumentException.java +++ b/src/main/java/duke/exception/InvalidArgumentException.java @@ -1,7 +1,5 @@ package duke.exception; -import duke.exception.DukeException; - public class InvalidArgumentException extends DukeException { public InvalidArgumentException() { super("I'm sorry, but I don't know what that means :-("); diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 960e463e34..07d5680370 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,7 +1,5 @@ package duke.task; -import duke.task.Task; - import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 7fb62607f2..ec1a767665 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -18,12 +18,14 @@ public Event(String description, String from, String to) { @Override public String toString() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm"); - return "[E]" + super.toString() + " (from: " + this.from.format(formatter) + " to: " + this.to.format(formatter) + ")"; + return "[E]" + super.toString() + " (from: " + this.from.format(formatter) + " to: " + + this.to.format(formatter) + ")"; } @Override public String toFileString() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"); - return "E | " + (isDone ? "1" : "0") + " | " + this.description + " | " + this.from.format(formatter) + " to " + this.to.format(formatter); + return "E | " + (isDone ? "1" : "0") + " | " + this.description + " | " + this.from.format(formatter) + + " to " + this.to.format(formatter); } } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 1b66222a10..d97970ce7f 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -30,4 +30,4 @@ public String toFileString() { return " | " + (isDone ? "1" : "0") + " | " + this.description; } -} \ No newline at end of file +} diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index f0d1280245..1417acadc8 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,7 +1,5 @@ package duke.task; -import duke.task.Task; - public class Todo extends Task { public Todo(String description) { super(description);