Class StorageManager

java.lang.Object
javatro.storage.StorageManager

public class StorageManager extends Object
The StorageManager class is responsible for managing the storage of game data, including reading from and writing to a save file. This class handles the serialization and deserialization of game data.

This class follows the Singleton pattern to ensure only one instance of the manager exists throughout the application.

  • Method Details

    • getInstance

      public static StorageManager getInstance()
      Returns the single instance of StorageManager.
      Returns:
      The singleton instance of StorageManager.
    • saveRunData

      public void saveRunData(int runNumber, ArrayList<String> runData)
      Saves a run's data in the storage map.
      Parameters:
      runNumber - The run number serving as the key.
      runData - The run data to be saved.
    • getRunData

      public ArrayList<String> getRunData(int runNumber)
      Retrieves the run data for a given run number.
      Parameters:
      runNumber - The run number for which data is requested.
      Returns:
      The list of strings representing the run data.
    • getAllRunData

      public TreeMap<Integer,ArrayList<String>> getAllRunData()
      Retrieves all run data stored in memory.
      Returns:
      A TreeMap containing all serialized run data.
    • deleteRunData

      public void deleteRunData(int runNumber)
      Deletes the data associated with a specific run number.
      Parameters:
      runNumber - The run number whose data is to be deleted.
    • getNumberOfRuns

      public int getNumberOfRuns()
      Returns the number of runs stored in memory.
      Returns:
      The total number of runs.
    • setSerializedRunData

      public void setSerializedRunData(TreeMap<Integer,ArrayList<String>> serializedRunData)
      Sets the entire serialized run data map.
      Parameters:
      serializedRunData - The TreeMap containing serialized run data.
    • createSaveFile

      public void createSaveFile() throws JavatroException
      Creates a new save file if it does not exist.
      Throws:
      JavatroException - if the file cannot be created.
    • updateSaveFile

      public void updateSaveFile() throws JavatroException
      Updates the save file by writing the serialized run data to disk.
      Throws:
      JavatroException - if the file cannot be written.
    • initaliseSaveFile

      public void initaliseSaveFile() throws JavatroException
      Initializes the save file by loading existing data or creating a new file if none exists.
      Throws:
      JavatroException - if the file cannot be read or created.
    • updateRoundData

      public void updateRoundData(int runIndex, List<String> roundData)
    • updateNewRoundData

      public void updateNewRoundData(int runIndex, List<String> roundData)
      Updates round-specific data for a new round in the storage.
      Parameters:
      runIndex - The index of the current run being updated.
      roundData - A list containing the updated round data in the following order: - Remaining plays (HAND_INDEX) - Remaining discards (DISCARD_INDEX) - Current round score (ROUND_SCORE_INDEX)