Package javatro.storage
Class Storage
java.lang.Object
javatro.storage.Storage
The
Storage class serves as a facade to interact with the underlying storage mechanism
managed by StorageManager. It provides methods for saving, loading, and updating game
data runs. This class uses the Singleton pattern.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic BooleanIndicates if a new deck is being used.static booleanStores whether storage is active for the game or not -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new run to the storage with default values.intRetrieves the total number of runs stored.intRetrieves the currently selected run index.Retrieves a deep copy of the serialized run data.static StorageRetrieves the singleton instance ofStorage.getValue(int runNumber, int idx) Retrieves a specific value from a run.voidsetRunChosen(int runChosen) Sets the currently selected run index.voidsetSerializedRunData(TreeMap<Integer, ArrayList<String>> serializedRunData) Sets the serialized run data by delegating to theStorageManager.voidSets a specific value for a given run and saves it.voidUpdates the save file by delegating to theStorageManager.
-
Field Details
-
isNewDeck
Indicates if a new deck is being used. -
saveActive
public static boolean saveActiveStores whether storage is active for the game or not
-
-
Method Details
-
getStorageInstance
Retrieves the singleton instance ofStorage.- Returns:
- The singleton instance of
Storage.
-
updateSaveFile
Updates the save file by delegating to theStorageManager.- Throws:
JavatroException- If an error occurs during saving.
-
getSerializedRunData
Retrieves a deep copy of the serialized run data.- Returns:
- A
TreeMapcontaining all serialized run data.
-
setSerializedRunData
Sets the serialized run data by delegating to theStorageManager.- Parameters:
serializedRunData- The run data to be set.
-
addNewRun
public void addNewRun()Adds a new run to the storage with default values. -
getNumberOfRuns
public int getNumberOfRuns()Retrieves the total number of runs stored.- Returns:
- The total number of runs.
-
getValue
Retrieves a specific value from a run.- Parameters:
runNumber- The run number.idx- The index of the value to retrieve.- Returns:
- The value as a
String.
-
setValue
Sets a specific value for a given run and saves it.- Parameters:
runNumber- The run number.idx- The index of the value to set.value- The value to be set.
-
getRunChosen
public int getRunChosen()Retrieves the currently selected run index.- Returns:
- The index of the current run.
-
setRunChosen
public void setRunChosen(int runChosen) Sets the currently selected run index.- Parameters:
runChosen- The run index to set.
-