Skip to content

Commit

Permalink
Update java documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
michelleykw committed Sep 30, 2019
1 parent 43ac14f commit 5ddef6e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import java.text.ParseException;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
Expand All @@ -22,8 +21,6 @@ public Duke() {
storage = new Storage();
try {
taskList = new TaskList(storage.load());
} catch (FileNotFoundException f) {
System.out.println("File is not found.");
} catch (ParseException p) {
System.out.println("Parse exception occurred. Please ensure correct input format.");
} catch (IOException io) {
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
Expand All @@ -25,12 +24,13 @@ public Storage() {}

/**
* Loads the task from the file into an array list.
* Creates the file if it does not exists.
*
* @return The list of tasks to be loaded from the file.
* @throws FileNotFoundException If file is not found.
* @throws IOException If an input or output exception occurred.
* @throws ParseException If a parse exception occurred.
*/
public ArrayList<Task> load() throws FileNotFoundException, ParseException, IOException {
public ArrayList<Task> load() throws ParseException, IOException {
ArrayList<Task> list = new ArrayList<>();
if (!this.directory.exists()) {
this.directory.mkdir();
Expand All @@ -56,6 +56,12 @@ public ArrayList<Task> load() throws FileNotFoundException, ParseException, IOEx
return list;
}

/**
* Loads the todo to the list.
*
* @param taskArr The array with the command details.
* @param list The list where the todo is to be added to.
*/
public void loadTodoToList(String[] taskArr, ArrayList<Task> list) {
Todo todo = new Todo(taskArr[2]);
updateDone(todo, taskArr);
Expand All @@ -64,6 +70,13 @@ public void loadTodoToList(String[] taskArr, ArrayList<Task> list) {
}


/**
* Loads the deadline to the list.
*
* @param taskArr The array with the command details.
* @param list The list where the deadline is to be added to.
* @throws ParseException If a parse exception occurred.
*/
public void loadDeadlineToList(String[] taskArr, ArrayList<Task> list)
throws ParseException {
Deadline deadline = new Deadline(taskArr[2], getDate(taskArr));
Expand All @@ -72,6 +85,13 @@ public void loadDeadlineToList(String[] taskArr, ArrayList<Task> list)
list.add(deadline);
}

/**
* Loads the event to the list.
*
* @param taskArr The array with the command details.
* @param list The list where the event is to be added to.
* @throws ParseException If a parse exception occurred.
*/
public void loadEventToList(String[] taskArr, ArrayList<Task> list)
throws ParseException {
Event event = new Event(taskArr[2], getDate(taskArr));
Expand All @@ -80,6 +100,13 @@ public void loadEventToList(String[] taskArr, ArrayList<Task> list)
list.add(event);
}

/**
* Gets the date from the command details.
*
* @param taskArr The array with the command details.
* @return The date of the task.
* @throws ParseException If a parse exception occurred.
*/
public Date getDate(String[] taskArr) throws ParseException {
String date = taskArr[4].substring(8, 10) + " "
+ taskArr[4].substring(4, 7) + " "
Expand All @@ -88,11 +115,23 @@ public Date getDate(String[] taskArr) throws ParseException {
return convertToDate(date);
}

/**
* Updates the priority of the task.
*
* @param task The task which priority is to be updated.
* @param taskArr The array with the command details.
*/
public void updatePriority(Task task, String[] taskArr) {
String priority = taskArr[3];
task.setPriority(priority);
}

/**
* Updates the task to be done.
*
* @param task The task to be marked done.
* @param taskArr The array with the command details.
*/
public void updateDone(Task task, String[] taskArr) {
if (taskArr[1].equals("1")) {
assert (taskArr[1].equals("1"));
Expand Down

0 comments on commit 5ddef6e

Please sign in to comment.