K
- key typeV
- value typepublic abstract class KeyInValueMap<K,V> extends Object implements Iterable<V>
Does not support null keys or values. Not thread safe.
Constructor and Description |
---|
KeyInValueMap(int initialCapacity,
float loadFactor)
Create a new map.
|
Modifier and Type | Method and Description |
---|---|
protected abstract V |
computeValue(K key)
This method must be overridden in subclasses so that values can be computed for missing keys.
|
V |
get(K key,
boolean computeIfAbsent)
Get the value for a key and optionally compute a new value if it is not already present in
the map.
|
protected abstract K |
getKey(V value)
Get the key for a value.
|
protected int |
hashKey(K key)
Calculate the hash for a key.
|
Iterator<V> |
iterator() |
int |
size() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public KeyInValueMap(int initialCapacity, float loadFactor)
initialCapacity
- initial storage capacityloadFactor
- load factor at which to increase the internal storage capacitypublic V get(K key, boolean computeIfAbsent)
computeValue(Object)
which must be
implemented by subclasses.key
- keycomputeIfAbsent
- If a value is not found and this is set to true
, then compute and add a
new value using computeValue(Object)
.false
and no matching value
exists, then null
is returned.public int size()
protected abstract V computeValue(K key)
get(Object, boolean)
when the requested key is missing in the map.key
- key to calculate value forprotected int hashKey(K key)
key
- key to calculate hash forCopyright © 2019. All rights reserved.