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

Add rest of the CodeQuality changes. #2

Merged
merged 1 commit into from
Feb 13, 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
6 changes: 6 additions & 0 deletions src/main/java/zoe/DoneStates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package zoe;

public enum DoneStates {
NotDone,
Done;
}
16 changes: 16 additions & 0 deletions src/main/java/zoe/LoadSplit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package zoe;

public enum LoadSplit {
Task_Type(0),
Description(1),
Status(2);

private final int idx;
private LoadSplit(int idx) {
this.idx = idx;
}

public int getIdx() {
return idx;
}
}
18 changes: 13 additions & 5 deletions src/main/java/zoe/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,24 @@ public ArrayList<Task> loadTasks(){
BufferedReader reader = new BufferedReader(new FileReader(file));
ArrayList<Task> loadedTasks = new ArrayList<Task>();
String line;

while (!(line = reader.readLine()).equals("EOF")) {
String[] readTask = line.split("_");
if (readTask[0].equals("todo")) {
ToDo td = new ToDo(readTask[1], readTask[2]);
int taskType = LoadSplit.Task_Type.getIdx();
int description = LoadSplit.Description.getIdx();
int status = LoadSplit.Status.getIdx();

if (readTask[taskType].equals("todo")) {
ToDo td = new ToDo(
readTask[description], readTask[status]);
loadedTasks.add(td);
} else if (readTask[0].equals("event")) {
Event e = new Event(readTask[1], readTask[2]);

} else if (readTask[taskType].equals("event")) {
Event e = new Event(readTask[description], readTask[status]);
loadedTasks.add(e);

} else {
Deadline dl = new Deadline(readTask[1], readTask[2]);
Deadline dl = new Deadline(readTask[description], readTask[status]);
loadedTasks.add(dl);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/zoe/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ public String carryOutShortCommand(String command) {
String res = "";
if (command.equals("list")) {
if (tl.getSize() < 1) {
res += "Sorry you dont have any tasks currently D:";
res += "Sorry you don't have any tasks currently D:";
} else {
for (int i = 1; i <= tl.getSize(); i++) {
res += String.format("%d.%s\n",
i, tl.get(i).getStatus());
res += String.format("%d.%s\n", i, tl.get(i).getStatus());
}
}
return res;

} else {
if (command.equals("todo")) {
Expand All @@ -49,8 +47,9 @@ public String carryOutShortCommand(String command) {
res += ui.invalidCommand();
}

return res;
}

return res;
}

/**
Expand Down Expand Up @@ -88,6 +87,7 @@ public String carryOutLongCommand(String command, String commandDescription) {
}

return res;

case "mark":
tl.markAsDone(Integer.parseInt(commandDescription));
return ui.markedTask(tl.get(Integer.parseInt(commandDescription)));
Expand All @@ -98,10 +98,13 @@ public String carryOutLongCommand(String command, String commandDescription) {
Task deletedTask = tl.get(Integer.parseInt(commandDescription));
tl.delete(Integer.parseInt(commandDescription));
return ui.deletedTask(deletedTask, tl.getSize());

default:
return ui.invalidCommand();
}

} catch (IndexOutOfBoundsException e) {
//catches invalid index from user input for mark, unmark and delete
return ui.invalidIndex(tl.getSize());
} catch (DateTimeParseException d) {
return ui.invalidDate();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/zoe/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public int isDoneNumerical() {
//to help with saving and loading
if (this.isDone) {
return 1;
} else {
return 0;
}

return 0;
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/zoe/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void add(Task t) {
* @param i
*/
public void delete(int i) {
tasks.remove(Integer.valueOf(i) - 1);
tasks.remove(Integer.valueOf(i) - 1);
}

/**
Expand Down Expand Up @@ -54,9 +54,4 @@ public Task get(int i) {
return this.tasks.get(i - 1);
}

/**
* Checks if a task exists in the list given an index when isValid(index) is called.
* @param i
* @return
*/
}