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 key
V - the type of the value
All Implemented Interfaces:
Serializable, ConcurrentMap<K,V>, Map<K,V>

public class ConcurrentHashMapWithOptionals<K,V> extends ConcurrentHashMap<K,V>
A specialisation of ConcurrentHashMap with Optional support.
Since:
3.1-ALPHA-2
Author:
Fabrizio Giudici
See Also:
  • 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 empty Optional. The map manipulation is atomically performed by calling ConcurrentHashMap.putIfAbsent(java.lang.Object, java.lang.Object). If optionalKey is empty, do nothing and return nothing.
      Parameters:
      optionalKey - the key
      value - the value
      Returns:
      the new key, or nothing
    • putIfAbsentAndGetNewKey

      @Nonnull public Optional<K> putIfAbsentAndGetNewKey(@Nonnull K key, @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 empty Optional. The map manipulation is atomically performed by calling ConcurrentHashMap.putIfAbsent(java.lang.Object, java.lang.Object).
      Parameters:
      key - the key
      value - the value
      Returns:
      the new key, or nothing