Class Storage

java.lang.Object
dev.prozilla.pine.core.storage.Storage
All Implemented Interfaces:
Destructible, Initializable, Printable, Transceivable<Storage>, Transmittable<Storage>
Direct Known Subclasses:
LocalStorage, SessionStorage

public abstract class Storage extends Object implements Initializable, Destructible, Transceivable<Storage>, Printable
A key-value store that uses strings for keys and values.
  • Field Details

    • items

      protected final Map<String,String> items
      The items in this store.
    • application

      protected final Application application
    • config

      protected final StorageConfig config
    • isInitialized

      protected boolean isInitialized
  • Constructor Details

    • Storage

      public Storage(Application application)
      Creates a new key-value store.
  • Method Details

    • init

      public void init()
      Loads items into this store.
      Specified by:
      init in interface Initializable
    • destroy

      public void destroy()
      Saves the items from this store and clears the memory.
      Specified by:
      destroy in interface Destructible
    • overwrite

      public void overwrite(Storage source)
      Overwrites the items in this store with the items from another store.
      Parameters:
      source - The store to read the items from
    • transmit

      public void transmit(Storage target)
      Copies the items of this store to another store.
      Specified by:
      transmit in interface Transceivable<Storage>
      Specified by:
      transmit in interface Transmittable<Storage>
      Parameters:
      target - The store to copy the items to
    • self

      public Storage self()
      Specified by:
      self in interface Transceivable<Storage>
    • hasItem

      public boolean hasItem(String key)
      Checks if this store has an item with a given key.
      Parameters:
      key - The key of the item
      Returns:
      true if an item exists in this store with the given key.
    • getVector2f

      public Vector2f getVector2f(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getVector2i

      public Vector2i getVector2i(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getVector3f

      public Vector3f getVector3f(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getVector3i

      public Vector3i getVector3i(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getVector4f

      public Vector4f getVector4f(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getVector4i

      public Vector4i getVector4i(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getDimension

      public DimensionBase getDimension(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getDualDimension

      public DualDimension getDualDimension(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getColor

      public Color getColor(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
      See Also:
    • getItem

      public <T> T getItem(String key, Parser<T> parser)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      parser - The parser to use
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
    • getItem

      public <T> T getItem(String key, ParseFunction<T> parseFunction)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      parseFunction - The parsing function to use
      Returns:
      The parsed value of the item, or null if the item does not exist or the parsing failed.
    • getInt

      public int getInt(String key) throws NumberFormatException
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or 0 if the item does not exist.
      Throws:
      NumberFormatException - If the parsing failed.
      See Also:
    • getFloat

      public float getFloat(String key) throws NumberFormatException
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or 0 if the item does not exist.
      Throws:
      NumberFormatException - If the parsing failed.
      See Also:
    • getBoolean

      public boolean getBoolean(String key)
      Returns the value of the item in this store with a given key by parsing it.
      Parameters:
      key - The key of the item
      Returns:
      The parsed value of the item, or false if the item does not exist.
      See Also:
    • getItem

      public String getItem(String key)
      Returns the value of the item in this store with a given key.
      Parameters:
      key - The key of the item
      Returns:
      The value of the item, or null if the item does not exist.
    • setItems

      public <O> boolean setItems(Map<String,O> items)
      Sets the values of multiple items.
      Parameters:
      items - The key and value pairs
      Returns:
      true if an item was changed.
    • setItems

      protected <O> boolean setItems(Set<Map.Entry<String,O>> items)
      Sets the values of multiple items.
      Parameters:
      items - The key and value pairs
      Returns:
      true if an item was changed.
    • setItem

      public boolean setItem(String key, Object value)
      Sets the value of the item with a given key to the string representation of an object.
      Parameters:
      key - The key of the item
      value - The new value
      Returns:
      true if the item was changed.
      See Also:
    • setItem

      public boolean setItem(String key, String value)
      Sets the value of the item with a given key.
      Parameters:
      key - The key of the item
      value - The new value
      Returns:
      true if the item was changed.
    • removeItem

      public boolean removeItem(String key)
      Removes the item with a given key.
      Parameters:
      key - The key of the item
      Returns:
      false if there was no item with the given key.
    • removeAll

      public void removeAll()
      Removes all items from this store.
    • clear

      public void clear()
      Removes all items from this store that are currently in memory.
    • size

      public int size()
      Returns the amount of items in this store.
      Returns:
      The amount of items in this store.
    • items

      public Set<Map.Entry<String,String>> items()
      Returns the items in this store.
      Returns:
      The items in this store.
    • keys

      public Set<String> keys()
      Returns the keys of the items in this store.
      Returns:
      The keys in this store.
    • values

      public Collection<String> values()
      Returns the values of the items in this store.
      Returns:
      The values in this store.
    • shouldLoad

      protected boolean shouldLoad()
    • shouldSave

      protected boolean shouldSave()
    • load

      protected abstract void load()
      Loads items into this store.
    • save

      protected abstract void save()
      Saves the items from this store.
    • print

      public void print()
      Description copied from interface: Printable
      Prints this object using the system logger then terminates the line.
      Specified by:
      print in interface Printable
    • getLogger

      protected Logger getLogger()
    • toString

      @NotNull public @NotNull String toString()
      Description copied from interface: Printable
      Returns a string representation of this object.
      Specified by:
      toString in interface Printable
      Overrides:
      toString in class Object
      Returns:
      String representation of this object.