Package javatro.storage
Class StorageManager
java.lang.Object
javatro.storage.StorageManager
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 Summary
Modifier and TypeMethodDescriptionvoidCreates a new save file if it does not exist.voiddeleteRunData(int runNumber) Deletes the data associated with a specific run number.Retrieves all run data stored in memory.static StorageManagerReturns the single instance ofStorageManager.intReturns the number of runs stored in memory.getRunData(int runNumber) Retrieves the run data for a given run number.voidInitializes the save file by loading existing data or creating a new file if none exists.voidsaveRunData(int runNumber, ArrayList<String> runData) Saves a run's data in the storage map.voidsetSerializedRunData(TreeMap<Integer, ArrayList<String>> serializedRunData) Sets the entire serialized run data map.voidupdateNewRoundData(int runIndex, List<String> roundData) Updates round-specific data for a new round in the storage.voidupdateRoundData(int runIndex, List<String> roundData) voidUpdates the save file by writing the serialized run data to disk.
-
Method Details
-
getInstance
Returns the single instance ofStorageManager.- Returns:
- The singleton instance of
StorageManager.
-
saveRunData
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
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
Retrieves all run data stored in memory.- Returns:
- A
TreeMapcontaining 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
Sets the entire serialized run data map.- Parameters:
serializedRunData- TheTreeMapcontaining serialized run data.
-
createSaveFile
Creates a new save file if it does not exist.- Throws:
JavatroException- if the file cannot be created.
-
updateSaveFile
Updates the save file by writing the serialized run data to disk.- Throws:
JavatroException- if the file cannot be written.
-
initaliseSaveFile
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
-
updateNewRoundData
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)
-