Class MapContainer<K,V>
- Type Parameters:
K- Key type.V- Value type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class com.marcusslover.plus.lib.container.AbstractContainer
DEFAULT_GSON, parentFolder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanLocally(K key) Cleans the object from the cache.booleancontainsKeyLocally(K key) Checks if object with the given key is loaded in the cache.booleancontainsValueLocally(V value) Checks if the object is loaded in the cache.protected abstract VemptyValue(K key) Creates a new instance of an object.getCache()Gets all the loaded keys from the cache.@NotNull Collection<V> Gets all the loaded objects from the cache.voidLoads all the objects from the files.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.Reads the object from the file.Reads the object from the file.retrieveLocally(K key) Retrieves the object from the cache.voidsaveData()Saves all the objects from the cache to the file.voidUnloads an object from the cache and saves it to the file.voidstoreLocally(K key, V value) Puts the object in the cache.voidPush the updated object to the cache and save it to the file.voidWrites the object to the file.Methods inherited from class com.marcusslover.plus.lib.container.AbstractContainer
getGson
-
Field Details
-
TRANSFORMER
-
COMPOSER
-
cache
-
keyTransformer
-
keyComposer
-
valueType
-
-
Constructor Details
-
MapContainer
public MapContainer()
-
-
Method Details
-
emptyValue
Creates a new instance of an object.This function is called when the object with the given key does not exist and has to be created for the first time.
- Parameters:
key- The key of the object.- Returns:
- The object.
-
onValueLoaded
Called when a new object gets loaded.This function is mainly called when
storeLocally(K, 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(K)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<K>- Parameters:
key- Key of the object.
-
loadData
Loads an object from the file. The key is the name of the file.- Parameters:
key- Key to the object.- Returns:
- The object.
-
loadAllData
public void loadAllData()Loads all the objects from the files. Called during start of the plugin, only when the container is annotated withInitialLoading.- Specified by:
loadAllDatain classAbstractContainer<K>
-
saveData
Unloads an object from the cache and saves it to the file.- Parameters:
key- Key to the object.
-
saveData
public void saveData()Saves all the objects from the cache to the file. Should be called when the plugin is disabled. -
containsKeyLocally
Checks if object with the given key is loaded in the cache.- Parameters:
key- Key to the object.- Returns:
- True if the object is loaded, false otherwise.
-
containsValueLocally
Checks if the object is loaded in the cache.The check does not include any files, only the cache!
- Parameters:
value- Object to check.- Returns:
- True if the object is loaded, false otherwise.
-
cleanLocally
Cleans the object from the cache.This function does not write the object to the file.
- Parameters:
key- Key to the object.
-
storeLocally
Puts the object in the cache.This function only puts the object in the cache. It doesn't save the object to the file -> Use
update(K)for that orwriteData(K, V).- Parameters:
key- Key to the object.value- Object to put.
-
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(K)instead.- Parameters:
key- Key to the object.- 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(Object)will be used.- Parameters:
key- Key to the object.- Returns:
- The object.
-
read
Reads the object from the file.This is an internal (raw) function -> Use
readData(Object)instead.- Parameters:
fileName- Name of the file.- Returns:
- The object.
-
writeData
Writes the object 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:
key- Key to the object.value- Object to write.
-
getValues
Gets all the loaded objects from the cache.- Returns:
- All the loaded objects.
-
getCache
Gets all the loaded keys from the cache.- Returns:
- All the loaded keys and their objects.
-