From 70b79f301b28ac6e90acda87ccfc4ceecb1d4472 Mon Sep 17 00:00:00 2001 From: Nereus Ng Wei Bin Date: Tue, 19 Sep 2023 02:24:51 +0800 Subject: [PATCH 1/2] Edit naming of boolean type variable --- src/main/java/corgi/commands/MarkTaskCommand.java | 14 +++++++------- src/main/java/corgi/parsers/CommandParser.java | 2 +- src/main/java/corgi/parsers/TaskParser.java | 12 ++++++------ src/main/java/corgi/tasks/Deadline.java | 10 +++++----- src/main/java/corgi/tasks/Event.java | 12 ++++++------ src/main/java/corgi/tasks/Task.java | 10 +++++----- src/main/java/corgi/tasks/TaskList.java | 6 +++--- src/main/java/corgi/tasks/ToDo.java | 12 ++++++------ 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main/java/corgi/commands/MarkTaskCommand.java b/src/main/java/corgi/commands/MarkTaskCommand.java index 4620355422..79e5f52598 100644 --- a/src/main/java/corgi/commands/MarkTaskCommand.java +++ b/src/main/java/corgi/commands/MarkTaskCommand.java @@ -22,19 +22,19 @@ public class MarkTaskCommand extends Command { /** * The new status of the task (true for done, false for undone). */ - private boolean status; + private boolean isDone; /** * Initializes a new MarkTaskCommand instance with the specified index, status, and command type. * * @param index The index of the task to be marked. - * @param status The new status of the task (true for done, false for undone). + * @param isDone The new status of the task (true for done, false for undone). * @param type The type of command (CommandType.MARK_DONE or CommandType.MARK_UNDONE). */ - public MarkTaskCommand(int index, boolean status) { + public MarkTaskCommand(int index, boolean isDone) { super(false); this.index = index; - this.status = status; + this.isDone = isDone; } /** @@ -52,12 +52,12 @@ public Pair execute(State currState, Stack> try { history.push(new Pair<>(currState, this)); - State newState = currState.markTask(this.index, this.status); + State newState = currState.markTask(this.index, this.isDone); TextRenderer renderer = newState.getTextRenderer(); TaskList list = newState.getTaskList(); - String returnMsg = (status) + String returnMsg = (isDone) ? renderer.showTaskDone(list.getTaskInfo(this.index)) : renderer.showTaskUndone(list.getTaskInfo(this.index)); @@ -71,7 +71,7 @@ public Pair execute(State currState, Stack> @Override public String toString() { - String action = this.status ? "Mark" : "Unmark"; + String action = this.isDone ? "Mark" : "Unmark"; return action + " task " + (this.index + 1); } } diff --git a/src/main/java/corgi/parsers/CommandParser.java b/src/main/java/corgi/parsers/CommandParser.java index c48c6f6ad7..a975407051 100644 --- a/src/main/java/corgi/parsers/CommandParser.java +++ b/src/main/java/corgi/parsers/CommandParser.java @@ -167,7 +167,7 @@ private Command newUnMarkCommand(String fullCommand) throws InvalidCommandFormat try { int index = Integer.parseInt(targetTaskNumber) - 1; - return new MarkTaskCommand(index, true); + return new MarkTaskCommand(index, false); } catch (NumberFormatException e) { throw new InvalidCommandFormatException("Please provide a valid task number!" + "\n\n" + commandFormat); diff --git a/src/main/java/corgi/parsers/TaskParser.java b/src/main/java/corgi/parsers/TaskParser.java index ed66d91bc9..baa37f1091 100644 --- a/src/main/java/corgi/parsers/TaskParser.java +++ b/src/main/java/corgi/parsers/TaskParser.java @@ -37,12 +37,12 @@ public Task parse(String s) throws ParsingException { String taskType = infos[0]; String statusStr = infos[1]; String desc = infos[2]; - boolean status = false; + boolean isDone = false; if (statusStr.equals("1")) { - status = true; + isDone = true; } else if (statusStr.equals("0")) { - status = false; + isDone = false; } else { throw new InvalidParsingFormatException("Task status should be 0 or 1!"); } @@ -54,7 +54,7 @@ public Task parse(String s) throws ParsingException { if (infos.length != 3) { throw new InvalidParsingFormatException("Wrong format for ToDo task!"); } - task = new ToDo(status, desc); + task = new ToDo(isDone, desc); break; case "D": if (infos.length != 4) { @@ -71,7 +71,7 @@ public Task parse(String s) throws ParsingException { assert by != null : "LocalDate object cannot be null"; - task = new Deadline(status, desc, by); + task = new Deadline(isDone, desc, by); break; case "E": @@ -92,7 +92,7 @@ public Task parse(String s) throws ParsingException { assert from != null : "LocalDate object cannot be null"; assert to != null : "LocalDate object cannot be null"; - task = new Event(status, desc, from, to); + task = new Event(isDone, desc, from, to); break; default: throw new InvalidParsingTypeException("Invalid task type!"); diff --git a/src/main/java/corgi/tasks/Deadline.java b/src/main/java/corgi/tasks/Deadline.java index 9704292c93..9091413fc0 100644 --- a/src/main/java/corgi/tasks/Deadline.java +++ b/src/main/java/corgi/tasks/Deadline.java @@ -28,14 +28,14 @@ public Deadline(String desc, LocalDate by) { * @param desc The description of the task. * @param by The deadline of the task. */ - public Deadline(boolean status, String desc, LocalDate by) { - super(status, desc); + public Deadline(boolean isDone, String desc, LocalDate by) { + super(isDone, desc); this.by = by; } @Override public Deadline markAsDone() throws TaskStatusException { - if (status) { + if (this.isDone) { throw new TaskStatusException("The task is already marked as done."); } return new Deadline(true, desc, by); @@ -43,7 +43,7 @@ public Deadline markAsDone() throws TaskStatusException { @Override public Deadline markAsNotDone() throws TaskStatusException { - if (!status) { + if (!this.isDone) { throw new TaskStatusException("The task is already marked as not done."); } return new Deadline(false, desc, by); @@ -66,7 +66,7 @@ public boolean isHappeningOnDate(LocalDate targetDate) { */ @Override public String toStorableString() { - String statusStr = this.status ? "1" : "0"; + String statusStr = this.isDone ? "1" : "0"; String formattedBy = this.by.format(Task.DATE_INPUT_FORMATTER); String[] infos = {"D", statusStr, this.desc, formattedBy}; diff --git a/src/main/java/corgi/tasks/Event.java b/src/main/java/corgi/tasks/Event.java index 28b44eaae0..03857a63de 100644 --- a/src/main/java/corgi/tasks/Event.java +++ b/src/main/java/corgi/tasks/Event.java @@ -28,20 +28,20 @@ public Event(String desc, LocalDate from, LocalDate to) { /** * Initializes a new event task with the given status, description, start date, and end date. * - * @param status The status of the task. + * @param isDone The status of the task. * @param desc The description of the task. * @param from The start date of the event. * @param to The end date of the event. */ - public Event(boolean status, String desc, LocalDate from, LocalDate to) { - super(status, desc); + public Event(boolean isDone, String desc, LocalDate from, LocalDate to) { + super(isDone, desc); this.from = from; this.to = to; } @Override public Event markAsDone() throws TaskStatusException { - if (status) { + if (this.isDone) { throw new TaskStatusException("The task is already marked as done."); } return new Event(true, desc, from, to); @@ -49,7 +49,7 @@ public Event markAsDone() throws TaskStatusException { @Override public Event markAsNotDone() throws TaskStatusException { - if (!status) { + if (!this.isDone) { throw new TaskStatusException("The task is already marked as not done."); } return new Event(false, desc, from, to); @@ -76,7 +76,7 @@ public boolean isHappeningOnDate(LocalDate targetDate) { */ @Override public String toStorableString() { - String statusStr = this.status ? "1" : "0"; + String statusStr = this.isDone ? "1" : "0"; String formattedFrom = this.from.format(Task.DATE_INPUT_FORMATTER); String formattedTo = this.to.format(Task.DATE_INPUT_FORMATTER); diff --git a/src/main/java/corgi/tasks/Task.java b/src/main/java/corgi/tasks/Task.java index 57c15d214d..52a1dad442 100644 --- a/src/main/java/corgi/tasks/Task.java +++ b/src/main/java/corgi/tasks/Task.java @@ -10,16 +10,16 @@ public abstract class Task implements Storable { public static final DateTimeFormatter DATE_INPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); public static final DateTimeFormatter DATE_OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("MMM dd yyyy"); protected final String desc; - protected final boolean status; + protected final boolean isDone; /** * Initializes a new task with its description. The task's initial status is set to not done. * - * @param status The status of the task. + * @param isDone The status of the task. * @param desc The description of the task. */ - public Task(boolean status, String desc) { - this.status = status; + public Task(boolean isDone, String desc) { + this.isDone = isDone; this.desc = desc; } @@ -45,7 +45,7 @@ public Task(boolean status, String desc) { * @return An icon ("X" for done, " " for not done). */ public String getStatusIcon() { - return (this.status ? "X" : " "); + return (this.isDone ? "X" : " "); } /** diff --git a/src/main/java/corgi/tasks/TaskList.java b/src/main/java/corgi/tasks/TaskList.java index 802c278eec..5f5b18d2c4 100644 --- a/src/main/java/corgi/tasks/TaskList.java +++ b/src/main/java/corgi/tasks/TaskList.java @@ -64,12 +64,12 @@ public TaskList remove(int index) throws TaskListIndexOutOfBoundsException { * Marks a task's status as done or not done and returns a new immutable TaskList with the updated task. * * @param index The index of the task to be marked. - * @param status The new status of the task. + * @param isDone The new status of the task. * @return A new TaskList with the specified task's status updated. * @throws TaskListIndexOutOfBoundsException If the index is invalid. * @throws TaskStatusException If the task was already marked with the given status. */ - public TaskList mark(int index, boolean status) throws TaskListIndexOutOfBoundsException, TaskStatusException { + public TaskList mark(int index, boolean isDone) throws TaskListIndexOutOfBoundsException, TaskStatusException { if (!isValidIndex(index)) { throw new TaskListIndexOutOfBoundsException(index); } @@ -78,7 +78,7 @@ public TaskList mark(int index, boolean status) throws TaskListIndexOutOfBoundsE Task targetTask = updatedTasks.get(index); - Task modifiedTask = (status) ? targetTask.markAsDone() : targetTask.markAsNotDone(); + Task modifiedTask = (isDone) ? targetTask.markAsDone() : targetTask.markAsNotDone(); updatedTasks.set(index, modifiedTask); diff --git a/src/main/java/corgi/tasks/ToDo.java b/src/main/java/corgi/tasks/ToDo.java index 80c23ed367..3ec127c457 100644 --- a/src/main/java/corgi/tasks/ToDo.java +++ b/src/main/java/corgi/tasks/ToDo.java @@ -17,16 +17,16 @@ public ToDo(String desc) { /** * Initializes a new todo task with the given status and description. * - * @param status The status of the task. + * @param isDone The status of the task. * @param desc The description of the task. */ - public ToDo(boolean status, String desc) { - super(status, desc); + public ToDo(boolean isDone, String desc) { + super(isDone, desc); } @Override public ToDo markAsDone() throws TaskStatusException { - if (status) { + if (this.isDone) { throw new TaskStatusException("The task is already marked as done."); } return new ToDo(true, desc); @@ -34,7 +34,7 @@ public ToDo markAsDone() throws TaskStatusException { @Override public ToDo markAsNotDone() throws TaskStatusException { - if (!status) { + if (!this.isDone) { throw new TaskStatusException("The task is already marked as not done."); } return new ToDo(false, desc); @@ -47,7 +47,7 @@ public ToDo markAsNotDone() throws TaskStatusException { */ @Override public String toStorableString() { - String statusStr = this.status ? "1" : "0"; + String statusStr = this.isDone ? "1" : "0"; String[] infos = {"T", statusStr, this.desc}; String combinedInfos = String.join(TaskParser.SEPARATOR, infos); From e59c0f44273ad924d29d84226007941881c4ff5c Mon Sep 17 00:00:00 2001 From: Nereus Ng Wei Bin Date: Tue, 19 Sep 2023 02:25:33 +0800 Subject: [PATCH 2/2] Remove dead code --- src/main/java/corgi/Corgi.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/corgi/Corgi.java b/src/main/java/corgi/Corgi.java index 79a4ca852b..8b11987fe3 100644 --- a/src/main/java/corgi/Corgi.java +++ b/src/main/java/corgi/Corgi.java @@ -35,9 +35,6 @@ public Corgi() { TaskList newList = new TaskList(newStorage.load()); this.state = new State(newList, newStorage, newRenderer); this.history = new Stack<>(); - // if (tasks.size() > 0) { - // this.renderer.showTasksLoaded(tasks.size()); - // } } public String getIntro() {