Skip to content

Commit

Permalink
Ensure code compliance with checkstyle guidelines
Browse files Browse the repository at this point in the history
Code is unable to pass Continuous Integration automated build checks due
to violations of checkstyle requirements.

Let's,
 * Rectify all checkstyle violations.
  • Loading branch information
macareonie committed Feb 11, 2024
1 parent 46430a2 commit f9062b8
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 67 deletions.
7 changes: 5 additions & 2 deletions src/main/java/tsundere/Tsundere.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package tsundere;

import javafx.application.Application;

import tsundere.task.Storage;

/**
* Encapsulates the main Tsundere chatbot object.
*/
public class Tsundere {

public static Storage storage;
private static Storage storage;

/**
* Initializes Tsundere with Storage.
Expand All @@ -18,6 +17,10 @@ public Tsundere() {
storage = new Storage();
}

public static Storage getStorage() {
return Tsundere.storage;
}

/**
* Launches the GUI application.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tsundere/exception/GeneralException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package tsundere.exception;

/**
* Encapsulates an Exception that contains a general message.
*/
public class GeneralException extends Exception {

protected final String msg;
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/tsundere/gui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package tsundere.gui;

import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand All @@ -11,12 +15,6 @@
import tsundere.Tsundere;
import tsundere.ui.Ui;

import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;



/**
* Controller for MainWindow. Provides the layout for the other controls.
*/
Expand All @@ -30,10 +28,10 @@ public class MainWindow extends AnchorPane {
@FXML
private Button sendButton;

private final Image USER_IMAGE = new Image(Objects.requireNonNull(this.getClass().
getResourceAsStream("/images/ok.png")));
private final Image TSUN_IMAGE = new Image(Objects.requireNonNull(this.getClass().
getResourceAsStream("/images/chitoge.png")));
private Image userImage = new Image(Objects.requireNonNull(this.getClass()
.getResourceAsStream("/images/ok.png")));
private Image tsunImage = new Image(Objects.requireNonNull(this.getClass()
.getResourceAsStream("/images/chitoge.png")));

/**
* Creates GUI with an initial dialog box with the greeting statement.
Expand All @@ -43,7 +41,7 @@ public void initialize() {
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
dialogContainer.getChildren().addAll(
DialogBox.getTsundereDialog("Don't get the wrong idea!\n"
+ "I'm not doing this to help you or anything!\n", TSUN_IMAGE)
+ "I'm not doing this to help you or anything!\n", tsunImage)
);
}

Expand All @@ -57,7 +55,7 @@ public void setTsundere(Tsundere t) {
* @throws IOException if savefile cannot be created.
*/
private void exit() throws InterruptedException, IOException {
Tsundere.storage.saveTasksToFile();
Tsundere.getStorage().saveTasksToFile();
TimeUnit.SECONDS.sleep(1);
Platform.exit();
System.exit(0);
Expand All @@ -74,9 +72,9 @@ private void handleUserInput() {

if (input.equalsIgnoreCase("bye")) {
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(input, USER_IMAGE),
DialogBox.getUserDialog(input, userImage),
DialogBox.getTsundereDialog("Don't forget about me!\n"
+ "You better come back soon!\n", TSUN_IMAGE)
+ "You better come back soon!\n", tsunImage)
);
try {
this.exit();
Expand All @@ -89,8 +87,8 @@ private void handleUserInput() {
Ui ui = new Ui();
String response = ui.chat(input);
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(input, USER_IMAGE),
DialogBox.getTsundereDialog(response, TSUN_IMAGE)
DialogBox.getUserDialog(input, userImage),
DialogBox.getTsundereDialog(response, tsunImage)
);
userInput.clear();
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/tsundere/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package tsundere.task;

import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* Encapsulates a Deadline object.
*/
public class Deadline extends Task {

private static final String TYPE = "D";
protected String by;
protected LocalDate date;
protected static final String TYPE = "D";


/**
* Initializes Deadline task with its name.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tsundere/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Encapsulates an Event object.
*/
public class Event extends Task {

private static final String TYPE = "E";
protected String from;
protected String to;

protected static final String TYPE = "E";

/**
* Initializes Event task with its name.
*
Expand Down Expand Up @@ -39,6 +39,6 @@ public String toSaveString() {
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to +")";
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}
}
14 changes: 5 additions & 9 deletions src/main/java/tsundere/task/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import java.util.ArrayList;
import java.util.Scanner;

Expand All @@ -17,9 +16,6 @@
public class Storage {

private static final String FILEPATH = "./data/data.txt";
private final String SAVED_SUCCESS_MSG = "Your session has been saved.";
private final String LOADED_SUCCESS_MSG = "Your previous session has been restored. Enjoy your chat.";
private final String LOADED_FAILURE_MSG = "Something went wrong with loading your previous session data!";

/**
* Initializes Storage.
Expand All @@ -30,7 +26,7 @@ public Storage() {
new File("./data").mkdirs();
TaskList.taskList = loadTasksFromFile();
} catch (IOException | GeneralException e) {
System.out.println(LOADED_FAILURE_MSG);
System.out.println("Something went wrong with loading your previous session data!");
}

}
Expand All @@ -48,15 +44,15 @@ public void saveTasksToFile() throws IOException {
for (Task task : TaskList.taskList) {
pw.println(task.toSaveString());
}
System.out.println(SAVED_SUCCESS_MSG);
System.out.println("Your session has been saved.");

} catch (FileNotFoundException e) {

File file = new File(FILEPATH);

if (file.createNewFile()) {
saveTasksToFile();
System.out.println(SAVED_SUCCESS_MSG);
System.out.println("Your session has been saved.");
} else {
throw new IOException("Unable to create the file: " + FILEPATH);
}
Expand Down Expand Up @@ -86,7 +82,7 @@ private ArrayList<Task> loadTasksFromFile() throws IOException, GeneralException
Task task = parseTaskFromSaveString(line);
tasks.add(task);
}
System.out.println(LOADED_SUCCESS_MSG);
System.out.println("Your previous session has been restored. Enjoy your chat.");
}
return tasks;

Expand Down Expand Up @@ -154,4 +150,4 @@ private static Task parseTaskFromSaveString(String saveString) throws GeneralExc
}
return task;
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/tsundere/task/Task.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package tsundere.task;

import tsundere.exception.GeneralException;
import java.util.ArrayList;

import tsundere.exception.GeneralException;

/**
* Encapsulates a Task object.
*/
Expand Down Expand Up @@ -123,4 +124,4 @@ public String toString() {
return "[" + this.getStatusIcon() + "] " + this.description + tags;
}

}
}
50 changes: 25 additions & 25 deletions src/main/java/tsundere/task/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package tsundere.task;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.LocalDate;

import java.util.ArrayList;

import tsundere.ui.Parser;
import tsundere.exception.GeneralException;
import tsundere.ui.Parser;

/**
* Encapsulates a TaskList object that contains all Task objects.
*/
public class TaskList {
public static ArrayList<Task> taskList = new ArrayList<>();
protected static ArrayList<Task> taskList = new ArrayList<>();
protected static String name = Parser.getName();

private static final String INVALID_TASK_NUMBER_INPUTTED_MSG = "Im pretty sure that's the wrong task number! " +
"Check again!";
private static final String INVALID_TASK_NUMBER_INPUTTED_MSG = "Im pretty sure that's the wrong task number! "
+ "Check again!";

/**
* Sets selected Task's status to undone.
Expand All @@ -30,17 +30,17 @@ public static String unmarkTask() throws GeneralException {
throw new GeneralException("What you tryna unmark huh?");
}
try {
Task t = TaskList.taskList.get(Integer.parseInt(Parser.name.substring(7, 8)) - 1);
Task t = TaskList.taskList.get(Integer.parseInt(TaskList.name.substring(7, 8)) - 1);
if (t.getStatusIcon().equals(" ")) {
return("You haven't even started this task dummy!");
return "You haven't even started this task dummy!";
} else {
t.unMarkTask();
return(t.toString());
return t.toString();
}
} catch (NumberFormatException e) {
throw new GeneralException("Can't you even remember the proper format for this?\n"
+ "unmark [task no.]");
} catch (IndexOutOfBoundsException e ) {
} catch (IndexOutOfBoundsException e) {
throw new GeneralException(INVALID_TASK_NUMBER_INPUTTED_MSG);
}

Expand All @@ -58,12 +58,12 @@ public static String markTask() throws GeneralException {
throw new GeneralException("What you tryna mark huh?");
}
try {
Task t = TaskList.taskList.get(Integer.parseInt(Parser.name.substring(5, 6)) - 1);
Task t = TaskList.taskList.get(Integer.parseInt(TaskList.name.substring(5, 6)) - 1);
if (t.isDone) {
return("You already finished this!");
return "You already finished this!";
} else {
t.markTaskAsDone();
return(t.toString());
return t.toString();
}
} catch (NumberFormatException e) {
throw new GeneralException("Can't you even remember the proper format for this?\n"
Expand All @@ -87,7 +87,7 @@ public static String deleteTask() throws GeneralException {
}

try {
int idx = Integer.parseInt(Parser.name.substring(7, 8)) - 1;
int idx = Integer.parseInt(TaskList.name.substring(7, 8)) - 1;
Task t = TaskList.taskList.get(idx);
TaskList.taskList.remove(idx);
return getListSize("deleted", t);
Expand Down Expand Up @@ -129,7 +129,7 @@ public static String listTasks() throws GeneralException {
public static String addToDoTask() throws GeneralException {

try {
String todo = Parser.name.split(" ", 2)[1];
String todo = TaskList.name.split(" ", 2)[1];

Task t = new ToDo(todo);
TaskList.taskList.add(t);
Expand All @@ -150,7 +150,7 @@ public static String addToDoTask() throws GeneralException {
public static String addEventTask() throws GeneralException {

try {
String event = Parser.name.split(" ", 2)[1];
String event = TaskList.name.split(" ", 2)[1];
String[] x = event.split(",");

Task t = new Event(x[0], x[1].trim().split(" ", 2)[1], x[2].trim().split(" ", 2)[1]);
Expand All @@ -172,7 +172,7 @@ public static String addEventTask() throws GeneralException {
public static String addDeadlineTask() throws GeneralException {

try {
String deadline = Parser.name.split(" ", 2)[1];
String deadline = TaskList.name.split(" ", 2)[1];
String[] x = deadline.split(",");
LocalDate d1 = LocalDate.parse(x[1].trim().split(" ", 2)[1]);
String date = d1.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
Expand Down Expand Up @@ -203,7 +203,7 @@ public static String findTasks() throws GeneralException {
StringBuilder response = new StringBuilder();
try {
int count = 0;
String keyword = Parser.name.split(" ", 2)[1];
String keyword = TaskList.name.split(" ", 2)[1];
for (int i = 0; i < size; i++) {
Task t = TaskList.taskList.get(i);
if (t.description.contains(keyword)) {
Expand All @@ -212,7 +212,7 @@ public static String findTasks() throws GeneralException {
}
}
if (count == 0) {
return("I couldn't find anything related to that!");
return "I couldn't find anything related to that!";
} else {
return response.toString();
}
Expand All @@ -233,7 +233,7 @@ public static String tagTask() throws GeneralException {
throw new GeneralException("Theres's nothing to find here!");
}
try {
String[] x = Parser.name.split(" ");
String[] x = TaskList.name.split(" ");
int idx = Integer.parseInt(x[1]) - 1;
String tag = x[2];
Task t = TaskList.taskList.get(idx);
Expand All @@ -258,7 +258,7 @@ public static String untagTask() throws GeneralException {
throw new GeneralException("Theres's nothing to find here!");
}
try {
String[] x = Parser.name.split(" ");
String[] x = TaskList.name.split(" ");
int idx = Integer.parseInt(x[1]) - 1;
String tag = x[2];
Task t = TaskList.taskList.get(idx);
Expand All @@ -280,13 +280,13 @@ public static String untagTask() throws GeneralException {
public static String getListSize(String str, Task t) {
String response = "";
int size = TaskList.taskList.size();
response += ("Noted...");
response += (" " + t.toString() + " has been " + str + "\n");
response += "Noted...";
response += " " + t.toString() + " has been " + str + "\n";

if (size > 0) {
response += ("Get to work! You still have " + size + " " + (size > 1 ? "tasks" : "task") + " left!");
response += "Get to work! You still have " + size + " " + (size > 1 ? "tasks" : "task") + " left!";
} else {
response += ("You finally have free time?");
response += "You finally have free time?";
}
return response;

Expand Down
Loading

0 comments on commit f9062b8

Please sign in to comment.