Skip to content

Commit

Permalink
Merge branch 'branch-A-Checkstyle' with gradle checkstyle support
Browse files Browse the repository at this point in the history
  • Loading branch information
Illio Suardi committed Sep 1, 2020
2 parents 776268e + 6d2d072 commit 9572022
Show file tree
Hide file tree
Showing 11 changed files with 614 additions and 197 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
src/main/data
403 changes: 403 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>
286 changes: 143 additions & 143 deletions src/main/java/duke/Command.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke;

import java.time.format.DateTimeParseException;
import java.util.List;

import duke.resource.TaskList;
Expand All @@ -9,7 +10,6 @@
import duke.task.ToDo;
import duke.util.DukeException;

import java.time.format.DateTimeParseException;

/**
* Command class that handles the logic flow of commands input.
Expand Down Expand Up @@ -41,158 +41,158 @@ public Command(String[] input) {
public void execute(TaskList tasks, Ui ui, Storage storage)
throws DukeException {
switch(input[0]) {
case "bye":
ui.printBye();
this.shouldExit = true;
break;
case "list": {
ui.printList(tasks);
break;
}
case "done": {
int index;
if (input.length == 1) {
throw new DukeException(" Please select a task to mark as completed!");
}
try {
index = Integer.parseInt(input[1]);
} catch (NumberFormatException e) {
throw new DukeException(" Please choose an integer value!");
}
if (index <= 0) {
throw new DukeException(" Please choose an integer greater than 0!");
} else if (index > tasks.size()) {
throw new DukeException(" Your task list is not that long yet!");
}
tasks.completeTask(index);
ui.printDone(tasks.getTask(index));
storage.save(tasks);
break;
case "bye":
ui.printBye();
this.shouldExit = true;
break;
case "list": {
ui.printList(tasks);
break;
}
case "done": {
int index;
if (input.length == 1) {
throw new DukeException(" Please select a task to mark as completed!");
}
case "delete": {
int index;
if (input.length == 1) {
throw new DukeException(" Please select a task to mark as completed!");
}
try {
index = Integer.parseInt(input[1]);
} catch (NumberFormatException e) {
throw new DukeException(" Please choose an integer value!");
}
if (index <= 0) {
throw new DukeException(" Please choose an integer greater than 0!");
} else if (index > tasks.size()) {
throw new DukeException(" Your task list is not that long yet!");
try {
index = Integer.parseInt(input[1]);
} catch (NumberFormatException e) {
throw new DukeException(" Please choose an integer value!");
}
if (index <= 0) {
throw new DukeException(" Please choose an integer greater than 0!");
} else if (index > tasks.size()) {
throw new DukeException(" Your task list is not that long yet!");
}
tasks.completeTask(index);
ui.printDone(tasks.getTask(index));
storage.save(tasks);
break;
}
case "delete": {
int index;
if (input.length == 1) {
throw new DukeException(" Please select a task to mark as completed!");
}
try {
index = Integer.parseInt(input[1]);
} catch (NumberFormatException e) {
throw new DukeException(" Please choose an integer value!");
}
if (index <= 0) {
throw new DukeException(" Please choose an integer greater than 0!");
} else if (index > tasks.size()) {
throw new DukeException(" Your task list is not that long yet!");
}
Task task = tasks.getTask(index);
tasks.deleteTask(index);
ui.printDelete(tasks, task);
storage.save(tasks);
break;
}
case "find": {
if (input.length == 1) {
throw new DukeException(" Please use a keyword you'd like to search with!");
}
if (input.length > 2) {
throw new DukeException(" Please use only one keyword!");
}
List<Task> matches = tasks.search(input[1]);
ui.printFind(matches);
break;
}
case "deadline": {
Task task;
StringBuilder description = new StringBuilder();
StringBuilder time = new StringBuilder();
if (input.length == 1) {
throw new DukeException(" A deadline requires a description and a time!");
}
int i = 1;
while (!input[i].equals("/by")) {
description.append(input[i++]).append(" ");
if (i == input.length) {
throw new DukeException(" deadline requires the use of \"/by\"!");
}
Task task = tasks.getTask(index);
tasks.deleteTask(index);
ui.printDelete(tasks, task);
}
if (description.length() == 0) {
throw new DukeException(" The description of a deadline cannot be empty!");
}
while (++i < input.length) {
time.append(input[i]).append(" ");
}
if (time.length() == 0) {
throw new DukeException(" The time of a deadline cannot be empty!");
}
description.deleteCharAt(description.length() - 1);
time.deleteCharAt(time.length() - 1);
try {
task = new Deadline(description.toString(), time.toString(), false);
tasks.addTask(task);
ui.printAdd(tasks, task);
storage.save(tasks);
break;
} catch (DateTimeParseException e) {
throw new DukeException(
" Error: Please use the following format instead:\n"
+ " dd-MM-yyyy HHmm");
}
case "find": {
if (input.length == 1) {
throw new DukeException(" Please use a keyword you'd like to search with!");
}
if (input.length > 2) {
throw new DukeException(" Please use only one keyword!");
}
List<Task> matches = tasks.search(input[1]);
ui.printFind(matches);
break;
}
case "deadline": {
Task task;
StringBuilder description = new StringBuilder();
StringBuilder time = new StringBuilder();
if (input.length == 1) {
throw new DukeException(" A deadline requires a description and a time!");
}
int i = 1;
while (!input[i].equals("/by")) {
description.append(input[i++]).append(" ");
if (i == input.length) {
throw new DukeException(" deadline requires the use of \"/by\"!");
}
}
if (description.length() == 0) {
throw new DukeException(" The description of a deadline cannot be empty!");
}
while (++i < input.length) {
time.append(input[i]).append(" ");
}
if (time.length() == 0) {
throw new DukeException(" The time of a deadline cannot be empty!");
}
description.deleteCharAt(description.length() - 1);
time.deleteCharAt(time.length() - 1);
try {
task = new Deadline(description.toString(), time.toString(), false);
tasks.addTask(task);
ui.printAdd(tasks, task);
storage.save(tasks);
} catch (DateTimeParseException e) {
throw new DukeException(
" Error: Please use the following format instead:\n" +
" dd-MM-yyyy HHmm");
}
break;
}
case "event": {
Task task;
StringBuilder description = new StringBuilder();
StringBuilder time = new StringBuilder();
if (input.length == 1) {
throw new DukeException(" An event requires a description and a time!");
}
int i = 1;
while (!input[i].equals("/at")) {
description.append(input[i++]).append(" ");
if (i == input.length) {
throw new DukeException(" event requires the use of \"/at\"!");
}
}
if (description.length() == 0) {
throw new DukeException(" The description of an event cannot be empty!");
}
while (++i < input.length) {
time.append(input[i]).append(" ");
}
if (time.length() == 0) {
throw new DukeException(" The time of an event cannot be empty!");
}
description.deleteCharAt(description.length() - 1);
time.deleteCharAt(time.length() - 1);
try {
task = new Event(description.toString(), time.toString(), false);
tasks.addTask(task);
ui.printAdd(tasks, task);
storage.save(tasks);
} catch (DateTimeParseException e) {
throw new DukeException(
" Error: Please use the following format instead:\n" +
" dd-MM-yyyy HHmm");
}
break;
break;
}
case "event": {
Task task;
StringBuilder description = new StringBuilder();
StringBuilder time = new StringBuilder();
if (input.length == 1) {
throw new DukeException(" An event requires a description and a time!");
}
case "todo": {
if (input.length == 1) {
throw new DukeException(" The description of a todo cannot be empty!");
int i = 1;
while (!input[i].equals("/at")) {
description.append(input[i++]).append(" ");
if (i == input.length) {
throw new DukeException(" event requires the use of \"/at\"!");
}
Task task;
StringBuilder description = new StringBuilder();
for (int i = 1; i < input.length; i++) {
description.append(input[i]).append(" ");
}
description.deleteCharAt(description.length() - 1);
task = new ToDo(description.toString(), false);
}
if (description.length() == 0) {
throw new DukeException(" The description of an event cannot be empty!");
}
while (++i < input.length) {
time.append(input[i]).append(" ");
}
if (time.length() == 0) {
throw new DukeException(" The time of an event cannot be empty!");
}
description.deleteCharAt(description.length() - 1);
time.deleteCharAt(time.length() - 1);
try {
task = new Event(description.toString(), time.toString(), false);
tasks.addTask(task);
ui.printAdd(tasks, task);
storage.save(tasks);
break;
} catch (DateTimeParseException e) {
throw new DukeException(
" Error: Please use the following format instead:\n"
+ " dd-MM-yyyy HHmm");
}
break;
}
case "todo": {
if (input.length == 1) {
throw new DukeException(" The description of a todo cannot be empty!");
}
Task task;
StringBuilder description = new StringBuilder();
for (int i = 1; i < input.length; i++) {
description.append(input[i]).append(" ");
}
default:
throw new DukeException(" I'm sorry, but I don't know what that means :-(");
description.deleteCharAt(description.length() - 1);
task = new ToDo(description.toString(), false);
tasks.addTask(task);
ui.printAdd(tasks, task);
storage.save(tasks);
break;
}
default:
throw new DukeException(" I'm sorry, but I don't know what that means :-(");
}
}

Expand Down
20 changes: 11 additions & 9 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public List<Task> load() throws DukeException {
br.lines().forEach(str -> {
try {
list.add(Task.parse(str));
} catch (DukeException de){
System.out.println(" Error: "+ de.getMessage());
} catch (DukeException de) {
System.out.println(" Error: " + de.getMessage());
}
});
} catch (FileNotFoundException e) {
Expand All @@ -55,14 +55,14 @@ public List<Task> load() throws DukeException {
new File("./src/main/data/duke.txt").createNewFile();
} catch (IOException ioe) {
throw new DukeException(
"Sorry, the file couldn't be created!\n" +
"Please try again.");
"Sorry, the file couldn't be created!\n"
+ "Please try again.");
}
throw new DukeException(
" No save file found in [root]/src/main/data/duke.txt.\n" +
" A file has been created by default.\n" +
" If you'd like to import one, simply copy the file\n" +
" over to the above location and rerun me!");
" No save file found in [root]/src/main/data/duke.txt.\n"
+ " A file has been created by default.\n"
+ " If you'd like to import one, simply copy the file\n"
+ " over to the above location and rerun me!");
}
return list;
}
Expand All @@ -81,7 +81,9 @@ public void save(TaskList tasks) {
FileWriter fw = new FileWriter("./src/main/data/duke.txt");
fw.write(toWrite);
fw.close();
} catch (IOException ignored) { }
} catch (IOException ignored) {
return;
}
}

}

0 comments on commit 9572022

Please sign in to comment.