Interface ResizableAssociation<K,V>

Type Parameters:
K - type of the keys in the ResizableAssociation
V - type of the values in the ResizableAssociation
All Superinterfaces:
Association<K,V>, Assortment<Association.Entry<K,V>>, Countable, EditableAssociation<K,V>, Enumerable<Association.Entry<K,V>>, Iterable<Association.Entry<K,V>>

public interface ResizableAssociation<K,V> extends EditableAssociation<K,V>
Defines and resizable Association that accepts adding a removing entries
  • Method Details

    • putValue

      void putValue(K key, V value)
      add a new entry with the gven key and value
      Parameters:
      key - the key
      value - the value
    • clear

      void clear()
      Removes all entries
    • removeKey

      Maybe<V> removeKey(K key)
      Removes the key and the associated value. If the key or the value are not present Maybe.none is returned.
      Parameters:
      key - the key of the entry to remove
      Returns:
      the corresponding value present before removing
    • computeValueIfAbsent

      V computeValueIfAbsent(K key, Function<K,V> computation)
      If the value is found return it. If not, compute a value from the given key. The computed value is permanently associated with the key. The next call will find the value associated with the key.
      Specified by:
      computeValueIfAbsent in interface Association<K,V>
      Parameters:
      key - the key to find
      computation - the computations to define the value for the key
      Returns:
      the associated value
    • unionWith

      default void unionWith(Association<K,V> other, BiFunction<V,V,V> valueSelector)
      Adds all entries in other to this. If the key is already present the valueSelector method is called with the original value and the new, to decide which remains.
      Parameters:
      other - the other Association
      valueSelector - the function to select between values
    • intersectWith

      default void intersectWith(Association<K,V> other, BiFunction<V,V,V> valueSelector)
      Removes all entries and retains only the ones common to other and this. A valueSelector method is called with the original value and the new, to decide which remains.
      Parameters:
      other - the other Association
      valueSelector - the function to select between values
    • computeValue

      void computeValue(K key, V defaultValue, BiFunction<K,V,V> computation)
      Recomputed the value of a given key delegation to a given computation. If the key is not present, the defaultValue is used in the computation
      Parameters:
      key - the value key
      defaultValue - the value to use then the key is not found
      computation - a function that receives the key, the old value and returns the new value