Skip to content

Commit 9f4af7e

Browse files
committed
Fix some coding standard and javadoc issues
1 parent 16b284f commit 9f4af7e

File tree

12 files changed

+98
-28
lines changed

12 files changed

+98
-28
lines changed

src/main/java/spike/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* A GUI for Duke using FXML.
1414
*/
1515
public class Main extends Application {
16-
16+
// Initializing the Spike instance
1717
private Spike spike = new Spike("/data", "/data/Spike.txt");
1818

1919
@Override

src/main/java/spike/Spike.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Spike(String directory, String filePath) {
3131

3232
/**
3333
* Gets number of tasks.
34-
* @return
34+
* @return number of tasks
3535
*/
3636
public int getNumOfTasks() {
3737
return tasks.getListSize();

src/main/java/spike/command/AddCommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public AddCommand(Task task) {
1919
this.task = task;
2020
}
2121

22+
/**
23+
* Executes the command.
24+
*
25+
* @param tasks current task list
26+
* @return execution result string
27+
*/
2228
@Override
2329
public String execute(TaskList tasks) {
2430
tasks.addTask(task);

src/main/java/spike/command/DeleteCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public DeleteCommand(Task task) {
2020
}
2121

2222
/**
23-
* Removes and printed the deleted task.
23+
* Removes and prints the deleted task.
2424
*
2525
* @param tasks current task list
2626
* @return deletion response string
@@ -33,6 +33,8 @@ public String execute(TaskList tasks) {
3333

3434
/**
3535
* Returns the message needed for printing when deleting task.
36+
*
37+
* @return response after deleting task
3638
*/
3739
private String getDeletedTaskText(Task task, TaskList tasks) {
3840
String result = " Noted. I've removed this task: \n"

src/main/java/spike/command/FindCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* Finds task based on keyword given.
88
*/
99
public class FindCommand extends Command {
10-
private String keyWord;
10+
private String keyword;
1111

1212
/**
1313
* Constructor using keyword string.
1414
*
15-
* @param keyWord the word used to find tasks
15+
* @param keyword the word used to find tasks
1616
*/
17-
public FindCommand(String keyWord) {
18-
this.keyWord = keyWord;
17+
public FindCommand(String keyword) {
18+
this.keyword = keyword;
1919
}
2020

2121
/**
@@ -29,7 +29,7 @@ public String execute(TaskList tasks) {
2929
int i = 1;
3030
String result = "Here are the matching tasks in your list:\n";
3131
for (Task task : tasks.getTasks()) {
32-
if (task.toString().contains(keyWord)) {
32+
if (task.toString().contains(keyword)) {
3333
result = result + i + "." + task + "\n";
3434
}
3535
i++;

src/main/java/spike/command/ListCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String execute(TaskList tasks) {
5050
* Lists all tasks.
5151
*
5252
* @param tasks
53-
* @return
53+
* @return all tasks
5454
*/
5555
private String getTaskListText(TaskList tasks) {
5656
int i = 1;
@@ -62,6 +62,12 @@ private String getTaskListText(TaskList tasks) {
6262
return result.trim();
6363
}
6464

65+
/**
66+
* Lists all tasks by date.
67+
*
68+
* @param tasks
69+
* @return all task filtered by date
70+
*/
6571
private String getTaskListTextByDate(TaskList tasks) {
6672
int i = 1;
6773
String result = "Here are the task(s) in your list filtered by date:\n";

src/main/java/spike/parser/Parser.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package spike.parser;
2+
23
import java.time.LocalDateTime;
34
import java.time.format.DateTimeFormatter;
45
import java.time.format.DateTimeParseException;
@@ -52,11 +53,14 @@ public String getCommand() {
5253
* @return a proper command to be executed
5354
*/
5455
public Command parseCommand(String inputLine, TaskList tasks) {
56+
// Extract the words
5557
String[] commandWords = inputLine.split(" ");
58+
// Get the command name and check validity
5659
CommandName type = validateCommand(commandWords[0]);
5760
if (type == null) {
5861
return new IncorrectCommand("Sorry, I am not programmed to do this yet :(");
5962
}
63+
// Start to generate command
6064
switch (type) {
6165
case LIST:
6266
try {
@@ -100,14 +104,27 @@ public Command parseCommand(String inputLine, TaskList tasks) {
100104
}
101105
}
102106

107+
/**
108+
* Parses the find command.
109+
*
110+
* @param inputLine user raw input
111+
* @return a command object ready to be executed
112+
* @throws SpikeException if the keyword for find is missing
113+
*/
103114
private Command parseFind(String inputLine) throws SpikeException {
104115
if (inputLine.length() <= 5) {
105116
throw new SpikeException("Kindly enter the keyword for finding task");
106117
}
107118
return new FindCommand(inputLine.substring(5));
108119
}
109120

110-
121+
/**
122+
* Parses the list command.
123+
*
124+
* @param inputLine user raw input
125+
* @return a command object ready to be executed
126+
* @throws SpikeException if the keyword for list by date is missing
127+
*/
111128
private Command parseList(String inputLine) throws SpikeException {
112129
if (inputLine.length() >= 5) {
113130
// User tries to list task by date
@@ -122,6 +139,15 @@ private Command parseList(String inputLine) throws SpikeException {
122139
}
123140
}
124141

142+
/**
143+
* Parses the add command
144+
*
145+
* @param c command name
146+
* @param command whole command in string
147+
* @param commandWords command broken down into words
148+
* @return a command object ready to be executed
149+
* @throws SpikeException if any parameter is missing
150+
*/
125151
private Command parseAdd(CommandName c, String command, String[] commandWords) throws SpikeException {
126152
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
127153
switch (c) {
@@ -163,6 +189,14 @@ private Command parseAdd(CommandName c, String command, String[] commandWords) t
163189
}
164190
}
165191

192+
/**
193+
* Parses delete command.
194+
*
195+
* @param commandWords command broken down into words
196+
* @param tasks current task list
197+
* @return a command object ready to be executed
198+
* @throws SpikeException if any parameter is missing
199+
*/
166200
private Command parseDelete(String[] commandWords, TaskList tasks) throws SpikeException {
167201
if (commandWords.length != 2 || isInt(commandWords[1]) == -1
168202
|| isInt(commandWords[1]) > tasks.getListSize()) {
@@ -172,6 +206,15 @@ private Command parseDelete(String[] commandWords, TaskList tasks) throws SpikeE
172206
return new DeleteCommand(toDelete);
173207
}
174208

209+
/**
210+
* Parses mark or unmark command
211+
*
212+
* @param c command name
213+
* @param commandWords command broken down into words
214+
* @param tasks current task list
215+
* @return a command object ready to be executed
216+
* @throws SpikeException if any parameter is missing
217+
*/
175218
private Command parseToggleMark(CommandName c, String[] commandWords, TaskList tasks) throws SpikeException {
176219
if (c.getCommand().equals("mark")) {
177220
if (commandWords.length != 2 || isInt(commandWords[1]) == -1
@@ -190,13 +233,20 @@ private Command parseToggleMark(CommandName c, String[] commandWords, TaskList t
190233
}
191234
}
192235

236+
/**
237+
* Parses exit command
238+
*
239+
* @return a command ready to be executed
240+
*/
193241
private Command parseExit() {
194242
return new ExitCommand();
195243
}
196244

197245

198246
/**
199247
* Parses date and time input by user and returns valid LocalDateTime object
248+
*
249+
* @return object containing date and time information
200250
*/
201251
private static LocalDateTime parseDateTime(String s, DateTimeFormatter dtf) {
202252
try {
@@ -210,6 +260,8 @@ private static LocalDateTime parseDateTime(String s, DateTimeFormatter dtf) {
210260
/**
211261
* Checks whether the input string is integer.
212262
* If yes, return it, else return -1.
263+
*
264+
* @return indicator of whether the input is an integer
213265
*/
214266
private static int isInt(String str) {
215267
try {
@@ -224,6 +276,8 @@ private static int isInt(String str) {
224276
/**
225277
* Checks whether it is a valid command.
226278
* If valid, return that command enum number, else return null.
279+
*
280+
* @return command name if the input is valid
227281
*/
228282
private CommandName validateCommand(String input) {
229283
for (CommandName c : CommandName.values()) {

src/main/java/spike/task/Task.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public Task(String description, LocalDateTime dateTime) {
3333

3434
/**
3535
* Retrieve the task status icon.
36+
*
37+
* @return status icon
3638
*/
3739
private String getStatusIcon() {
3840
return (isDone ? "X" : " "); // mark done task with X
@@ -54,21 +56,26 @@ public void markAsNotDone() {
5456

5557
/**
5658
* Returns the representative string for saving in data file.
59+
*
60+
* @return string format for saving
5761
*/
5862
public String toFileFormat() {
5963
return "";
6064
}
6165

6266
/**
63-
* Format the string representation of spike.task.Task objects.
6467
* Gets the date and time for tasks with such information.
68+
*
69+
* @return object containing the date and time information
6570
*/
6671
public LocalDateTime getDateTime() {
6772
return this.dateTime;
6873
}
6974

7075
/**
71-
* Formats the string representation of spike.task.Task objects.
76+
* Formats the string representation of Task objects.
77+
*
78+
* @return string representation of a task
7279
*/
7380
@Override
7481
public String toString() {

src/main/java/spike/ui/DialogBox.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ private void flip() {
5050
}
5151

5252
public static DialogBox getUserDialog(String text, Image img) {
53-
return new DialogBox(text, img);
53+
DialogBox dialogBox = new DialogBox(text, img);
54+
dialogBox.getChildren().get(0).setStyle("-fx-background-color: #a9a9a9; -fx-background-radius: 10;");
55+
return dialogBox;
5456
}
5557

5658
public static DialogBox getSpikeDialog(String text, Image img) {
5759
var db = new DialogBox(text, img);
60+
db.getChildren().get(0).setStyle("-fx-background-color: #3cb371; -fx-background-radius: 10;");
5861
db.flip();
5962
return db;
6063
}

src/main/java/spike/ui/MainWindow.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javafx.scene.layout.AnchorPane;
99
import javafx.scene.layout.VBox;
1010
import spike.Spike;
11-
import spike.command.ExitCommand;
1211

1312
/**
1413
* Controller for MainWindow. Provides the layout for the other controls.
@@ -67,16 +66,10 @@ public void setSpike(Spike s) {
6766
private void handleUserInput() {
6867
String input = userInput.getText();
6968
String response = spike.getResponseCommand(input);
70-
if (response.equals(ExitCommand.EXIT_MESSAGE)) {
71-
dialogContainer.getChildren().addAll(
72-
DialogBox.getSpikeDialog(response, spikeImage)
73-
);
74-
} else {
75-
dialogContainer.getChildren().addAll(
76-
DialogBox.getUserDialog(input, userImage),
77-
DialogBox.getSpikeDialog(response, spikeImage)
78-
);
79-
}
69+
dialogContainer.getChildren().addAll(
70+
DialogBox.getUserDialog(input, userImage),
71+
DialogBox.getSpikeDialog(response, spikeImage)
72+
);
8073
userInput.clear();
8174
}
8275
}

0 commit comments

Comments
 (0)