Interface Storage

All Known Implementing Classes:
JsonStorage

public interface Storage
  • Method Summary

    Modifier and Type
    Method
    Description
    <KeyType, ValType, ColType extends Collection<ValType>>
    boolean
    clearCollection(@NotNull Map<KeyType,ColType> data, KeyType key, @NotNull String path)
    Clear Collection in data Map and in storageFile in given path.
    <KeyType, MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>>
    boolean
    clearMap(@NotNull Map<KeyType,MapType> data, KeyType key, @NotNull Class<MapKeyType> mapKeyType)
    Clear inner Map in data Map and in storageFile.
    void
    Create storage file.
    void
    Create folder for storage file.
    <KeyType, ValType>
    ValType
    get(@NotNull Map<KeyType,ValType> data, KeyType key)
    Get element from data Map.
    <KeyType, ValType>
    @NotNull Collection<ValType>
    getCollection(@NotNull Map<KeyType,? extends Collection<ValType>> data, KeyType key)
    Get Collection from data Map.
    void
    Load data from storage file.
    <KeyType, ValType>
    boolean
    remove(@Nullable Map<KeyType,ValType> data, KeyType key, @Nullable String path)
    Remove element from data Map and from storageFile from given path.
    <KeyType, ValType, ColType extends Collection<ValType>>
    boolean
    removeCollection(@NotNull Map<KeyType,ColType> data, KeyType key, ValType value, @NotNull String path)
    Remove element from Collection in data Map and from storageFile from given path.
    <KeyType, MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>>
    boolean
    removeMap(@NotNull Map<KeyType,MapType> data, KeyType key, MapKeyType mapKey, @Nullable String path)
    Remove element from inner Map in data Map and from storageFile from given path.
    <KeyType, ValType>
    void
    save(@Nullable Map<KeyType,ValType> data, KeyType key, ValType value, @Nullable String path)
    Save element to data Map and to storageFile to given path.
    <KeyType, ValType, ColType extends Collection<ValType>>
    boolean
    saveCollection(@NotNull Map<KeyType,ColType> data, KeyType key, ValType value, @NotNull String path)
    Save element to Collection in data Map and to storageFile to given path.
    <KeyType, MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>>
    void
    saveMap(@NotNull Map<KeyType,MapType> data, KeyType key, MapKeyType mapKey, ValType value, @Nullable String path)
    Save element to inner Map in data Map and 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 Map<KeyType,ValType> data, @NotNull KeyType key)
      Get element from data Map. May be used to add extra logic to data query. Map is used because data is often stored as key:value.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Data Map value type
      Parameters:
      data - Data Map to get element from
      key - Data Map key to get element from
      Returns:
      Element of Storage from data Map or null
    • getCollection

      @NotNull <KeyType, ValType> @NotNull Collection<ValType> getCollection(@NotNull @NotNull Map<KeyType,? extends Collection<ValType>> data, @NotNull KeyType key)
      Get Collection from data Map. May be used to add extra logic to data query. Map is used because data is often stored as key:value.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Collection value type
      Parameters:
      data - Data Map to get Collection from
      key - Data Map key to get Collection from
      Returns:
      Collection from data Map or 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 data Map and 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.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Data Map value type
      Parameters:
      data - Data Map to save element to
      key - Data Map key to save element to
      value - Value to save
      path - Path in storageFile to save element to
    • saveCollection

      <KeyType, ValType, ColType extends Collection<ValType>> boolean saveCollection(@NotNull @NotNull Map<KeyType,ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path)
      Save element to Collection in data Map and to storageFile to given path.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Collection value type
      ColType - Type of Collection
      Parameters:
      data - Data Map to save Collection to
      key - Data Map key to Collection to save element to
      value - Value to save
      path - Path to JsonArray in storageFile to save element to
      Returns:
      True/False if save succeed/failed
    • saveMap

      <KeyType, MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>> void saveMap(@NotNull @NotNull Map<KeyType,MapType> data, @NotNull KeyType key, @NotNull MapKeyType mapKey, @NotNull ValType value, @Nullable @Nullable String path)
      Save element to inner Map in data Map and to storageFile to given path.
      Type Parameters:
      KeyType - Data Map key type
      MapKeyType - Inner Map key type
      ValType - Inner Map value type
      MapType - Type of inner Map
      Parameters:
      data - Data Map to save inner Map element to
      key - Data Map key to inner Map to save element to
      mapKey - Inner Map key to save element to
      value - Value to save
      path - Path to inner Map element 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 data Map and 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.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Data Map value type
      Parameters:
      data - Data Map to remove element from
      key - Data Map key to remove element from
      path - Path in storageFile to remove element from
      Returns:
      True/False if remove succeed/failed
    • removeCollection

      <KeyType, ValType, ColType extends Collection<ValType>> boolean removeCollection(@NotNull @NotNull Map<KeyType,ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path)
      Remove element from Collection in data Map and from storageFile from given path.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Collection value type
      ColType - Type of Collection
      Parameters:
      data - Data Map to remove Collection element from
      key - Data Map key to Collection to remove element from
      value - Value to remove
      path - Path to JsonArray in storageFile to remove element from
      Returns:
      True/False if remove succeed/failed
    • removeMap

      <KeyType, MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>> boolean removeMap(@NotNull @NotNull Map<KeyType,MapType> data, @NotNull KeyType key, @NotNull MapKeyType mapKey, @Nullable @Nullable String path)
      Remove element from inner Map in data Map and from storageFile from given path.
      Set path as null to remove element by mapKey
      Type Parameters:
      KeyType - Data Map key type
      MapKeyType - Inner Map key type
      ValType - Inner Map value type
      MapType - Type of inner Map
      Parameters:
      data - Data Map to remove inner Map element from
      key - Data Map key to inner Map to remove element from
      mapKey - Inner Map key to remove
      path - Path to inner Map element in storageFile to remove
      Returns:
      True/False if remove succeed/failed
    • clearCollection

      <KeyType, ValType, ColType extends Collection<ValType>> boolean clearCollection(@NotNull @NotNull Map<KeyType,ColType> data, @NotNull KeyType key, @NotNull @NotNull String path)
      Clear Collection in data Map and in storageFile in given path.
      Type Parameters:
      KeyType - Data Map key type
      ValType - Collection value type
      ColType - Type of Collection
      Parameters:
      data - Data Map to clear Collection from
      key - Data Map key to Collection to clear
      path - Path to JsonArray in storageFile to clear
      Returns:
      True/False if clear succeed/failed
    • clearMap

      <KeyType, MapKeyType, ValType, MapType extends Map<MapKeyType, ValType>> boolean clearMap(@NotNull @NotNull Map<KeyType,MapType> data, @NotNull KeyType key, @NotNull @NotNull Class<MapKeyType> mapKeyType)
      Clear inner Map in data Map and in storageFile.
      Type Parameters:
      KeyType - Data Map key type
      MapKeyType - Inner Map key type
      ValType - Inner Map value type
      MapType - Type of inner Map
      Parameters:
      data - Data Map to clear inner Map from
      key - Data Map key to inner Map to clear
      mapKeyType - Inner Map key type
      Returns:
      True/False if clear succeed/failed