Package amadeus.brain
Class Database
java.lang.Object
amadeus.brain.Database
-
Field Details
-
FILE_PATH
The file path where tasks are saved and loaded from.The default file path is
"Memory.txt".- See Also:
-
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
save
Saves the current list of tasks to a file.Each task is converted to a file-friendly format using the
Task.toFileFormat()method and written to the file specified byFILE_PATH.- Parameters:
tasks- the list of tasks to save; must not benull.- Throws:
AmadeusException- if an error occurs while saving tasks to the file.
-
parseSave
Parses a line from the file into aTaskobject.The line is expected to be in a specific format, depending on the task type:
- ToDo:
T | <isDone> | <description> - Deadline:
D | <isDone> | <description> | <by> - Event:
E | <isDone> | <description> | <from> | <to>
- Parameters:
line- the line from the file to parse; must not benull.- Returns:
- the
Taskobject corresponding to the line. - Throws:
AmadeusException- if the line is invalid or cannot be parsed.
- ToDo:
-
load
Loads tasks from the file and returns them as a list ofTaskobjects.If the file does not exist, an empty list is returned. If the file exists, each line is parsed into a
Taskobject using theparseSave(String)method.- Returns:
- a list of tasks loaded from the file; never
null. - Throws:
AmadeusException- if an error occurs while loading tasks from the file.
-