forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2113-AY2324S1#14 from AY2324S1-CS2113-F11-3/…
…master Update
- Loading branch information
Showing
13 changed files
with
179 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
3 | cs2113 | software enginnering | 3 | ||
5 | Hello | Duke | 4 | ||
7 | Hello | Duke | 4 | ||
9 | id | checker | 6 | ||
10 | id increases | correctly | 5 | ||
11 | f | dfdf | 5 | ||
12 | dfdf | | 5 | ||
13 | 1 | j | 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
3 | cs2113 | software enginnering | 3 | ||
5 | Hello | Duke | 4 | ||
7 | Hello | Duke | 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package seedu.duke.storage; | ||
|
||
import seedu.duke.calendar.Event; | ||
import seedu.duke.calendar.Goal; | ||
import seedu.duke.storage.exceptions.EventFileFormatException; | ||
import seedu.duke.storage.exceptions.FlashcardFileFormatException; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class EventStorageParser { | ||
|
||
private static Logger logger; // for logging | ||
|
||
/** | ||
* check the saved file format | ||
* token length should be 3 or 4 | ||
* if token length is 3, format should be string, localdatetime, localdatetime | ||
* if token length is 4, format should be string, localdatetime, int, int | ||
* @param tokens is a split txt line | ||
* @throws EventFileFormatException | ||
*/ | ||
public static void eventFileChecker(String[] tokens) throws EventFileFormatException { | ||
if(tokens.length != 3 && tokens.length != 4) { | ||
throw new EventFileFormatException(); | ||
} | ||
|
||
try { | ||
LocalDateTime.parse(tokens[1].trim()); | ||
if(tokens.length == 3){ | ||
LocalDateTime.parse(tokens[2].trim()); | ||
} | ||
if(tokens.length == 4){ | ||
Integer.parseInt(tokens[2].trim()); | ||
Integer.parseInt(tokens[3].trim()); | ||
} | ||
} catch (DateTimeParseException | NumberFormatException e) { | ||
throw new EventFileFormatException(); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* load an event from certain format | ||
* Tokens includes attributes of Event | ||
* @param tokens is used to get event name | ||
* @return Event object | ||
*/ | ||
public static Event loadEvent(String[] tokens){ | ||
|
||
logger = Logger.getLogger("event"); | ||
logger.setLevel(Level.WARNING); | ||
|
||
assert tokens.length == 3 || tokens.length == 4: "Token length should be 3 or 4"; | ||
|
||
if(tokens.length == 3) { | ||
String name = tokens[0].trim(); | ||
LocalDateTime from = LocalDateTime.parse(tokens[1].trim()); | ||
LocalDateTime to = LocalDateTime.parse(tokens[2].trim()); | ||
|
||
logger.log(Level.INFO, "loaded event"); | ||
|
||
return new Event(name, from, to); | ||
} | ||
String name = tokens[0].trim(); | ||
LocalDateTime by = LocalDateTime.parse(tokens[1].trim()); | ||
int goal = Integer.parseInt(tokens[2].trim()); | ||
int completed = Integer.parseInt(tokens[3].trim()); | ||
|
||
logger.log(Level.INFO, "loaded event"); | ||
|
||
return new Goal(name, by, goal, completed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/seedu/duke/storage/exceptions/EventFileFormatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package seedu.duke.storage.exceptions; | ||
|
||
public class EventFileFormatException extends Exception{ | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/seedu/duke/storage/exceptions/FlashcardFileFormatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package seedu.duke.storage.exceptions; | ||
|
||
public class FlashcardFileFormatException extends Exception{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters