Interface Storage

All Known Implementing Classes:
JsonStorage

public interface Storage
  • 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 from HashMap. May be used to add extra logic to data query. HashMap is used because data is often stored as key:value.
      Type Parameters:
      KeyType - Data HashMap key type
      ValType - Data HashMap value type
      Parameters:
      data - HashMap to get element from
      key - HashMap key to get element from
      Returns:
      Element of Storage from data or null
    • getCollection

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

      <KeyType, ValType> boolean remove(@Nullable @Nullable HashMap<KeyType,ValType> data, @NotNull KeyType key, @Nullable @Nullable String path)
      Remove element from data HashMap 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 HashMap key type
      ValType - Data HashMap value type
      Parameters:
      data - HashMap to remove element from
      key - HashMap 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 HashMap<KeyType,ColType> data, @NotNull KeyType key, @NotNull ValType value, @NotNull @NotNull String path)
      Remove element from Collection in data HashMap and from storageFile from given path.
      Type Parameters:
      KeyType - Data HashMap key type
      ValType - Collection value type
      ColType - Type of Collection
      Parameters:
      data - HashMap to remove Collection element from
      key - HashMap 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
    • clearCollection

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