Class SingleContainer<V>
java.lang.Object
com.marcusslover.plus.lib.container.AbstractContainer<V>
com.marcusslover.plus.lib.container.type.SingleContainer<V>
- Type Parameters:
V- Value type.
Container that represents a single object.
The object is serialized to a single json file.
The file name is final and can be changed in the constructor.
-
Field Summary
FieldsFields inherited from class com.marcusslover.plus.lib.container.AbstractContainer
DEFAULT_GSON, parentFolder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCleans the local cache.protected abstract VCreates a new instance of an object.voidAttempts to load all the data from the container.loadData()Loads an object from the file.protected voidonValueLoaded(V value) Called when a new object gets loaded.protected voidonValueUnloaded(V value) Called when an object gets unloaded.readData()Reads the object from the file.Retrieves the object from the cache.voidsaveData()Unloads the data from the cache and saves it to the file.voidstoreLocally(V value) Stores locally the data.voidPush the updated object to the cache and save it to the file.voidWrites the data to the file.Methods inherited from class com.marcusslover.plus.lib.container.AbstractContainer
getGson
-
Field Details
-
valueType
-
fileName
-
cache
-
-
Constructor Details
-
SingleContainer
public SingleContainer()
-
-
Method Details
-
emptyValue
Creates a new instance of an object.This function is called when the object does not exist and has to be created for the first time.
- Returns:
- The object.
-
onValueLoaded
Called when a new object gets loaded.This function is mainly called when
storeLocally(V)is called.- Parameters:
value- The object that was most recently loaded.
-
onValueUnloaded
Called when an object gets unloaded.This function is mainly called when
cleanLocally()} is called.- Parameters:
value- The object that was most recently unloaded.
-
update
Description copied from class:AbstractContainerPush the updated object to the cache and save it to the file.- Specified by:
updatein classAbstractContainer<V>- Parameters:
value- Key of the object.
-
loadData
Loads an object from the file.- Returns:
- The object.
-
loadAllData
public void loadAllData()Description copied from class:AbstractContainerAttempts to load all the data from the container. Look atInitialLoadingfor more information.- Specified by:
loadAllDatain classAbstractContainer<V>
-
saveData
public void saveData()Unloads the data from the cache and saves it to the file. -
cleanLocally
public void cleanLocally()Cleans the local cache.This function does not delete the file.
-
storeLocally
Stores locally the data.This function does not write the data to the file.
- Parameters:
value- The value to store.
-
retrieveLocally
Retrieves the object from the cache.This function will not attempt to load the object from the file, if it is not loaded -> Use
loadData()instead.- Returns:
- The object or null if it is not loaded.
-
readData
Reads the object from the file.If the file doesn't exist, it will create a new one. Default value created by
emptyValue()will be used.- Returns:
- The object.
-
writeData
Writes the data to the file.This function does not unload anything from the cache. The cache is not affected by this function. If you want to delete the file, set the value to null!
- Parameters:
value- Object to write.
-