Skip to content

Commit

Permalink
Removed unnecessary imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavzzz committed Sep 21, 2022
1 parent b51074a commit 8c4e65a
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 66 deletions.
1 change: 1 addition & 0 deletions database/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T;borrow book;
11 changes: 0 additions & 11 deletions src/main/java/Duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,3 @@ public String getResponse(String input) throws DukeException, IOException {
return message;
}
}











50 changes: 32 additions & 18 deletions src/main/java/Duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class Storage {
private final List<List<String>> tasks;
private static final String TASK_FILE_PATH = "database/duke.txt";
private static final String TASK_FILE_DIR = "data";
private FileWriter fileWriter;
private final File taskFile;

Expand All @@ -25,7 +26,7 @@ public class Storage {
*
*/

public Storage() throws IOException {
public Storage() throws IOException, DukeException {
taskFile = new File(TASK_FILE_PATH);
tasks = new ArrayList<>();
addTasks(fileToList());
Expand Down Expand Up @@ -69,7 +70,7 @@ public List<Task> fileToList() {
return list;
}

public void updateTask(int taskNumber, Constants command) throws IOException {
public void updateTask(int taskNumber, Constants command) throws IOException, DukeException {
switch (command) {
case MARK:
tasks.get(taskNumber - 1).set(1, "X");
Expand All @@ -86,29 +87,30 @@ public void updateTask(int taskNumber, Constants command) throws IOException {
updateFile();
}

private void updateFile() throws IOException {
fileWriter = new FileWriter(TASK_FILE_PATH);
for (List<String> task : tasks) {
StringBuilder taskString = new StringBuilder(task.get(0)).append(";");
for (int i = 1; i < task.size(); i++) {
taskString.append(task.get(i));
if (i != task.size() - 1) {
taskString.append(";");
}
private void updateFile() throws DukeException {
try {
File fileDir = new File(TASK_FILE_DIR);
if (!fileDir.isDirectory() && !fileDir.mkdirs()) {
throw new DukeException("I cant save the task bro.");
}

FileWriter fileWriter = new FileWriter(TASK_FILE_PATH);
for (List<String> task : tasks) {
fileWriter.write(listToCsv(task));
}
fileWriter.write(taskString.append("\n").toString());
System.out.println("ayo");
fileWriter.close();
} catch (IOException e) {
throw new DukeException(
"Cant save the task list bro: " + e);
}
for (List<String> task : tasks)
System.out.println(String.join(", ", task));
}

public void addTask(Task addedTask) throws IOException {
public void addTask(Task addedTask) throws IOException, DukeException {
tasks.add(addedTask.toList());
updateFile();
}

private void addTasks(List<Task> addedTasks) throws IOException {
private void addTasks(List<Task> addedTasks) throws IOException, DukeException {
for (Task addedTask : addedTasks) {
addTask(addedTask);
}
Expand All @@ -120,4 +122,16 @@ public void close() throws IOException {
fileWriter.close();
}
}
}


private String listToCsv(List<String> list) {
StringBuilder csv = new StringBuilder(list.get(0)).append(";");
for (int i = 1; i < list.size(); i++) {
csv.append(list.get(i));
if (i != list.size() - 1) {
csv.append(";");
}
}
return csv.append("\n").toString();
}
}
2 changes: 1 addition & 1 deletion src/main/java/Duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ public TaskList filter(List<String> Keywords) {

return result;
}
}
}
1 change: 0 additions & 1 deletion src/main/java/Duke/commands/ByeCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import Duke.Storage;
import Duke.TaskList;
import Duke.Ui;
import java.util.List;
import java.io.IOException;

public class ByeCommands extends Command {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/Command.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package Duke.commands;

import java.util.ArrayList;
import java.util.List;
import Duke.DukeException;
import Duke.Storage;
import Duke.TaskList;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/Duke/commands/DeadlineCommands.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package Duke.commands;


import java.util.ArrayList;
import java.util.List;
import Duke.*;
import Duke.tasks.Deadline;
import Duke.tasks.Task;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/Duke/commands/DeleteCommands.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package Duke.commands;


import java.util.ArrayList;
import java.util.List;
import Duke.*;

import java.io.IOException;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/DetectDuplicateCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import Duke.*;

public class DetectDuplicateCommands extends Command {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/EventCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import Duke.tasks.Event;
import Duke.tasks.Task;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/Duke/commands/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import Duke.Storage;
import Duke.TaskList;
import Duke.Ui;
import java.util.List;

import java.io.IOException;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/Duke/commands/FindCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FindCommands extends Command {

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/ListCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import Duke.Storage;
import Duke.TaskList;
import Duke.Ui;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;

public class ListCommands extends Command {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/MarkCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import Duke.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MarkCommands extends TaskCommands {

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/Duke/commands/TaskCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

import Duke.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.List;


public abstract class TaskCommands extends Command {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/TodoCommands.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package Duke.commands;

import java.util.ArrayList;
import java.util.List;
import Duke.DukeException;
import Duke.Storage;
import Duke.TaskList;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/commands/UnmarkCommands.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package Duke.commands;

import java.util.ArrayList;
import java.util.List;
import Duke.*;
import java.io.IOException;

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Duke/gui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package Duke.gui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import Duke.*;
import Duke.commands.Command;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Duke/tasks/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public String format(LocalDate time) {
}

@Override
public List<String> toList() {
List<String> product = new ArrayList<>();
public ArrayList<String> toList() {
ArrayList<String> product = new ArrayList<>();
product.add("D");
product.addAll(super.toList());
product.add(by.toString());
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/Duke/tasks/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class Event extends Task {

Expand All @@ -20,8 +19,8 @@ public String format(LocalDate time) {
}

@Override
public List<String> toList() {
List<String> product = new ArrayList<>();
public ArrayList<String> toList() {
ArrayList<String> product = new ArrayList<>();
product.add("E");
product.addAll(super.toList());
product.add(at.toString());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Duke/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public String toString() {
return "[" + this.getStatusIcon() + "] " + description;
}

}
}
4 changes: 2 additions & 2 deletions src/main/java/Duke/tasks/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public Todo(String description) {
}

@Override
public List<String> toList() {
List<String> product = new ArrayList<>();
public ArrayList<String> toList() {
ArrayList<String> product = new ArrayList<>();
product.add("T");
product.addAll(super.toList());
return product;
Expand Down

0 comments on commit 8c4e65a

Please sign in to comment.