Package it.tidalwave.util
Class ConcurrentHashMapWithOptionals<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.concurrent.ConcurrentHashMap<K,V>
it.tidalwave.util.ConcurrentHashMapWithOptionals<K,V>
- Type Parameters:
K
- the type of the keyV
- the type of the value
- All Implemented Interfaces:
Serializable
,ConcurrentMap<K,
,V> Map<K,
V>
A specialisation of
ConcurrentHashMap
with Optional
support.- Since:
- 3.1-ALPHA-2
- Author:
- Fabrizio Giudici
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap
ConcurrentHashMap.KeySetView<K,
V> Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionputIfAbsentAndGetNewKey
(Optional<? extends K> optionalKey, V value) If the map doesn't contain the given key, put the new pair(key, value), and return the key itself.putIfAbsentAndGetNewKey
(K key, V value) If the map doesn't contain the given key, put the new pair(key, value), and return the key itself.Methods inherited from class java.util.concurrent.ConcurrentHashMap
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, values
Methods inherited from class java.util.AbstractMap
clone
-
Constructor Details
-
ConcurrentHashMapWithOptionals
public ConcurrentHashMapWithOptionals()
-
-
Method Details
-
putIfAbsentAndGetNewKey
@Nonnull public Optional<K> putIfAbsentAndGetNewKey(@Nonnull Optional<? extends K> optionalKey, @Nonnull V value) If the map doesn't contain the given key, put the new pair(key, value), and return the key itself. Otherwise, do nothing and return an emptyOptional
. The map manipulation is atomically performed by callingConcurrentHashMap.putIfAbsent(java.lang.Object, java.lang.Object)
. IfoptionalKey
is empty, do nothing and return nothing.- Parameters:
optionalKey
- the keyvalue
- the value- Returns:
- the new key, or nothing
-
putIfAbsentAndGetNewKey
If the map doesn't contain the given key, put the new pair(key, value), and return the key itself. Otherwise, do nothing and return an emptyOptional
. The map manipulation is atomically performed by callingConcurrentHashMap.putIfAbsent(java.lang.Object, java.lang.Object)
.- Parameters:
key
- the keyvalue
- the value- Returns:
- the new key, or nothing
-