Skip to content

Commit

Permalink
update files to comply with checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
lawruixi committed Sep 24, 2023
1 parent 5731f0e commit 2533920
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 140 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ plugins {
id 'checkstyle'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11);
}
}

repositories {
mavenCentral()
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/duchess/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duchess;

import java.time.LocalDate;

import java.util.ArrayList;

/**
Expand Down Expand Up @@ -56,7 +55,7 @@ public String mainString() {
@Override
public String toSaveString() {
String saveString = String.format("D|%s|by:%s|", super.toSaveString(), this.deadline);

for (String tag : this.tags) {
saveString += String.format("#%s|", tag);
}
Expand Down Expand Up @@ -91,15 +90,15 @@ public static Deadline fromSaveString(String s) {

for (int i = 4; i < splitString.length; i++) {
String dataString = splitString[i];

if (dataString.startsWith("#")) {
tags.add(dataString.substring(1));
}
}

try {
Deadline deadline = new Deadline(name, deadlineString, taskStatus);

for (String tag : tags) {
deadline.addTag(tag);
}
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/duchess/Duchess.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package duchess;

import duchess.command.Command;
import duchess.command.CommandType;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.function.Consumer;

import duchess.command.Command;

/**
* The main class used to execute Duchess actions.
*/
public class Duchess {
/**
* Name for the Duchess AI.
*/
public final String NAME = "Duchess";
public static final String NAME = "Duchess";

/**
* An ArrayList to store text in.
Expand Down Expand Up @@ -44,6 +42,7 @@ private void executeCallbackHandler(String s) {

/**
* Attempts to parse and execute the user input as a Duchess command.
* Afterwards, executes Duchess' set callback handler.
*
* @param userInput - the user's input.
*/
Expand All @@ -53,6 +52,10 @@ public void parseUserInput(String userInput) {
this.executeCallbackHandler(output);
}

/**
* Runs the CLI Duchess' main logic loop of receiving user input, and giving the appropriate
* response.
*/
public void run() {
this.executeCallbackHandler(Ui.printGreeting());

Expand Down Expand Up @@ -83,10 +86,16 @@ public void run() {
this.executeCallbackHandler(Ui.printFarewell());
}

/**
* Saves Tasks from this Duchess instance into a save file.
*/
public void saveTasks() {
Storage.saveTasksToFile(this.storedTasks);
}

/**
* Loads Tasks from a specific save file into this Duchess instance.
*/
public void loadTasks() {
// Create the save file, if it does not exist.
Storage.createSaveFile();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duchess/DuchessException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package duchess;

/**
* A general-purpose Exception to be thrown by Duchess when an error is encountered,
* with a customized message.
*/
public class DuchessException extends Throwable {
private String message;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package duchess;

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

/**
* The main class used to execute Duchess actions.
*/
public class DuchessGUI {
public class DuchessGui {

private Duchess duchess;
private String responseString = "";

public DuchessGUI() {
/**
* Returns a new DuchessGUI instance.
*/
public DuchessGui() {
this.duchess = new Duchess();
this.duchess.setCallbackHandler((s) -> {
this.responseString = s;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/duchess/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.ArrayList;

/**
* Represents an Event Task, which is a Task with a name, start time and end time.
*/
public class Event extends Task {
private String startTime;
private String endTime;
Expand Down Expand Up @@ -94,14 +97,14 @@ public static Event fromSaveString(String s) {

for (int i = 5; i < splitString.length; i++) {
String dataString = splitString[i];

if (dataString.startsWith("#")) {
tags.add(dataString.substring(1));
}
}

Event event = new Event(name, startTime, endTime, taskStatus);

for (String tag : tags) {
event.addTag(tag);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/duchess/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
* A GUI for Duke using FXML.
*/
public class Main extends Application {
private DuchessGUI duchessGUI = new DuchessGUI();
private FXMLLoader duchessGUILoader;
private DuchessGui duchessGui = new DuchessGui();
private FXMLLoader duchessGuiLoader;

@Override
public void start(Stage stage) {
try {
duchessGUILoader = new FXMLLoader(Main.class.getResource("/view/Duchess.fxml"));
VBox vb = duchessGUILoader.load();
duchessGuiLoader = new FXMLLoader(Main.class.getResource("/view/Duchess.fxml"));
VBox vb = duchessGuiLoader.load();

Scene scene = new Scene(vb);
stage.setScene(scene);

duchessGUILoader.<MainWindowController>getController().setDuchessGUI(duchessGUI);
duchessGUILoader.<MainWindowController>getController().loadTasksFromFile();
duchessGuiLoader.<MainWindowController>getController().setDuchessGui(duchessGui);
duchessGuiLoader.<MainWindowController>getController().loadTasksFromFile();

stage.show();
} catch (IOException e) {
Expand All @@ -35,7 +35,7 @@ public void start(Stage stage) {

@Override
public void stop() {
duchessGUILoader.<MainWindowController>getController().saveTasksToFile();
duchessGuiLoader.<MainWindowController>getController().saveTasksToFile();
}
}

Expand Down
46 changes: 23 additions & 23 deletions src/main/java/duchess/MainWindowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,69 @@

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;

/**
* Controller for MainWindow. Provides the layout for the other controls.
*/
public class MainWindowController extends VBox {
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png"));
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png"));
private Image duchessImage = new Image(this.getClass().getResourceAsStream("/images/duchess.png"));

@FXML
ScrollPane scrollPane;
private ScrollPane scrollPane;

@FXML
VBox chat_vbox;
private VBox chatVbox;

@FXML
TextField userinput_textfield;
private TextField userinputTextfield;

private DuchessGUI duchessGUI;
private DuchessGui duchessGui;

public void setDuchessGUI(DuchessGUI dGUI) {
this.duchessGUI = dGUI;
public void setDuchessGui(DuchessGui dGui) {
this.duchessGui = dGui;
}

public void loadTasksFromFile() {
this.duchessGUI.loadTasks();
this.duchessGui.loadTasks();
}

@FXML
private void initialize() {
chat_vbox.heightProperty().addListener(observable -> scrollPane.setVvalue(1D));
chatVbox.heightProperty().addListener(observable -> scrollPane.setVvalue(1D));

chat_vbox.getChildren().addAll(
chatVbox.getChildren().addAll(
DialogBox.getDuchessDialog(Ui.printGreeting(), duchessImage)
);
);

userinput_textfield.clear();
userinputTextfield.clear();
}

@FXML
private void handleUserInput() {
String input = userinput_textfield.getText();
String response = duchessGUI.getResponse(input);
String input = userinputTextfield.getText();
String response = duchessGui.getResponse(input);

if (Parser.isExitCommand(input)) {
chat_vbox.getChildren().addAll(
chatVbox.getChildren().addAll(
DialogBox.getDuchessDialog(Ui.printFarewell(), duchessImage)
);
userinput_textfield.clear();
);
userinputTextfield.clear();
Platform.exit();
}

chat_vbox.getChildren().addAll(
chatVbox.getChildren().addAll(
DialogBox.getUserDialog(input, userImage),
DialogBox.getDuchessDialog(response, duchessImage)
);
userinput_textfield.clear();
);
userinputTextfield.clear();
}

public void saveTasksToFile() {
this.duchessGUI.saveTasks();
this.duchessGui.saveTasks();
}
}
22 changes: 11 additions & 11 deletions src/main/java/duchess/Parser.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package duchess;

import java.util.regex.Matcher;

import duchess.command.Command;
import duchess.command.CommandType;

import java.util.regex.Matcher;

/**
* A class used to parse user input from the command line.
*/
Expand Down Expand Up @@ -219,7 +219,7 @@ public static boolean isEventCommand(String s) {
public static Event parseEventCommand(String s) throws DuchessException {
Matcher m = Utility.parseRegex(
s, "^event( [A-Za-z0-9_ ]+)?( /from( [A-Za-z0-9_ ]+)?)?( /to( [A-Za-z0-9_ ]+)?)?$"
);
);

if (m.group(1) == null) {
throw new DuchessException("(´;ω;`) Sorry, event names cannot be empty... ;-;");
Expand Down Expand Up @@ -252,12 +252,12 @@ public static boolean isAddTagCommand(String s) {
* @throws DuchessException if any essential arguments to this command are missing.
*/
public static int parseAddTagCommandIndex(String s) throws DuchessException {
// Matches a tag, followed by either "a" or "add", then an index
// (any number of digits) and then any number of (hashtags (optional)
// and then letters without spaces.) Each tag hence needs to have no spaces inside.
// Matches a tag, followed by either "a" or "add", then an index
// (any number of digits) and then any number of (hashtags (optional)
// and then letters without spaces.) Each tag hence needs to have no spaces inside.
Matcher m = Utility.parseRegex(
s, "^tag a(?:dd)? ([0-9]+)?((?: (?:#)?(?:[A-Za-z0-9_\\-]+))*)?"
);
);

if (m.group(1) == null) {
throw new DuchessException("(´;ω;`) Sorry, I don't know which task to tag... ;-;");
Expand All @@ -277,7 +277,7 @@ public static String[] parseAddTagCommandTags(String s) throws DuchessException
// See parseAddTagCommandIndex.
Matcher m = Utility.parseRegex(
s, "^tag a(?:dd)? ([0-9]+)?((?: (?:#)?(?:[A-Za-z0-9_\\-]+))*)?"
);
);

if (m.group(1) == null || m.group(2) == null || m.group(2).length() == 0) {
throw new DuchessException("(´;ω;`) Sorry, tags cannot be empty... ;-;");
Expand Down Expand Up @@ -307,11 +307,11 @@ public static boolean isRemoveTagCommand(String s) {
*/
public static int parseRemoveTagCommandIndex(String s) throws DuchessException {
// Matches a tag, followed by some variant of "rm" or "del", then
// (any number of digits) and then any number of (hashtags (optional)
// (any number of digits) and then any number of (hashtags (optional)
// and then letters without spaces.)
Matcher m = Utility.parseRegex(
s, "^tag (?:rm|remove|del|delete) ([0-9]+)?((?: (?:#)?(?:[A-Za-z0-9_\\-]+))*)?"
);
);

if (m.group(1) == null) {
throw new DuchessException("(´;ω;`) Sorry, I don't know which task to remove the tag from... ;-;");
Expand All @@ -331,7 +331,7 @@ public static String[] parseRemoveTagCommandTags(String s) throws DuchessExcepti
// See parseRemoveTagCommandIndex.
Matcher m = Utility.parseRegex(
s, "^tag (?:rm|remove|del|delete) ([0-9]+)?((?: (?:#)?(?:[A-Za-z0-9_\\-]+))*)?"
);
);

if (m.group(1) == null || m.group(2) == null || m.group(2).length() == 0) {
throw new DuchessException("(´;ω;`) Sorry, tags cannot be empty... ;-;");
Expand Down
Loading

0 comments on commit 2533920

Please sign in to comment.