Package me.wyne.wutils.storage
Interface Storage
- All Known Implementing Classes:
JsonStorage
public interface Storage
-
Method Summary
Modifier and TypeMethodDescription<KeyType,ValType, ColType extends Collection<ValType>>
booleanclearCollection(@NotNull Map<KeyType, ColType> data, KeyType key, @NotNull String path) ClearCollectionin dataMapand in storageFile in given path.<KeyType,MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>>
booleanvoidCreate storage file.voidcreateStorageFolder(@NotNull File folderPath) Create folder for storage file.<KeyType,ValType>
ValTypeGet element from dataMap.<KeyType,ValType>
@NotNull Collection<ValType>getCollection(@NotNull Map<KeyType, ? extends Collection<ValType>> data, KeyType key) GetCollectionfrom dataMap.voidloadData()Load data from storage file.@Nullable ThrowableImplementation of loading data from storage file.<KeyType,ValType>
booleanRemove element from dataMapand from storageFile from given path.<KeyType,ValType, ColType extends Collection<ValType>>
booleanremoveCollection(@NotNull Map<KeyType, ColType> data, KeyType key, ValType value, @NotNull String path) Remove element fromCollectionin dataMapand from storageFile from given path.<KeyType,MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>>
booleanremoveMap(@NotNull Map<KeyType, MapType> data, KeyType key, MapKeyType mapKey, @Nullable String path) <KeyType,ValType>
voidSave element to dataMapand to storageFile to given path.<KeyType,ValType, ColType extends Collection<ValType>>
booleansaveCollection(@NotNull Map<KeyType, ColType> data, KeyType key, ValType value, @NotNull String path) Save element toCollectionin dataMapand to storageFile to given path.<KeyType,MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>>
void
-
Method Details
-
createStorageFolder
Create folder for storage file. -
createStorageFile
void createStorageFile()Create storage file. -
loadData
void loadData()Load data from storage file. UsesloadDataImpl(), puts it in other thread and logs. -
loadDataImpl
Implementation of loading data from storage file.loadData()will take care of logging and putting implementation in other thread.- Returns:
Throwableif data loading caused exception
-
get
@Nullable <KeyType,ValType> ValType get(@NotNull @NotNull Map<KeyType, ValType> data, @NotNull KeyType key) Get element from dataMap. May be used to add extra logic to data query. Map is used because data is often stored as key:value. -
getCollection
@NotNull <KeyType,ValType> @NotNull Collection<ValType> getCollection(@NotNull @NotNull Map<KeyType, ? extends Collection<ValType>> data, @NotNull KeyType key) GetCollectionfrom dataMap. May be used to add extra logic to data query. Map is used because data is often stored as key:value.- Type Parameters:
KeyType- DataMapkey typeValType-Collectionvalue type- Parameters:
data- DataMapto getCollectionfromkey- DataMapkey to getCollectionfrom- Returns:
Collectionfrom dataMapor empty set
-
save
<KeyType,ValType> void save(@Nullable @Nullable Map<KeyType, ValType> data, @NotNull KeyType key, @NotNull ValType value, @Nullable @Nullable String path) Save element to dataMapand 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
<KeyType,ValType, boolean saveCollectionColType extends Collection<ValType>> (@NotNull @NotNull Map<KeyType, ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path) Save element toCollectionin dataMapand to storageFile to given path.- Type Parameters:
KeyType- DataMapkey typeValType-Collectionvalue typeColType- Type ofCollection- Parameters:
data- DataMapto saveCollectiontokey- DataMapkey toCollectionto save element tovalue- Value to savepath- Path toJsonArrayin storageFile to save element to- Returns:
- True/False if save succeed/failed
-
saveMap
<KeyType,MapKeyType, void saveMapValType, MapType extends Map<MapKeyType, ValType>> (@NotNull @NotNull Map<KeyType, MapType> data, @NotNull KeyType key, @NotNull MapKeyType mapKey, @NotNull ValType value, @Nullable @Nullable String path) - Type Parameters:
KeyType- DataMapkey typeMapKeyType- InnerMapkey typeValType- InnerMapvalue typeMapType- Type of innerMap- Parameters:
data- DataMapto save innerMapelement tokey- DataMapkey to innerMapto save element tomapKey- InnerMapkey to save element tovalue- Value to savepath- Path to innerMapelement in storageFile to save element to
-
remove
<KeyType,ValType> boolean remove(@Nullable @Nullable Map<KeyType, ValType> data, @NotNull KeyType key, @Nullable @Nullable String path) Remove element from dataMapand 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. -
removeCollection
<KeyType,ValType, boolean removeCollectionColType extends Collection<ValType>> (@NotNull @NotNull Map<KeyType, ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path) Remove element fromCollectionin dataMapand from storageFile from given path.- Type Parameters:
KeyType- DataMapkey typeValType-Collectionvalue typeColType- Type ofCollection- Parameters:
data- DataMapto removeCollectionelement fromkey- DataMapkey toCollectionto remove element fromvalue- Value to removepath- Path toJsonArrayin storageFile to remove element from- Returns:
- True/False if remove succeed/failed
-
removeMap
<KeyType,MapKeyType, boolean removeMapValType, MapType extends Map<MapKeyType, ValType>> (@NotNull @NotNull Map<KeyType, MapType> data, @NotNull KeyType key, @NotNull MapKeyType mapKey, @Nullable @Nullable String path) Remove element from innerMapin dataMapand from storageFile from given path.
Set path as null to remove element by mapKey- Type Parameters:
KeyType- DataMapkey typeMapKeyType- InnerMapkey typeValType- InnerMapvalue typeMapType- Type of innerMap- Parameters:
data- DataMapto remove innerMapelement fromkey- DataMapkey to innerMapto remove element frommapKey- InnerMapkey to removepath- Path to innerMapelement in storageFile to remove- Returns:
- True/False if remove succeed/failed
-
clearCollection
<KeyType,ValType, boolean clearCollectionColType extends Collection<ValType>> (@NotNull @NotNull Map<KeyType, ColType> data, @NotNull KeyType key, @NotNull @NotNull String path) ClearCollectionin dataMapand in storageFile in given path.- Type Parameters:
KeyType- DataMapkey typeValType-Collectionvalue typeColType- Type ofCollection- Parameters:
data- DataMapto clearCollectionfromkey- DataMapkey toCollectionto clearpath- Path toJsonArrayin storageFile to clear- Returns:
- True/False if clear succeed/failed
-
clearMap
<KeyType,MapKeyType, boolean clearMapValType, MapType extends Map<MapKeyType, ValType>> (@NotNull @NotNull Map<KeyType, MapType> data, @NotNull KeyType key, @NotNull @NotNull Class<MapKeyType> mapKeyType) - Type Parameters:
KeyType- DataMapkey typeMapKeyType- InnerMapkey typeValType- InnerMapvalue typeMapType- Type of innerMap- Parameters:
data- DataMapto clear innerMapfromkey- DataMapkey to innerMapto clearmapKeyType- InnerMapkey type- Returns:
- True/False if clear succeed/failed
-