Skip to content

Commit

Permalink
fixed all checkstyle errors except javadocs missing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hauchongtang committed Aug 19, 2022
1 parent 590af8f commit a5ea391
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 147 deletions.
6 changes: 3 additions & 3 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package duke;

import java.io.IOException;

import duke.command.Command;
import duke.parser.Parser;

import java.io.IOException;

public class Duke {
private final Ui ui;
private final Storage storage;
Expand Down Expand Up @@ -34,4 +34,4 @@ public static void main(String[] args) throws Storage.InvalidStorageFilePathExce
Duke duke = new Duke();
duke.run();
}
}
}
9 changes: 5 additions & 4 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package duke;

import duke.task.TaskList;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import duke.task.TaskList;

public class Storage {
public static final String DEFAULT_FILE_NAME = "todolist.txt";
public final Path path;
Expand All @@ -19,7 +19,8 @@ public class Storage {
Storage(String filePath) throws InvalidStorageFilePathException, IOException {
this.path = Paths.get(System.getProperty("user.dir"), filePath);
if (!validPath(filePath)) {
throw new InvalidStorageFilePathException("duke.task.Storage file needs to end with .txt, please try again.");
throw new InvalidStorageFilePathException(
"duke.task.Storage file needs to end with .txt, please try again.");
}
if (!Files.exists(path) || !Files.isRegularFile(path)) {
// Create a new file
Expand Down Expand Up @@ -63,7 +64,7 @@ public TaskList writeDataToFile(TaskList taskList) throws IOException {
taskList.getTaskList().forEach((task) -> {
sb.append(StorageWriter.writeSingleTask(task) + "\n");
});
String toWrite = sb.subSequence(0, sb.length()-1).toString();
String toWrite = sb.subSequence(0, sb.length() - 1).toString();
byte[] byteString = toWrite.getBytes();
Files.write(this.path, byteString);
return taskList;
Expand Down
100 changes: 62 additions & 38 deletions src/main/java/duke/StorageParser.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package duke;

import duke.task.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import duke.task.Deadline;
import duke.task.Event;
import duke.task.Task;
import duke.task.TaskList;
import duke.task.TaskType;
import duke.task.ToDo;

public class StorageParser {
static TaskList parseFile(List<String> lines) {
List<Task> tasks = new ArrayList<>();
Expand All @@ -15,66 +20,85 @@ static TaskList parseFile(List<String> lines) {
}

static Task formatTask(String rawTask) {
String identifier = rawTask.substring(0,1).toUpperCase(Locale.ROOT);
String identifier = rawTask.substring(0, 1).toUpperCase(Locale.ROOT);
boolean marked = false;
String[] segments = rawTask.split("\\| ");
StringBuilder sb = new StringBuilder();
Task formattedTask = new Task("", TaskType.TASK);

switch (identifier) {
case "T":
if (segments[1].contains("1")) marked = true;

for (int i = 0; i < segments.length; i++) {
if (i >= 2) {
sb.append(segments[i]);
}
case "T":
if (segments[1].contains("1")) {
marked = true;
}

for (int i = 0; i < segments.length; i++) {
if (i >= 2) {
sb.append(segments[i]);
}
}

formattedTask = new ToDo(sb.toString());
formattedTask = new ToDo(sb.toString());

if (marked) {
formattedTask.markAsDone(true);
}
if (marked) {
formattedTask.markAsDone(true);
}

return formattedTask;
return formattedTask;

case "D":
if (segments[1].contains("1")) marked = true;
case "D":
if (segments[1].contains("1")) {
marked = true;
}

String deadlineDesc = "";
StringBuilder deadlineBy = new StringBuilder();
String deadlineDesc = "";
StringBuilder deadlineBy = new StringBuilder();

for (int i = 0; i < segments.length; i++) {
if (i == 2) deadlineDesc = segments[i];
if (i >= 3) deadlineBy.append(segments[i]);
for (int i = 0; i < segments.length; i++) {
if (i == 2) {
deadlineDesc = segments[i];
}
if (i >= 3) {
deadlineBy.append(segments[i]);
}
}

LocalDateTime doneBy = DateHandler.parseDateString(deadlineBy.toString());
formattedTask = new Deadline(deadlineDesc, doneBy);
LocalDateTime doneBy = DateHandler.parseDateString(deadlineBy.toString());
formattedTask = new Deadline(deadlineDesc, doneBy);

if (marked) formattedTask.markAsDone(true);
if (marked) {
formattedTask.markAsDone(true);
}

return formattedTask;
return formattedTask;

case "E":
if (segments[1].contains("1")) marked = true;
case "E":
if (segments[1].contains("1")) {
marked = true;
}

String eventDesc = "";
StringBuilder eventBy = new StringBuilder();
String eventDesc = "";
StringBuilder eventBy = new StringBuilder();

for (int i = 0; i < segments.length; i++) {
if (i == 2) eventDesc = segments[i];
if (i >= 3) eventBy.append(segments[i]);
for (int i = 0; i < segments.length; i++) {
if (i == 2) {
eventDesc = segments[i];
}
if (i >= 3) {
eventBy.append(segments[i]);
}
}

LocalDateTime eventAt = DateHandler.parseDateString(eventBy.toString());
formattedTask = new Event(eventDesc, eventAt);
LocalDateTime eventAt = DateHandler.parseDateString(eventBy.toString());
formattedTask = new Event(eventDesc, eventAt);

if (marked) formattedTask.markAsDone(true);
if (marked) {
formattedTask.markAsDone(true);
}

return formattedTask;
return formattedTask;
default:
return formattedTask;
}
return formattedTask;
}
}
16 changes: 8 additions & 8 deletions src/main/java/duke/StorageWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ public class StorageWriter {
static String writeSingleTask(Task task) {
int done = task.getDoneStatus();
switch (task.type) {
case TODO:
return String.format("%s | %d | %s", "T", done, task.getDescription());
case DEADLINE:
return String.format("%s | %d | %s| %s", "D", done, task.getDescription(), task.getBy());
case EVENT:
return String.format("%s | %d | %s| %s", "E", done, task.getDescription(), task.getBy());
default:
return "";
case TODO:
return String.format("%s | %d | %s", "T", done, task.getDescription());
case DEADLINE:
return String.format("%s | %d | %s| %s", "D", done, task.getDescription(), task.getBy());
case EVENT:
return String.format("%s | %d | %s| %s", "E", done, task.getDescription(), task.getBy());
default:
return "";
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package duke.command;

import java.io.IOException;

import duke.DukeException;
import duke.Storage;
import duke.Ui;
import duke.task.TaskList;

import java.io.IOException;

public class Command {
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException, DukeException {
System.out.println("Parent class Command executed");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package duke.command;

import java.io.IOException;

import duke.Storage;
import duke.Ui;
import duke.task.Task;
import duke.task.TaskList;

import java.io.IOException;

public class DeadlineCommand extends Command {
public static final String COMMAND_ID = "DEADLINE";
private final Task task;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package duke.command;

import java.io.IOException;

import duke.Storage;
import duke.Ui;
import duke.task.TaskList;

import java.io.IOException;

public class DeleteCommand extends Command {
public static final String COMMAND_ID = "DELETE";
private final int targetIndex;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/command/EventCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package duke.command;

import java.io.IOException;

import duke.Storage;
import duke.Ui;
import duke.task.Task;
import duke.task.TaskList;

import java.io.IOException;

public class EventCommand extends Command {
public static final String COMMAND_ID = "EVENT";
private final Task task;
Expand All @@ -20,4 +20,4 @@ public void execute(TaskList taskList, Ui ui, Storage storage) throws IOExceptio
taskList.addTaskToList(task);
storage.writeDataToFile(taskList);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class ExitCommand extends Command {
public static final String COMMAND_ID = "BYE";
private static String EXIT_MSG = "Bye. Hope to see you again soon!";
private static final String EXIT_MSG = "Bye. Hope to see you again soon!";

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/MarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package duke.command;

import java.io.IOException;

import duke.Storage;
import duke.Ui;
import duke.task.TaskList;

import java.io.IOException;

public class MarkCommand extends Command {
public static final String COMMAND_ID = "MARK";
private final int targetIndex;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/ToDoCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package duke.command;

import java.io.IOException;

import duke.Storage;
import duke.Ui;
import duke.task.Task;
import duke.task.TaskList;

import java.io.IOException;

public class ToDoCommand extends Command {
public static final String COMMAND_ID = "TODO";
private final Task task;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/UnMarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package duke.command;

import java.io.IOException;

import duke.Storage;
import duke.Ui;
import duke.task.TaskList;

import java.io.IOException;

public class UnMarkCommand extends Command {
public static final String COMMAND_ID = "UNMARK";
private final int targetIndex;
Expand Down
Loading

0 comments on commit a5ea391

Please sign in to comment.