Skip to content

Commit d297447

Browse files
committed
Refactor to match coding standard
There are minor coding standard violations This makes it hard to standardise it to make it seem like it is written by only one person Lets - Make extra javadocs - Ensure code follows the java coding standards
1 parent 7415aa2 commit d297447

31 files changed

Lines changed: 347 additions & 161 deletions

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727

2828
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0'
2929
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'
30+
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.7.0'
3031

3132
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
3233
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'

data/duke.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
D | 1 | apply financial assistance | 2021-03-01
2+
D | 0 | CS3230 homework | 2021-03-02
23
E | 0 | CS3230 midterm | 2021-03-06
34
E | 1 | graduation | I think is somewhere around 2022-05-03...
4-
T | 0 | CS3230 homwork
5-
T | 0 | NOBODY MOVE

src/main/java/duke/Duke.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,40 @@
33
import java.io.File;
44
import java.io.IOException;
55

6+
import duke.command.Command;
7+
import duke.command.CommandResult;
8+
import duke.exceptions.DukeCommandParseException;
69
import duke.exceptions.DukeDateParseException;
710
import duke.exceptions.DukeOutOfBoundsException;
8-
import duke.exceptions.DukeCommandParseException;
911
import duke.exceptions.DukeStorageException;
1012
import duke.model.TaskList;
1113
import duke.parser.CommandParser;
1214
import duke.storage.Storage;
1315
import duke.ui.MessageGenerator;
14-
import duke.command.Command;
15-
import duke.command.CommandResult;
16+
1617

1718
/**
1819
* main class containing the Duke Chatbot main logic.
1920
*/
2021

2122
public class Duke {
2223

23-
private final static String STORAGE_DIRECTORY_PATH = "data";
24-
private final static String STORAGE_FILE_PATH = "data/duke.txt";
25-
private final static String STORAGE_INITIALIZATION_ERROR_MESSAGE = "Cannot Crete file duke.txt";
24+
private static final String STORAGE_DIRECTORY_PATH = "data";
25+
private static final String STORAGE_FILE_PATH = "data/duke.txt";
26+
private static final String STORAGE_INITIALIZATION_ERROR_MESSAGE = "Cannot Crete file duke.txt";
2627

2728
private static Storage storage;
2829
private MessageGenerator messageGenerator;
2930
private TaskList tasks;
3031
private boolean isExit = false;
3132

3233

34+
/**
35+
* Initializes and loads all the data from storage, as well as create the nexessary classes.
36+
*
37+
* @throws IOException when the file does not exist and Duke cannot create the file in the necessary path
38+
*/
39+
3340
public Duke() throws IOException {
3441
this.messageGenerator = new MessageGenerator();
3542
Duke.storage = initializeStorage();
@@ -62,12 +69,22 @@ private Storage initializeStorage() throws IOException {
6269
return new Storage("data/duke.txt");
6370
}
6471

72+
/**
73+
* Returns the message to display at the start of the program.
74+
*
75+
* @return the message to display at the when Duke is started.
76+
*/
6577

66-
67-
public String startMessage(){
78+
public String startMessage() {
6879
return messageGenerator.getWelcomeMessage();
6980
}
7081

82+
/**
83+
* Runs the Duke logic given the input string and gets Duke's response to the input.
84+
*
85+
* @param input the string to be passed to Dyke
86+
* @return the response after Duke analyses the string
87+
*/
7188

7289
public String getResponse(String input) {
7390
try {
@@ -85,6 +102,13 @@ public String getResponse(String input) {
85102
}
86103
}
87104

105+
/**
106+
* Gets the exit flag for Duke Chatbot
107+
* @return the flag isExit. It is true if the exit Command has been executed.
108+
* Else it will be false to show Duke is still running
109+
*
110+
*/
111+
88112
public boolean getIsExit() {
89113
return isExit;
90114
}

src/main/java/duke/Launcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package duke;
22

3-
import duke.Main;
43
import javafx.application.Application;
54

65
/**
@@ -10,4 +9,4 @@ public class Launcher {
109
public static void main(String[] args) {
1110
Application.launch(Main.class, args);
1211
}
13-
}
12+
}

src/main/java/duke/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Main extends Application {
1616

1717

1818

19+
1920
@Override
2021
public void start(Stage stage) {
2122
try {

src/main/java/duke/command/Command.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@
66
import duke.storage.Storage;
77
import duke.ui.MessageGenerator;
88

9+
/**
10+
* The Command class provides the contract by which all commands must abide by.
11+
* All commands should be able to be executed and return
12+
* a command result. They must have access to the model and the storage,
13+
* as well as a class for generating the messages to put in the
14+
* CommandResult class ( if need be).
15+
*/
916
public abstract class Command {
10-
protected boolean isExitAfterExecution = false;
1117

18+
/**
19+
* Executes a sequence of high - level instructions and returns a CommandResult data structure
20+
* containing the data obtained after
21+
* running the execute method.
22+
*
23+
* @param messageGenerator The class to handle formatting and generating UI display messages
24+
* @param tasks The model of the data
25+
* @param storage The class responsible to save data onto the hard disk
26+
* @return CommandResult, a resulting data obtained after executing the command.
27+
* @throws DukeStorageException
28+
* @throws DukeOutOfBoundsException
29+
*/
1230
public abstract CommandResult execute(MessageGenerator messageGenerator, TaskList tasks, Storage storage)
1331
throws DukeStorageException, DukeOutOfBoundsException;
14-
15-
1632
}

src/main/java/duke/command/CommandResult.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package duke.command;
22

3+
/**
4+
* A class containing the information to pass to Duke from Command class after that Command is executed.
5+
*
6+
*/
37
public class CommandResult {
48
private String messageToDisplay;
59
private boolean isExit;
610

11+
/**
12+
* Constructor that stores the necessary information
13+
* @param messageToDisplay the message for the GUI to display.
14+
* @param isExit the flag indicating if the program should stop after the command is run.
15+
*/
716
CommandResult(String messageToDisplay, boolean isExit) {
817
this.messageToDisplay = messageToDisplay;
918
this.isExit = isExit;

src/main/java/duke/command/DeleteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public CommandResult execute(MessageGenerator messageGenerator, TaskList tasks,
2020
throws DukeStorageException, DukeOutOfBoundsException {
2121
Task taskToDelete = tasks.pop(indexToDelete);
2222
storage.saveTasks(tasks);
23-
String deleteMessage = messageGenerator.generateDeleteMessage(taskToDelete,tasks);
23+
String deleteMessage = messageGenerator.generateDeleteMessage(taskToDelete, tasks);
2424
return new CommandResult(deleteMessage, false);
2525
}
2626
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package duke.command;
22

3-
import duke.storage.Storage;
43
import duke.model.TaskList;
4+
import duke.storage.Storage;
55
import duke.ui.MessageGenerator;
66

77
public class ExitCommand extends Command {
88

99
@Override
1010
public CommandResult execute(MessageGenerator messageGenerator, TaskList tasks, Storage storage) {
1111
String exitMessage = messageGenerator.generateExitMessage();
12-
return new CommandResult( exitMessage, true);
12+
return new CommandResult(exitMessage, true);
1313
}
1414
}

src/main/java/duke/command/FindTaskCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package duke.command;
22

3-
import duke.storage.Storage;
43
import duke.model.TaskList;
4+
import duke.storage.Storage;
55
import duke.ui.MessageGenerator;
66

77
public class FindTaskCommand extends Command {
@@ -17,6 +17,6 @@ public FindTaskCommand(String keyword) {
1717
public CommandResult execute(MessageGenerator messageGenerator, TaskList tasks, Storage storage) {
1818
TaskList filteredTaskList = tasks.filterByWord(keyword);
1919
String findTaskMessage = messageGenerator.generateFindTaskMessage(filteredTaskList);
20-
return new CommandResult(findTaskMessage,false);
20+
return new CommandResult(findTaskMessage, false);
2121
}
2222
}

0 commit comments

Comments
 (0)