Package me.wyne.wutils.storage
Class JsonStorage
java.lang.Object
me.wyne.wutils.storage.JsonStorage
- All Implemented Interfaces:
Storage
Requires
com.google.gson dependency.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.gson.Gsonprotected final ExecutorServiceprotected final org.bukkit.plugin.Pluginprotected final File -
Constructor Summary
ConstructorsConstructorDescriptionJsonStorage(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull File storageFile) -
Method Summary
Modifier and TypeMethodDescription<KeyType,ValType, ColType extends Collection<ValType>>
booleanclearCollection(@NotNull HashMap<KeyType, ColType> data, KeyType key, @NotNull String path) ClearCollectionin dataHashMapand in storageFile in given path.voidCreate storage file.voidCreate folder for storage file.<KeyType,ValType>
ValTypeGet element fromHashMap.<KeyType,ValType>
@NotNull Collection<ValType>getCollection(@NotNull HashMap<KeyType, ? extends Collection<ValType>> data, KeyType key) GetCollectionfromHashMap.<KeyType,ValType>
booleanRemove element from dataHashMapand from storageFile from given path.<KeyType,ValType, ColType extends Collection<ValType>>
booleanremoveCollection(@NotNull HashMap<KeyType, ColType> data, KeyType key, ValType value, @NotNull String path) Remove element fromCollectionin dataHashMapand from storageFile from given path.<KeyType,ValType>
voidSave element to dataHashMapand to storageFile to given path.<KeyType,ValType, ColType extends Collection<ValType>>
booleansaveCollection(@NotNull HashMap<KeyType, ColType> data, KeyType key, ValType value, @NotNull String path) Save element toCollectionin dataHashMapand to storageFile to given path.
-
Field Details
-
plugin
protected final org.bukkit.plugin.Plugin plugin -
gson
protected final com.google.gson.Gson gson -
storageFile
-
jsonExecutorService
-
-
Constructor Details
-
JsonStorage
public JsonStorage(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull File storageFile)
-
-
Method Details
-
createStorageFolder
public void createStorageFolder()Description copied from interface:StorageCreate folder for storage file.- Specified by:
createStorageFolderin interfaceStorage
-
createStorageFile
public void createStorageFile()Description copied from interface:StorageCreate storage file.- Specified by:
createStorageFilein interfaceStorage
-
get
@Nullable public <KeyType,ValType> ValType get(@NotNull @NotNull HashMap<KeyType, ValType> data, @NotNull KeyType key) Get element fromHashMap. If HashMap doesn't have given key it will return null. HashMap is used because data is often stored as key:value. -
getCollection
@NotNull public <KeyType,ValType> @NotNull Collection<ValType> getCollection(@NotNull @NotNull HashMap<KeyType, ? extends Collection<ValType>> data, @NotNull KeyType key) GetCollectionfromHashMap. If HashMap doesn't have given key or retrievedCollectionis empty it will return null. HashMap is used because data is often stored as key:value.- Specified by:
getCollectionin interfaceStorage- Type Parameters:
KeyType- DataHashMapkey typeValType-Collectionvalue type- Parameters:
data-HashMapto getCollectionfromkey-HashMapkey to getCollectionfrom- Returns:
Collectionfrom data or null
-
save
public <KeyType,ValType> void save(@Nullable @Nullable HashMap<KeyType, ValType> data, @NotNull KeyType key, @NotNull ValType value, @Nullable @Nullable String path) Description copied from interface:StorageSave element to dataHashMapand to storageFile to given path.
Set path as null to save value directly to key in storageFile.
Set data as null to save value only to storageFile. -
saveCollection
public <KeyType,ValType, boolean saveCollectionColType extends Collection<ValType>> (@NotNull @NotNull HashMap<KeyType, ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path) Description copied from interface:StorageSave element toCollectionin dataHashMapand to storageFile to given path.- Specified by:
saveCollectionin interfaceStorage- Type Parameters:
KeyType- DataHashMapkey typeValType-Collectionvalue typeColType- Type ofCollection- Parameters:
data-HashMapto saveCollectiontokey-HashMapkey toCollectionto save element tovalue- Value to savepath- Path toJsonArrayin storageFile to save element to- Returns:
- True/False if save succeed/failed
-
remove
public <KeyType,ValType> boolean remove(@Nullable @Nullable HashMap<KeyType, ValType> data, @NotNull KeyType key, @Nullable @Nullable String path) Description copied from interface:StorageRemove element from dataHashMapand from storageFile from given path.
Set path as null to remove whole key from storageFile.
Set data as null to remove value only from storageFile.- Specified by:
removein interfaceStorage- Type Parameters:
KeyType- DataHashMapkey typeValType- DataHashMapvalue type- Parameters:
data-HashMapto remove element fromkey-HashMapkey to remove element frompath- Path in storageFile to remove element from- Returns:
- True/False if remove succeed/failed
-
removeCollection
public <KeyType,ValType, boolean removeCollectionColType extends Collection<ValType>> (@NotNull @NotNull HashMap<KeyType, ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path) Description copied from interface:StorageRemove element fromCollectionin dataHashMapand from storageFile from given path.- Specified by:
removeCollectionin interfaceStorage- Type Parameters:
KeyType- DataHashMapkey typeValType-Collectionvalue typeColType- Type ofCollection- Parameters:
data-HashMapto removeCollectionelement fromkey-HashMapkey toCollectionto remove element fromvalue- Value to removepath- Path toJsonArrayin storageFile to remove element from- Returns:
- True/False if remove succeed/failed
-
clearCollection
public <KeyType,ValType, boolean clearCollectionColType extends Collection<ValType>> (@NotNull @NotNull HashMap<KeyType, ColType> data, @NotNull KeyType key, @NotNull @NotNull String path) Description copied from interface:StorageClearCollectionin dataHashMapand in storageFile in given path.- Specified by:
clearCollectionin interfaceStorage- Type Parameters:
KeyType- DataHashMapkey typeValType-Collectionvalue typeColType- Type ofCollection- Parameters:
data-HashMapto clearCollectionfromkey-HashMapkey toCollectionto clearpath- Path toJsonArrayin storageFile to clear- Returns:
- True/False if clear succeed/failed
-