Skip to content

Commit

Permalink
Merge pull request #11 from NereusWB922/5-sharing-ip-code-quality-fee…
Browse files Browse the repository at this point in the history
…dback-for-nereuswb922

Solve issue #5
  • Loading branch information
NereusWB922 authored Sep 18, 2023
2 parents 296c95d + e59c0f4 commit 5ccfcff
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
3 changes: 0 additions & 3 deletions src/main/java/corgi/Corgi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/corgi/commands/MarkTaskCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -52,12 +52,12 @@ public Pair<State, String> execute(State currState, Stack<Pair<State, Command>>
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));

Expand All @@ -71,7 +71,7 @@ public Pair<State, String> execute(State currState, Stack<Pair<State, Command>>

@Override
public String toString() {
String action = this.status ? "Mark" : "Unmark";
String action = this.isDone ? "Mark" : "Unmark";
return action + " task " + (this.index + 1);
}
}
2 changes: 1 addition & 1 deletion src/main/java/corgi/parsers/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/corgi/parsers/TaskParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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) {
Expand All @@ -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":
Expand All @@ -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!");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/corgi/tasks/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ 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);
}

@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);
Expand All @@ -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};
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/corgi/tasks/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ 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);
}

@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);
Expand All @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/corgi/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public abstract class Task implements Storable<Task> {
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;
}

Expand All @@ -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" : " ");
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/corgi/tasks/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/corgi/tasks/ToDo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ 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);
}

@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);
Expand All @@ -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);
Expand Down

0 comments on commit 5ccfcff

Please sign in to comment.