Class AbstractValueStorage<K,V>

java.lang.Object
ru.progrm_jarvis.javacommons.object.valuestorage.AbstractValueStorage<K,V>
Type Parameters:
K - type of keys used for identifying values
V - type of stored values
All Implemented Interfaces:
ValueStorage<K,V>
Direct Known Subclasses:
SimpleValueStorage

public abstract class AbstractValueStorage<K,V> extends Object implements ValueStorage<K,V>
Abstract base for ValueStorage.
  • Field Details

    • values

      @NonNull protected final @NonNull Map<K,V> values
      Values stored by their unique keys
  • Constructor Details

    • AbstractValueStorage

      public AbstractValueStorage(@NonNull @NonNull Map<K,V> values)
  • Method Details

    • generateNewKey

      protected abstract K generateNewKey()
      Generates a new key for storing the unique value.
      Returns:
      newly generated unique key
    • storeValue

      public K storeValue(@NonNull V value)
      Description copied from interface: ValueStorage
      Stores the given non-null value returning its unique key.
      Specified by:
      storeValue in interface ValueStorage<K,V>
      Parameters:
      value - non-null value to store
      Returns:
      unique key by which the stored value may be retrieved
    • retrieveValue

      public V retrieveValue(K key)
      Description copied from interface: ValueStorage
      Retrieves (gets and removes) the value stored by the given key.
      Specified by:
      retrieveValue in interface ValueStorage<K,V>
      Parameters:
      key - unique key by which the value should be found
      Returns:
      value which was stored by the given key or null if there was no value stored
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object