Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete A-CodeQuality #3

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/java/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ public AddCommand(String description, LocalDateTime startDate, LocalDateTime end
*
* @param tasks The task list where the task will be added.
* @param storageManager The storage manager to save the changes.
* @return The added task.
* @return String print output.
*/
public String execute(TaskList tasks, StorageManager storageManager) {
task.setStatus(status);
tasks.add(task);
storageManager.save(tasks);

StringBuilder output = new StringBuilder();
output.append("Got it. I've added this task:\n");
output.append(task).append("\n");
output.append(String.format("Now you have %d tasks in the list.\n", tasks.getSize()));

return output.toString();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/commands/ByeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ByeCommand extends Command {
*
* @param tasks The task list (not used in this command).
* @param storageManager The storage manager (not used in this command).
* @return Null, as there is no task to return.
* @return String print output.
*/
public String execute(TaskList tasks, StorageManager storageManager) {
return ("Bye. Hope to see you again soon!");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class Command {
*
* @param tasks the taskList
* @param storageManager to load and save tasks
* @return Task handled by the command
* @return String print output.
* @throws CalException if there was an error when executing the command.
*/
public abstract String execute(TaskList tasks, StorageManager storageManager) throws CalException;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ public DeleteCommand(int taskNum) {
*
* @param tasks The task list where the task will be deleted.
* @param storageManager The storage manager to save the changes.
* @return The deleted task.
* @return String print output.
*/
public String execute(TaskList tasks, StorageManager storageManager) {
Task t = tasks.delete(taskNum);
storageManager.save(tasks);

StringBuilder output = new StringBuilder();
output.append("Noted. I've removed this task\n");
output.append(t).append("\n");
output.append(String.format("Now you have %d tasks in the list.\n", tasks.getSize()));

return output.toString();
}


/**
* Indicates whether the DeleteCommand is an exit command.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public FindCommand(String keyword) {
*
* @param tasks The task list to search through
* @param storageManager The storage manager (not used in this command).
* @return Null, as there is no task to return.
* @return String print output.
*/
public String execute(TaskList tasks, StorageManager storageManager) {
StringBuilder output = new StringBuilder();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ListCommand extends Command {
*
* @param tasks The task list to be displayed.
* @param storageManager The storage manager (not used in this command).
* @return Null, as there is no task to return.
* @return String print output.
*/
public String execute(TaskList tasks, StorageManager storageManager) {
StringBuilder output = new StringBuilder();
Expand All @@ -28,7 +28,6 @@ public String execute(TaskList tasks, StorageManager storageManager) {
}
return output.toString();
}


/**
* Indicates whether the ListCommand is an exit command.
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/commands/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ public MarkCommand(int taskNum) {
*
* @param tasks The task list containing the task.
* @param storageManager The storage manager to save the changes.
* @return The task that has been marked as done.
* @return String print output.
* @throws CalException if the task number is invalid or if an error occurs.
*/
public String execute(TaskList tasks, StorageManager storageManager) throws CalException {
Task t = tasks.mark(taskNum);
storageManager.save(tasks);

StringBuilder output = new StringBuilder();
output.append("Nice! I've marked this task as done:\n");
output.append(t).append("\n");

return output.toString();
}


/**
* Indicates whether the MarkCommand is an exit command.
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/commands/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ public UnmarkCommand(int taskNum) {
*
* @param tasks The task list containing the task.
* @param storageManager The storage manager to save the changes.
* @return The task that has been unmarked.
* @return String print output.
* @throws CalException if the task number is invalid or if an error occurs.
*/
public String execute(TaskList tasks, StorageManager storageManager) throws CalException {
Task t = tasks.unmark(taskNum);
storageManager.save(tasks);

StringBuilder output = new StringBuilder();
output.append("OK, I've marked this task as not done yet:\n");
output.append(t).append("\n");

return output.toString();
}


/**
* Indicates whether the UnmarkCommand is an exit command.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/controller/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

/**
* An example of a custom control using FXML.
* This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label
* containing text from the speaker.
* represents a dialog box consisting of an ImageView to represent user profile picture and a label
* containing dialog text.
*/
public class DialogBox extends HBox {
@FXML
Expand All @@ -36,8 +36,8 @@ private DialogBox(String text, Image img, String backgroundColor) {
}
dialog.setText(text);
displayPicture.setImage(img);
dialog.setStyle("-fx-background-color: " + backgroundColor
+ "; -fx-background-radius: 10; " + "-fx-label-padding: 10;");
dialog.setStyle("-fx-background-color: " + backgroundColor
+ "; -fx-background-radius: 10; " + "-fx-label-padding: 10;");
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import javafx.scene.layout.VBox;

/**
* The main view for the application.
* represents the main view for the application consisting of chat window,
* text field and send button.
*/
public class MainWindow {
@FXML
Expand Down
59 changes: 22 additions & 37 deletions src/main/java/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
* contains a static method 'parseCommand' which takes a user input string and returns the appropriate Command object.
*/
public class Parser {
public static void checkNullTaskNum(int inputLen) throws CalException {
if (inputLen < 2) {
throw new CalException("Task number not provided!");
}
}

public static void checkBlankField(String field, String fieldName) throws CalException {
if (field.isBlank()) {
throw new CalException("Oops! You are missing" + fieldName + ".");
}
}

/**
* Parses the user input string and returns the corresponding Command object.
*
Expand All @@ -40,38 +52,24 @@ public static Command parseCommand(String line) throws CalException {
case "list":
return new ListCommand();
case "mark":
if (tokens.length < 2) {
throw new CalException("Task number not provided!");
}

checkNullTaskNum(tokens.length);
return new MarkCommand(Integer.parseInt(tokens[1]));
case "unmark":
if (tokens.length < 2) {
throw new CalException("Task number not provided!");
}

checkNullTaskNum(tokens.length);
return new UnmarkCommand(Integer.parseInt(tokens[1]));
case "todo":
description = line.substring(4).strip();
if (description.isBlank()) {
throw new CalException("Task description not provided");
}

checkBlankField(description, "description");
return new AddCommand(description);
case "deadline":
int byIndex = line.indexOf("/by");
LocalDateTime dueDate;

try {
description = line.substring(8, byIndex).strip();
if (description.isBlank()) {
throw new CalException("Task description not provided");
}

checkBlankField(description, "description");
String by = line.substring(byIndex + 4).strip();
if (by.isBlank()) {
throw new CalException("Task due date not provided");
}
checkBlankField(by, "due date");
dueDate = LocalDateTime.parse(by, Task.INPUT_DATE_FORMAT);
} catch (StringIndexOutOfBoundsException e) {
throw new CalException("Deadline Task is not in the format: "
Expand All @@ -89,20 +87,12 @@ public static Command parseCommand(String line) throws CalException {

try {
description = line.substring(5, fromIndex).strip();
if (description.isBlank()) {
throw new CalException("Event description not provided");
}

checkBlankField(description, "description");
String startDateStr = line.substring(fromIndex + 5, toIndex).strip();
if (startDateStr.isBlank()) {
throw new CalException("Event start date not provided");
}
checkBlankField(startDateStr, "start date");
startDate = LocalDateTime.parse(startDateStr, Task.INPUT_DATE_FORMAT);

String endDateStr = line.substring(toIndex + 3).strip();
if (endDateStr.isBlank()) {
throw new CalException("Event end date not provided");
}
checkBlankField(endDateStr, "end date");
endDate = LocalDateTime.parse(endDateStr, Task.INPUT_DATE_FORMAT);
} catch (StringIndexOutOfBoundsException e) {
throw new CalException("Event Task is not in the format: "
Expand All @@ -113,16 +103,11 @@ public static Command parseCommand(String line) throws CalException {

return new AddCommand(description, startDate, endDate);
case "delete":
if (tokens.length < 2) {
throw new CalException("Task number not provided!");
}

checkNullTaskNum(tokens.length);
return new DeleteCommand(Integer.parseInt(tokens[1]));
case "find":
String keyword = line.substring(4).strip();
if (keyword.isBlank()) {
throw new CalException("Missing search keyword.");
}
checkBlankField(keyword, "search keyword");
return new FindCommand(keyword);
default:
throw new CalException("Command not recognized.");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/storage/TaskSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class TaskSerializer {
*/
public static String serialize(Task t) {
assert t != null : "Task should not be null";

String[] taskFields = {"", "", "", "", ""};
taskFields[1] = t.getStatus() ? "1" : "0";
taskFields[2] = t.getDescription();
Expand Down