Package amadeus.brain

Class Database

java.lang.Object
amadeus.brain.Database

public class Database extends Object
Manages the storage and retrieval of tasks in the Amadeus application.

This class handles saving tasks to a file and loading tasks from a file, ensuring data persistence across application sessions. It supports three types of tasks: ToDo, Deadline, and Event.

  • Field Details

    • FILE_PATH

      public static final String 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

      public static void save(ArrayList<Task> tasks) throws AmadeusException
      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 by FILE_PATH.

      Parameters:
      tasks - the list of tasks to save; must not be null.
      Throws:
      AmadeusException - if an error occurs while saving tasks to the file.
    • parseSave

      public static Task parseSave(String line) throws AmadeusException
      Parses a line from the file into a Task object.

      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 be null.
      Returns:
      the Task object corresponding to the line.
      Throws:
      AmadeusException - if the line is invalid or cannot be parsed.
    • load

      public static ArrayList<Task> load() throws AmadeusException
      Loads tasks from the file and returns them as a list of Task objects.

      If the file does not exist, an empty list is returned. If the file exists, each line is parsed into a Task object using the parseSave(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.