diff --git a/data/data.txt b/data/data.txt index fece7e51ed..edf1b3a1a9 100644 --- a/data/data.txt +++ b/data/data.txt @@ -1,4 +1,5 @@ D%d%false%d%flying%d%1829-12-23 -T%d%true%d%test +T%d%false%d%test E%d%false%d%test%d%2020-12-12 D%d%false%d%test%d%2020-12-12 +T%d%false%d%this diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 721fe91164..e81279c465 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -42,6 +42,11 @@ File load() { return this.storeFile; } + /** + * Loads data file + * @param filePath path of file to be loaded + * @throws IOException exception thrown when loading a file + */ public void loadFile(String filePath) throws IOException { if (filePath == null) { filePath = "data/data.txt"; @@ -58,6 +63,11 @@ public void loadFile(String filePath) throws IOException { this.updatePointerFile(filePath); } + /** + * Saves data file + * @param tasks Task list to be saveed to file + * @throws IOException exception thrown when saving a file + */ public void saveFile(TaskList tasks) throws IOException { FileOutputStream fos = new FileOutputStream(this.storeFile); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); @@ -70,6 +80,10 @@ public void saveFile(TaskList tasks) throws IOException { bw.close(); } + /** + * Prompts the user to choose a storage file + * @return String path of the file chosen + */ public static String promptForFile() { JFileChooser fc = new JFileChooser("./data"); fc.setFileFilter(new FileNameExtensionFilter("*.txt", "txt")); diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 480a230cfe..25102ee8da 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -14,6 +14,11 @@ public class TaskList { this.loadTaskFile(file); } + /** + * Loads task file into task list + * @param file Storage file + * @throws IOException exception thrown when reading storage file + */ public void loadTaskFile(File file) throws IOException { BufferedReader br = new BufferedReader(new FileReader(file)); String line = br.readLine(); @@ -29,26 +34,51 @@ public void loadTaskFile(File file) throws IOException { } } + /** + * Sets task as done + * @param doneTask index of task + */ public void done(int doneTask) { taskList.get(doneTask).setDone(); } + /** + * Deletes task + * @param deleteTask index of task + */ public void delete(int deleteTask) { taskList.remove(deleteTask); } + /** + * Adds a deadline task + * @param task Task name + * @param deadline Task deadline + * @return Task object + */ public Task addDeadline(String task, String deadline) { Deadline dl = new Deadline(task, deadline); taskList.add(dl); return dl; } + /** + * Adds a todo task + * @param task Task name + * @return Task object + */ public Task addTodo(String task) { Todo td = new Todo(task); taskList.add(td); return td; } + /** + * Adds a event task + * @param task Task name + * @param at Task date + * @return Task object + */ public Task addEvent(String task, String at) { Event e = new Event(task, at); taskList.add(e); @@ -77,6 +107,11 @@ public String toString() { } } + /** + * Finds tasks matching a given key + * @param key Key to be found + * @return List of tasks found + */ public String find(String key) { String rtn = taskList.stream() .map(task -> task.toString()) diff --git a/src/test/java/TodoTest.java b/src/test/java/TodoTest.java index aeb396d13f..8909a89a61 100644 --- a/src/test/java/TodoTest.java +++ b/src/test/java/TodoTest.java @@ -1,17 +1,17 @@ -import org.junit.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.Test; + public class TodoTest { @Test public void testTodo() { Todo testTodo = new Todo("Todo 1"); - assertEquals("[T][✗] Todo 1",testTodo.toString()); + assertEquals("[T][✗] Todo 1", testTodo.toString()); } @Test public void testTodoDone() { Todo testTodo = new Todo("Todo 1"); testTodo.setDone(); - assertEquals("[T][✓] Todo 1",testTodo.toString()); + assertEquals("[T][✓] Todo 1", testTodo.toString()); } }