Skip to content

Commit

Permalink
Modify the data file reading format
Browse files Browse the repository at this point in the history
  • Loading branch information
emilysim00 committed Mar 3, 2022
1 parent cb9dc4f commit 9ed7723
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions database/database.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T|1|meet jerry, james and keyy
E|0|meet kelly |Nov-10-2021 6:20PM
4 changes: 2 additions & 2 deletions src/main/java/EmProgram/exception/StorageException.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class StorageException extends Exception{
public static final String IO_EXCEPTION = "☹ OOPS!!! Something wrong with the input-output operation.";
public static final String INVALID_FILE_INPUT = "☹ OOPS!!! The file information is corrupted. " +
"Please ensure that the data in the file is separated by commas and in the format of\n " +
"[Task Type, task status, task description, task timing(applicable for event/deadline task)]\n"+
" For example:\n " + " T,0,read book\n" + " E,1,meet kelly,Nov-11-2012 12:30PM\n" +
"[Task Type| task status| task description| task timing (applicable for event/deadline task)]\n"+
" For example:\n " + " T|0|read book\n" + " E|1|meet kelly|Nov-11-2012 12:30PM\n" +
"Please also ensure that there are no spaces after the commas.";

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/em/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public static String formulateDatabaseInput(String[] taskDescription) {
String databaseInput = null;
switch (taskDescription[0]) {
case "todo":
databaseInput = "T," + "0," + taskDescription[1];
databaseInput = "T|" + "0|" + taskDescription[1];
break;
case "deadline":
databaseInput = "D," + "0," + taskDescription[1] + "," + taskDescription[2];
databaseInput = "D|" + "0|" + taskDescription[1] + "|" + taskDescription[2];
break;
case "event":
databaseInput = "E," + "0," + taskDescription[1] + "," + taskDescription[2];
databaseInput = "E|" + "0|" + taskDescription[1] + "|" + taskDescription[2];
break;
}
return databaseInput;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/em/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static ArrayList populateFileContents() throws FileNotFoundException, Inv
for (String lines : fileContentLines) {
isFileContentValid(lines);
String userInput = null;
String[] contentsInALine = lines.split(",", -1);
String[] contentsInALine = lines.split("\\|", -1);
if (contentsInALine.length < 1) {
throw new InvalidUserInputException(INVALID_INPUT);
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public static void checkFileExists() throws IOException {
* @throws StorageException If command in the file is invalid.
*/
public static void isFileContentValid(String fileCommand) throws StorageException {
String[] fileCommandArray = fileCommand.split(",");
String[] fileCommandArray = fileCommand.split("\\|");
switch (fileCommandArray[0]) {
case "T":
if (fileCommandArray.length < 3) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/em/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static ArrayList findContent(String keyword) {
fileContentLines = Files.readAllLines(Storage.databasePath);
int taskNumber = 1;
for (String lines : fileContentLines) {
String[] contentsInALine = lines.split(",", -1);
String[] contentsInALine = lines.split("\\|", -1);
if (contentsInALine.length < 1) {
throw new InvalidUserInputException(NO_DESCRIPTION);
}
Expand Down
6 changes: 6 additions & 0 deletions text-ui-test/database/database.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
T|0|buy book
E|1|meeting with kelly |Jan-1-2022 5:30PM
D|0|return book |Feb-3-2022 11:20AM
D|0|return kelly water bottle |Mar-11-2022 1:30PM
E|1|meet ben |Oct-11-2022 2:15PM
D|0|assignment 3 |Jan-1-2011 12:30PM

0 comments on commit 9ed7723

Please sign in to comment.