Skip to content

Commit

Permalink
Fix checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
koonweee committed Oct 18, 2020
1 parent 86a85a4 commit 8bb5803
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
3 changes: 2 additions & 1 deletion data/data.txt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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));
Expand All @@ -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"));
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/TodoTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 8bb5803

Please sign in to comment.