public class LimitedHashMap<K,V>
extends java.util.HashMap<K,V>
LimitedHashMap is a HashMap which limits its content based on the function removeElement.
removeElement determines whether the map limit is reached. If it returns an empty value, the map behaves as usual.
Otherwise, the returned key is removed from the map.| Modifier and Type | Field and Description |
|---|---|
protected TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> |
removeElement |
| Constructor and Description |
|---|
LimitedHashMap(int initialCapacity,
TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement)
Create an empty limited map with reserved initial capacity.
|
LimitedHashMap(java.util.Map<? extends K,? extends V> m,
TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement)
Create a limited map from another map and a tripredicate.
|
LimitedHashMap(TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement)
Create an empty limited hash map.
|
| Modifier and Type | Method and Description |
|---|---|
V |
compute(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction) |
V |
computeIfAbsent(K key,
java.util.function.Function<? super K,? extends V> mappingFunction) |
V |
merge(K key,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction) |
V |
put(K key,
V value) |
void |
putAll(java.util.Map<? extends K,? extends V> m) |
V |
putIfAbsent(K key,
V value) |
clear, clone, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, remove, remove, replace, replace, replaceAll, size, valuesprotected TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement
public LimitedHashMap(TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement)
removeElement - determines whether the map limit is reached
if it returns an empty value, the map behaves as usual
otherwise, the returned key is removed from the mappublic LimitedHashMap(int initialCapacity,
TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement)
initialCapacity - the initial capacity of the hash tableremoveElement - determines whether the map limit is reached
if it returns an empty value, the map behaves as usual
otherwise, the returned key is removed from the mappublic LimitedHashMap(java.util.Map<? extends K,? extends V> m, TriFunction<LimitedHashMap<K,V>,K,V,java.util.Optional<K>> removeElement)
m - map which elements are used for initializationremoveElement - determines whether the map limit is reached
if it returns an empty value, the map behaves as usual
otherwise, the returned key is removed from the mappublic V computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction)
public V compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)