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 HashMap<KeyType, ColType> data, KeyType key, 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.voidloadData()Load data from storage file.<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.
-
Method Details
-
createStorageFolder
void createStorageFolder()Create folder for storage file. -
createStorageFile
void createStorageFile()Create storage file. -
loadData
void loadData()Load data from storage file. -
get
@Nullable <KeyType,ValType> ValType get(@NotNull @NotNull HashMap<KeyType, ValType> data, @NotNull KeyType key) Get element fromHashMap. May be used to add extra logic to data query. HashMap is used because data is often stored as key:value. -
getCollection
@NotNull <KeyType,ValType> @NotNull Collection<ValType> getCollection(@NotNull @NotNull HashMap<KeyType, ? extends Collection<ValType>> data, @NotNull KeyType key) GetCollectionfromHashMap. May be used to add extra logic to data query. HashMap is used because data is often stored as key:value.- Type Parameters:
KeyType- DataHashMapkey typeValType-Collectionvalue type- Parameters:
data-HashMapto getCollectionfromkey-HashMapkey to getCollectionfrom- Returns:
Collectionfrom data or empty set
-
save
<KeyType,ValType> void save(@Nullable @Nullable HashMap<KeyType, ValType> data, @NotNull KeyType key, @NotNull ValType value, @Nullable @Nullable String path) Save 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
<KeyType,ValType, boolean saveCollectionColType extends Collection<ValType>> (@NotNull @NotNull HashMap<KeyType, ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path) Save element toCollectionin dataHashMapand to storageFile to given path.- 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
<KeyType,ValType> boolean remove(@Nullable @Nullable HashMap<KeyType, ValType> data, @NotNull KeyType key, @Nullable @Nullable String path) Remove 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. -
removeCollection
<KeyType,ValType, boolean removeCollectionColType extends Collection<ValType>> (@NotNull @NotNull HashMap<KeyType, ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path) Remove element fromCollectionin dataHashMapand from storageFile from given path.- 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
<KeyType,ValType, boolean clearCollectionColType extends Collection<ValType>> (@NotNull @NotNull HashMap<KeyType, ColType> data, @NotNull KeyType key, String path) ClearCollectionin dataHashMapand in storageFile in given path.- 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
-