Skip to content

Commit

Permalink
Merge branch 'branch-A-Gradle'
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren159 committed Sep 1, 2023
2 parents f77065e + 1789ab1 commit 29d04b9
Show file tree
Hide file tree
Showing 22 changed files with 540 additions and 95 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id 'application'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}

Expand Down Expand Up @@ -28,7 +29,7 @@ test {
}

application {
mainClass.set("seedu.duke.Duke")
mainClass.set("duke.Duke")
}

shadowJar {
Expand All @@ -40,3 +41,7 @@ shadowJar {
run{
standardInput = System.in
}

checkstyle {
toolVersion = '10.2'
}
434 changes: 434 additions & 0 deletions config/checkstyle/checkstyle.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<suppress checks="JavadocType" files=".*Test\.java"/>
<suppress checks="MissingJavadocMethodCheck" files=".*Test\.java"/>
</suppressions>
Empty file added data/tasks.txt
Empty file.
4 changes: 2 additions & 2 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
84 changes: 45 additions & 39 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -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<Task>{
import duke.task.Task;

public class TaskList implements Iterable<Task> {
private List<Task> tasks;

public TaskList() {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.showNumberOfTasks(tasks);
storage.save(tasks);
}
}
}
1 change: 0 additions & 1 deletion src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import duke.Storage;
import duke.TaskList;
import duke.Ui;
import duke.command.Command;

public class ExitCommand extends Command {
public ExitCommand() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import duke.Storage;
import duke.TaskList;
import duke.Ui;
import duke.command.Command;

public class ListCommand extends Command {
@Override
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duke/command/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duke/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/exception/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke.exception;

public class DukeException extends Exception{
public class DukeException extends Exception {
public DukeException(String errorMessage) {
super("☹ OOPS!!! " + errorMessage);
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/exception/EmptyDescriptionException.java
Original file line number Diff line number Diff line change
@@ -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.");
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/exception/InvalidArgumentException.java
Original file line number Diff line number Diff line change
@@ -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 :-(");
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke.task;

import duke.task.Task;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ public String toFileString() {
return " | " + (isDone ? "1" : "0") + " | " + this.description;
}

}
}
2 changes: 0 additions & 2 deletions src/main/java/duke/task/Todo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke.task;

import duke.task.Task;

public class Todo extends Task {
public Todo(String description) {
super(description);
Expand Down

0 comments on commit 29d04b9

Please sign in to comment.