Skip to content

Commit

Permalink
resolved merging conflicts with B-Snooze
Browse files Browse the repository at this point in the history
  • Loading branch information
limweijun committed Sep 10, 2022
2 parents 9437253 + 214560c commit ca0fe08
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
String javaFxVersion = '11'
String javaFxVersion = '11.0.2'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
Expand Down
5 changes: 5 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<<<<<<< HEAD
D|0|abc|2022-10-04T12:00
=======
T|1|play
T|1|eat
>>>>>>> 214560c1796b2e9cd7580c42ade8f2d41082b479
6 changes: 3 additions & 3 deletions src/main/java/Duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class Duke {
public Duke(String filePath, FXMLLoader fxmlLoader) {
ui = new Ui();
mainWindow = fxmlLoader.<MainWindow>getController();
String[] seperates = filePath.split("/");
storage = new Storage(ui, seperates[0], seperates[1], mainWindow);
String[] strArr = filePath.split("/");
storage = new Storage(strArr[0], strArr[1], mainWindow);
try {
tasks = new TaskList(ui, storage, mainWindow);
tasks = new TaskList(storage, mainWindow);
} catch (Exception e) {
mainWindow.printErrorMessage(e.toString());
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Duke/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public void printDeleteSuccessfulMsg(Task task, int size) {
/**
* The method is a static and takes in two parameter
* @param task of type Task
* @param size of type int
*/
public void printUpdateSuccessfulMsg(Task task) {
Label dukeText = new Label("Kk. Updated:\n" + task.toString() +
Expand Down
88 changes: 57 additions & 31 deletions src/main/java/Duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,65 @@ public class Parser {
* @param tasks of type TaskList
*/
public static void readLine(Ui ui, String command, TaskList tasks, MainWindow mainWindow) {
String[] strs = command.split(" ");
String[] strArr = command.split(" ");
if (command.equals("bye")) {
ui.closeApplication();
} else if (command.equals("list")) {
mainWindow.printList(tasks);
} else if (strs.length == 2 && (strs[0].equals("mark") || strs[0].equals("unmark"))) {
int index = Integer.parseInt(strs[1]) - 1;
if (strs[0].equals("mark")) {
tasks.markTaskAsDone(index);
} else if (strs[0].equals("unmark")) {
tasks.unMarkTaskAsDone(index);
}
} else if (strs.length == 2 && (strs[0].equals("delete"))) {
int index = Integer.parseInt(strs[1]) - 1;
tasks.deleteTask(index);
} else if (strs.length == 2 && (strs[0].equals("find"))) {
ArrayList<Task> tempTasks = new ArrayList<>();
for (int i = 0; i < tasks.getSize(); i++) {
if (tasks.getTask(i).getTask().contains(strs[1])) {
tempTasks.add(tasks.getTask(i));
}
}
mainWindow.printFindTasks(tempTasks);
} else if (strs.length == 5 && (strs[0].equals("update") && strs[1].equals("datetime"))) {
int index = Integer.parseInt(strs[2]) - 1;
String newDateStr = strs[3] + " " + strs[4];
tasks.updateTask(index, newDateStr);
} else if (strArr.length == 2 && (strArr[0].equals("mark") || strArr[0].equals("unmark"))) {
markUnmarkTask(strArr, tasks);
} else if (strArr.length == 2 && (strArr[0].equals("delete"))) {
deleteTask(strArr, tasks);
} else if (strArr.length == 2 && (strArr[0].equals("find"))) {
findTask(strArr, tasks, mainWindow);
} else if (strArr.length == 5 && (strArr[0].equals("update") && strArr[1].equals("datetime"))) {
updateDateTime(strArr, tasks);
} else {
try {
String[] details;
Task task;
switch (strs[0]) {
handleTodoDeadlineEvent(strArr, command, tasks, mainWindow);
}
}

private static void markUnmarkTask(String[] strArr, TaskList tasks) {
assert java.util.regex.Pattern.matches("\\d+", strArr[1]) : "The 2nd parameter should be a " +
"positive integer";
int index = Integer.parseInt(strArr[1]) - 1;
assert index < tasks.getSize() : "the index to be mark or unmark should be less than " + tasks.getSize();
if (strArr[0].equals("mark")) {
tasks.markTaskAsDone(index);
} else if (strArr[0].equals("unmark")) {
tasks.unMarkTaskAsDone(index);
}
}

private static void deleteTask(String[] strArr, TaskList tasks) {
assert java.util.regex.Pattern.matches("\\d+", strArr[1]) : "The 2nd parameter should be a " +
"positive integer";
int index = Integer.parseInt(strArr[1]) - 1;
assert index < tasks.getSize() : "the index to be deleted should be less than " + tasks.getSize();
tasks.deleteTask(index);
}

private static void findTask(String[] strArr, TaskList tasks, MainWindow mW) {
ArrayList<Task> tempTasks = new ArrayList<>();
for (int i = 0; i < tasks.getSize(); i++) {
if (tasks.getTask(i).getTask().contains(strArr[1])) {
tempTasks.add(tasks.getTask(i));
}
}
mW.printFindTasks(tempTasks);
}

private static void updateDateTime(String[] strArr, TaskList tasks) {
int index = Integer.parseInt(strArr[2]) - 1;
String newDateStr = strArr[3] + " " + strArr[4];
tasks.updateTask(index, newDateStr);
}

private static void handleTodoDeadlineEvent(String[] strArr, String command, TaskList tasks, MainWindow mW) {
try {
String[] details;
Task task;
switch (strArr[0]) {
case "deadline":
details = command.split(" ", 2)[1].split(" /by ");
task = new Deadline(details[0], false, details[1]);
Expand All @@ -62,11 +89,10 @@ public static void readLine(Ui ui, String command, TaskList tasks, MainWindow ma
tasks.addTask(task);
break;
default:
mainWindow.printDontUnderstandMsg();
}
} catch (ArrayIndexOutOfBoundsException e) {
mainWindow.printDescriptionCantBeEmptyMsg(strs[0]);
mW.printDontUnderstandMsg();
}
} catch (ArrayIndexOutOfBoundsException e) {
mW.printDescriptionCantBeEmptyMsg(strArr[0]);
}
}
}
66 changes: 38 additions & 28 deletions src/main/java/Duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ public class Storage {
BufferedReader bR;
File dukeFile;
MainWindow mainWindow;
Ui ui;

/**
* The method takes in two parameters
* @param pathName of type String
* @param fileName of type String
*/
public Storage(Ui ui, String pathName, String fileName, MainWindow mainWindow) {
this.ui = ui;
public Storage(String pathName, String fileName, MainWindow mainWindow) {
this.mainWindow = mainWindow;
Path file = Paths.get(pathName);
File curr = new File(String.valueOf(pathName), fileName);
Expand All @@ -50,29 +48,7 @@ public ArrayList<Task> load() {
bR = new BufferedReader(new FileReader(dukeFile));
ArrayList<Task> tasksToDo = new ArrayList<>();
String currLine = bR.readLine();
while (currLine != null) {
String[] details = currLine.split("\\|");
boolean done = !Objects.equals(details[1], "0");
String type = details[0];
String[] date;
switch (type) {
case "T":
tasksToDo.add(new Todo(details[2], done));
break;
case "D":
date = details[3].split("T");
tasksToDo.add(new Deadline(details[2], done, date[0] + " " + date[1]));
break;
case "E":
date = details[3].split("T");
tasksToDo.add(new Event(details[2], done, date[0] + " " + date[1]));
break;
default:
break;
}
currLine = bR.readLine();
}
return tasksToDo;
return handleFileList(tasksToDo, currLine);
} catch (IOException e) {
mainWindow.printErrorMessage(e.toString());
}
Expand All @@ -87,8 +63,8 @@ public ArrayList<Task> load() {
public boolean updateFile(Task task) {
try {
String taskStr = task.getType() == 'T' ?
('T' + "|" + task.getDone() + "|" + task.getTask())
: (task.getType() + "|" + task.getDone() + "|" + task.getTask() + "|" + task.getOriginalDetail());
getTodoString(task)
: getEventDeadlineString(task);
Files.write(Paths.get(filePath), (taskStr + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND);
return true;
} catch (IOException e) {
Expand All @@ -115,4 +91,38 @@ public boolean rewriteEntireFile(ArrayList<Task> tasks) {
return false;
}
}

public ArrayList<Task> handleFileList(ArrayList<Task> tasksToDo, String currLine) throws IOException {
while (currLine != null) {
String[] details = currLine.split("\\|");
boolean done = !Objects.equals(details[1], "0");
String type = details[0];
String[] date;
switch (type) {
case "T":
tasksToDo.add(new Todo(details[2], done));
break;
case "D":
date = details[3].split("T");
tasksToDo.add(new Deadline(details[2], done, date[0] + " " + date[1]));
break;
case "E":
date = details[3].split("T");
tasksToDo.add(new Event(details[2], done, date[0] + " " + date[1]));
break;
default:
break;
}
currLine = bR.readLine();
}
return tasksToDo;
}

public String getTodoString(Task task) {
return 'T' + "|" + task.getDone() + "|" + task.getTask();
}

public String getEventDeadlineString(Task task) {
return task.getType() + "|" + task.getDone() + "|" + task.getTask() + "|" + task.getOriginalDetail();
}
}
8 changes: 3 additions & 5 deletions src/main/java/Duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
*/
public class TaskList {
ArrayList<Task> tasks;
Ui ui;
MainWindow mainWindow;
Storage storage;

/**
* The method takes in two parameter
* @param ui of type Ui
* @param storage of type Ui
* @param storage of type Storage
*/
public TaskList(Ui ui, Storage storage, MainWindow mainWindow) {
public TaskList(Storage storage, MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.tasks = storage.load();
this.ui = ui;

this.storage = storage;
}

Expand Down

0 comments on commit ca0fe08

Please sign in to comment.