K
- identifier (key)-typeV
- value-typepublic class MapCreate<K,V> extends Object
Internally it uses a HashMap
for it's implementation, and the K
and V
types must obey the rules for a HashMap
(with valid equals, hashcode etc.)
This structure is not inherently thread-safe.
Constructor and Description |
---|
MapCreate(java.util.function.Supplier<V> createNewElement)
Creates without a comparator, using a
HashMap internally. |
MapCreate(java.util.function.Supplier<V> createNewElement,
Comparator<K> comparator)
Creates with an explicit comparator, and using a
TreeMap internally. |
Modifier and Type | Method and Description |
---|---|
V |
computeIfAbsent(K key)
Gets an existing element from the map, newly creating and storing the element if it's absent.
|
Set<Map.Entry<K,V>> |
entrySet()
The entries in the map.
|
V |
get(K key)
Gets an existing element from the map, returning null if it is absent.
|
boolean |
isEmpty()
Whether the map is empty or not.
|
<E extends Exception> |
iterateEntries(CheckedBiConsumer<K,V,E> operation)
Iterate over each entry in the map, and apply an operation.
|
Set<K> |
keySet()
The keys in the map.
|
void |
remove(K key,
V value)
Removes the entry for the specified key only if it is currently mapped to the specified
value.
|
public MapCreate(java.util.function.Supplier<V> createNewElement)
HashMap
internally.createNewElement
- called as necessary to create a new element in the tree.public MapCreate(java.util.function.Supplier<V> createNewElement, Comparator<K> comparator)
TreeMap
internally.createNewElement
- called as necessary to create a new element in the tree.comparator
- used to impose an ordering on elements.public V get(K key)
key
- the key for the map query.public V computeIfAbsent(K key)
key
- the key for the map query.public void remove(K key, V value)
key
- the key to remove.value
- the value to remove.public Set<Map.Entry<K,V>> entrySet()
public Set<K> keySet()
public boolean isEmpty()
public <E extends Exception> void iterateEntries(CheckedBiConsumer<K,V,E> operation) throws E extends Exception
E
- an exception that may be thrown by {code operation}.operation
- the operation applied to each element in the map, passing the key and value
as parameters.E
- if operation
throws it.E extends Exception
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.