Package org.midheaven.collections
Interface ResizableAssociation<K,V>
- Type Parameters:
K- type of the keys in the ResizableAssociationV- 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>>
Defines and resizable
Association that accepts adding a removing entries-
Nested Class Summary
Nested classes/interfaces inherited from interface org.midheaven.collections.Association
Association.Entry<K,V> -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entriesvoidcomputeValue(K key, V defaultValue, BiFunction<K, V, V> computation) Recomputed the value of a given key delegation to a givencomputation.computeValueIfAbsent(K key, Function<K, V> computation) If the value is found return it.default voidintersectWith(Association<K, V> other, BiFunction<V, V, V> valueSelector) Removes all entries and retains only the ones common tootherandthis.voidadd a new entry with the gven key and valueRemoves the key and the associated value.default voidunionWith(Association<K, V> other, BiFunction<V, V, V> valueSelector) Adds all entries inothertothis.Methods inherited from interface org.midheaven.collections.Association
containsKey, containsValue, getValue, intersection, keys, toCollection, union, valuesMethods inherited from interface org.midheaven.collections.Assortment
contains, containsAll, count, isEmptyMethods inherited from interface org.midheaven.collections.EditableAssociation
computeValue, setValue, toUnmodifiableMethods inherited from interface org.midheaven.collections.Enumerable
allMatch, any, anyMatch, as, associate, associate, cast, collect, concat, distinct, enumerator, filter, first, flatMap, groupBy, iterator, limit, map, maximum, minimum, ofType, peek, reduce, reduce, skip, sorted, toArray, toArray, toArray, toDistinctAssortment, toSequence, toSequence, with, zipMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
putValue
add a new entry with the gven key and value- Parameters:
key- the keyvalue- the value
-
clear
void clear()Removes all entries -
removeKey
Removes the key and the associated value. If the key or the value are not presentMaybe.noneis returned.- Parameters:
key- the key of the entry to remove- Returns:
- the corresponding value present before removing
-
computeValueIfAbsent
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:
computeValueIfAbsentin interfaceAssociation<K,V> - Parameters:
key- the key to findcomputation- the computations to define the value for the key- Returns:
- the associated value
-
unionWith
Adds all entries inothertothis. 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 AssociationvalueSelector- the function to select between values
-
intersectWith
Removes all entries and retains only the ones common tootherandthis. A valueSelector method is called with the original value and the new, to decide which remains.- Parameters:
other- the other AssociationvalueSelector- the function to select between values
-
computeValue
Recomputed the value of a given key delegation to a givencomputation. If the key is not present, thedefaultValueis used in the computation- Parameters:
key- the value keydefaultValue- the value to use then the key is not foundcomputation- a function that receives the key, the old value and returns the new value
-