Class ConcurrentMutableHashMap<K,V>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<V>, ConcurrentMap<K,V>, Map<K,V>, InternalIterable<V>, ConcurrentMutableMap<K,V>, MapIterable<K,V>, MutableMap<K,V>, MutableMapIterable<K,V>, UnsortedMapIterable<K,V>, RichIterable<V>

@Deprecated public final class ConcurrentMutableHashMap<K,V> extends AbstractMutableMap<K,V> implements ConcurrentMutableMap<K,V>, Serializable
Deprecated.
since 2.0
A simple concurrent implementation of MutableMap which uses java.util.concurrent.ConcurrentHashMap for its underlying concurrent Map implementation.
See Also:
  • Constructor Details

    • ConcurrentMutableHashMap

      public ConcurrentMutableHashMap(ConcurrentMap<K,V> delegate)
      Deprecated.
  • Method Details

    • newMap

      public static <NK, NV> ConcurrentMutableHashMap<NK,NV> newMap()
      Deprecated.
    • newMap

      public static <NK, NV> ConcurrentMutableHashMap<NK,NV> newMap(int initialCapacity)
      Deprecated.
    • newMap

      public static <NK, NV> ConcurrentMutableHashMap<NK,NV> newMap(int initialCapacity, float loadFactor, int concurrencyLevel)
      Deprecated.
    • newMap

      public static <NK, NV> ConcurrentMutableHashMap<NK,NV> newMap(Map<NK,NV> map)
      Deprecated.
    • withKeyValue

      public ConcurrentMutableHashMap<K,V> withKeyValue(K key, V value)
      Deprecated.
      Description copied from interface: MutableMapIterable
      This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus the additional key and value. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:
       map = map.withKeyValue("new key", "new value");
       
      In the case of FixedSizeMap, a new instance will be returned by withKeyValue, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.
      Specified by:
      withKeyValue in interface MutableMap<K,V>
      Specified by:
      withKeyValue in interface MutableMapIterable<K,V>
      Overrides:
      withKeyValue in class AbstractMutableMap<K,V>
      See Also:
    • withAllKeyValues

      public ConcurrentMutableHashMap<K,V> withAllKeyValues(Iterable<? extends Pair<? extends K,? extends V>> keyValues)
      Deprecated.
      Description copied from interface: MutableMapIterable
      This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus all the additional keys and values. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:
       map = map.withAllKeyValues(FastList.newListWith(PairImpl.of("new key", "new value")));
       
      In the case of FixedSizeMap, a new instance will be returned by withAllKeyValues, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.
      Specified by:
      withAllKeyValues in interface MutableMap<K,V>
      Specified by:
      withAllKeyValues in interface MutableMapIterable<K,V>
      Overrides:
      withAllKeyValues in class AbstractMutableMap<K,V>
      See Also:
    • withAllKeyValueArguments

      public ConcurrentMutableHashMap<K,V> withAllKeyValueArguments(Pair<? extends K,? extends V>... keyValues)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Convenience var-args version of withAllKeyValues
      Specified by:
      withAllKeyValueArguments in interface MutableMap<K,V>
      Specified by:
      withAllKeyValueArguments in interface MutableMapIterable<K,V>
      Overrides:
      withAllKeyValueArguments in class AbstractMutableMap<K,V>
      See Also:
    • withoutKey

      public ConcurrentMutableHashMap<K,V> withoutKey(K key)
      Deprecated.
      Description copied from interface: MutableMapIterable
      This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus the key and value to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:
       map = map.withoutKey("key");
       
      In the case of FixedSizeMap, a new instance will be returned by withoutKey, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.
      Specified by:
      withoutKey in interface MutableMap<K,V>
      Specified by:
      withoutKey in interface MutableMapIterable<K,V>
      Overrides:
      withoutKey in class AbstractMutableMap<K,V>
      See Also:
    • withoutAllKeys

      public ConcurrentMutableHashMap<K,V> withoutAllKeys(Iterable<? extends K> keys)
      Deprecated.
      Description copied from interface: MutableMapIterable
      This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus all the keys and values to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:
       map = map.withoutAllKeys(FastList.newListWith("key1", "key2"));
       
      In the case of FixedSizeMap, a new instance will be returned by withoutAllKeys, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.
      Specified by:
      withoutAllKeys in interface MutableMap<K,V>
      Specified by:
      withoutAllKeys in interface MutableMapIterable<K,V>
      Overrides:
      withoutAllKeys in class AbstractMutableMap<K,V>
      See Also:
    • toString

      public String toString()
      Deprecated.
      Description copied from class: AbstractRichIterable
      Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.
       Assert.assertEquals("[]", Lists.mutable.empty().toString());
       Assert.assertEquals("[1]", Lists.mutable.with(1).toString());
       Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
       
      Specified by:
      toString in interface MapIterable<K,V>
      Specified by:
      toString in interface RichIterable<K>
      Overrides:
      toString in class AbstractRichIterable<V>
      Returns:
      a string representation of this collection.
      See Also:
    • clone

      public MutableMap<K,V> clone()
      Deprecated.
      Specified by:
      clone in interface MutableMap<K,V>
      Specified by:
      clone in class AbstractMutableMap<K,V>
    • newEmpty

      public <K, V> MutableMap<K,V> newEmpty(int capacity)
      Deprecated.
      Description copied from class: AbstractMutableMap
      Creates a new instance of the same type, using the given capacity and the default growth parameters.
      Specified by:
      newEmpty in class AbstractMutableMap<K,V>
    • notEmpty

      public boolean notEmpty()
      Deprecated.
      Description copied from interface: RichIterable
      The English equivalent of !this.isEmpty()
      Specified by:
      notEmpty in interface RichIterable<K>
    • forEachWithIndex

      public void forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
      Deprecated.
      Description copied from interface: InternalIterable
      Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

      Example using a Java 8 lambda:

       people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
       

      Example using an anonymous inner class:

       people.forEachWithIndex(new ObjectIntProcedure<Person>()
       {
           public void value(Person person, int index)
           {
               LOGGER.info("Index: " + index + " person: " + person.getName());
           }
       });
       
      Specified by:
      forEachWithIndex in interface InternalIterable<K>
      Overrides:
      forEachWithIndex in class AbstractMapIterable<K,V>
    • size

      public int size()
      Deprecated.
      Description copied from interface: RichIterable
      Returns the number of items in this iterable.
      Specified by:
      size in interface Map<K,V>
      Specified by:
      size in interface RichIterable<K>
    • isEmpty

      public boolean isEmpty()
      Deprecated.
      Description copied from interface: RichIterable
      Returns true if this iterable has zero items.
      Specified by:
      isEmpty in interface Map<K,V>
      Specified by:
      isEmpty in interface RichIterable<K>
      Overrides:
      isEmpty in class AbstractRichIterable<V>
    • iterator

      public Iterator<V> iterator()
      Deprecated.
      Specified by:
      iterator in interface Iterable<K>
      Overrides:
      iterator in class AbstractMutableMapIterable<K,V>
    • remove

      public V remove(Object key)
      Deprecated.
      Specified by:
      remove in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Deprecated.
      Specified by:
      keySet in interface Map<K,V>
    • values

      public Collection<V> values()
      Deprecated.
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Deprecated.
      Specified by:
      entrySet in interface Map<K,V>
    • clear

      public void clear()
      Deprecated.
      Specified by:
      clear in interface Map<K,V>
    • newEmpty

      public MutableMap<K,V> newEmpty()
      Deprecated.
      Description copied from interface: MutableMapIterable
      Creates a new instance of the same type, using the default capacity and growth parameters.
      Specified by:
      newEmpty in interface MutableMap<K,V>
      Specified by:
      newEmpty in interface MutableMapIterable<K,V>
    • tap

      public ConcurrentMutableMap<K,V> tap(Procedure<? super V> procedure)
      Deprecated.
      Description copied from interface: MapIterable
      Executes the Procedure for each value of the map and returns this.
       return peopleByCity.tap(person -> LOGGER.info(person.getName()));
       
      Specified by:
      tap in interface ConcurrentMutableMap<K,V>
      Specified by:
      tap in interface MapIterable<K,V>
      Specified by:
      tap in interface MutableMap<K,V>
      Specified by:
      tap in interface MutableMapIterable<K,V>
      Specified by:
      tap in interface RichIterable<K>
      Specified by:
      tap in interface UnsortedMapIterable<K,V>
      Overrides:
      tap in class AbstractMutableMap<K,V>
      See Also:
    • forEachValue

      public void forEachValue(Procedure<? super V> procedure)
      Deprecated.
      Description copied from interface: MapIterable
      Calls the procedure with each value of the map.
           Set<String> result = UnifiedSet.newSet();
           MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
           map.forEachValue(new CollectionAddProcedure<String>(result));
           Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
       
      Specified by:
      forEachValue in interface MapIterable<K,V>
      Overrides:
      forEachValue in class AbstractMapIterable<K,V>
    • forEachKey

      public void forEachKey(Procedure<? super K> procedure)
      Deprecated.
      Description copied from interface: MapIterable
      Calls the procedure with each key of the map.
           final Collection<Integer> result = new ArrayList<Integer>();
           MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
           map.forEachKey(new CollectionAddProcedure<Integer>(result));
           Verify.assertContainsAll(result, 1, 2, 3);
       
      Specified by:
      forEachKey in interface MapIterable<K,V>
      Overrides:
      forEachKey in class AbstractMapIterable<K,V>
    • forEachKeyValue

      public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
      Deprecated.
      Description copied from interface: MapIterable
      Calls the procedure with each key-value pair of the map.
           final Collection<String> collection = new ArrayList<String>();
           MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
           map.forEachKeyValue((Integer key, String value) -> collection.add(String.valueOf(key) + value));
           Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
       
      Specified by:
      forEachKeyValue in interface MapIterable<K,V>
    • get

      public V get(Object key)
      Deprecated.
      Specified by:
      get in interface Map<K,V>
      Specified by:
      get in interface MapIterable<K,V>
      See Also:
    • put

      public V put(K key, V value)
      Deprecated.
      Specified by:
      put in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> map)
      Deprecated.
      Specified by:
      putAll in interface Map<K,V>
    • collectKeysAndValues

      public <E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)
      Deprecated.
      Description copied from interface: MutableMap
      Adds all the entries derived from iterable to this. The key and value for each entry is determined by applying the keyFunction and valueFunction to each item in collection. Any entry in map that has the same key as an entry in this will have its value replaced by that in map.
      Specified by:
      collectKeysAndValues in interface MutableMap<K,V>
    • removeKey

      public V removeKey(K key)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Remove an entry from the map at the specified key.
      Specified by:
      removeKey in interface MutableMapIterable<K,V>
      Returns:
      The value removed from entry at key, or null if not found.
      See Also:
    • containsKey

      public boolean containsKey(Object key)
      Deprecated.
      Specified by:
      containsKey in interface Map<K,V>
      Specified by:
      containsKey in interface MapIterable<K,V>
      See Also:
    • containsValue

      public boolean containsValue(Object value)
      Deprecated.
      Specified by:
      containsValue in interface Map<K,V>
      Specified by:
      containsValue in interface MapIterable<K,V>
      See Also:
    • getIfAbsentPut

      public V getIfAbsentPut(K key, Function0<? extends V> function)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the result of evaluating the specified Function0, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPut in interface MutableMapIterable<K,V>
      Overrides:
      getIfAbsentPut in class AbstractMutableMapIterable<K,V>
    • getIfAbsentPut

      public V getIfAbsentPut(K key, V value)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the specified value, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPut in interface MutableMapIterable<K,V>
      Overrides:
      getIfAbsentPut in class AbstractMutableMapIterable<K,V>
    • getIfAbsentPutWith

      public <P> V getIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key return the result of evaluating the specified Function using the specified parameter, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPutWith in interface MutableMapIterable<K,V>
      Overrides:
      getIfAbsentPutWith in class AbstractMutableMapIterable<K,V>
    • getIfAbsent

      public V getIfAbsent(K key, Function0<? extends V> function)
      Deprecated.
      Description copied from interface: MapIterable
      Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified Function0.
      Specified by:
      getIfAbsent in interface MapIterable<K,V>
      Overrides:
      getIfAbsent in class AbstractMapIterable<K,V>
    • getIfAbsentValue

      public V getIfAbsentValue(K key, V value)
      Deprecated.
      Description copied from interface: MapIterable
      Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return value.
      Specified by:
      getIfAbsentValue in interface MapIterable<K,V>
      Overrides:
      getIfAbsentValue in class AbstractMapIterable<K,V>
    • getIfAbsentWith

      public <P> V getIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)
      Deprecated.
      Description copied from interface: MapIterable
      Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified function and parameter.
      Specified by:
      getIfAbsentWith in interface MapIterable<K,V>
      Overrides:
      getIfAbsentWith in class AbstractMapIterable<K,V>
    • getIfAbsentPut

      public V getIfAbsentPut(K key, Function<? super K,? extends V> factory)
      Deprecated.
    • ifPresentApply

      public <A> A ifPresentApply(K key, Function<? super V,? extends A> function)
      Deprecated.
      Description copied from interface: MapIterable
      If there is a value in the Map that corresponds to the specified key return the result of applying the specified Function on the value, otherwise return null.
      Specified by:
      ifPresentApply in interface MapIterable<K,V>
      Overrides:
      ifPresentApply in class AbstractMapIterable<K,V>
    • equals

      public boolean equals(Object o)
      Deprecated.
      Description copied from interface: MapIterable
      Follows the same general contract as Map.equals(Object).
      Specified by:
      equals in interface Map<K,V>
      Specified by:
      equals in interface MapIterable<K,V>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Deprecated.
      Description copied from interface: MapIterable
      Follows the same general contract as Map.hashCode().
      Specified by:
      hashCode in interface Map<K,V>
      Specified by:
      hashCode in interface MapIterable<K,V>
      Overrides:
      hashCode in class Object
    • forEachWith

      public <P> void forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
      Deprecated.
      Description copied from interface: InternalIterable
      The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

      Example using a Java 8 lambda:

       people.forEachWith((Person person, Person other) ->
           {
               if (person.isRelatedTo(other))
               {
                    LOGGER.info(person.getName());
               }
           }, fred);
       

      Example using an anonymous inner class:

       people.forEachWith(new Procedure2<Person, Person>()
       {
           public void value(Person person, Person other)
           {
               if (person.isRelatedTo(other))
               {
                    LOGGER.info(person.getName());
               }
           }
       }, fred);
       
      Specified by:
      forEachWith in interface InternalIterable<K>
      Overrides:
      forEachWith in class AbstractMapIterable<K,V>
    • putIfAbsent

      public V putIfAbsent(K key, V value)
      Deprecated.
      Specified by:
      putIfAbsent in interface ConcurrentMap<K,V>
      Specified by:
      putIfAbsent in interface Map<K,V>
    • remove

      public boolean remove(Object key, Object value)
      Deprecated.
      Specified by:
      remove in interface ConcurrentMap<K,V>
      Specified by:
      remove in interface Map<K,V>
    • replace

      public boolean replace(K key, V oldValue, V newValue)
      Deprecated.
      Specified by:
      replace in interface ConcurrentMap<K,V>
      Specified by:
      replace in interface Map<K,V>
    • replace

      public V replace(K key, V value)
      Deprecated.
      Specified by:
      replace in interface ConcurrentMap<K,V>
      Specified by:
      replace in interface Map<K,V>
    • updateValue

      public V updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Looks up the value associated with key, applies the function to it, and replaces the value. If there is no value associated with key, starts it off with a value supplied by factory.
      Specified by:
      updateValue in interface MutableMapIterable<K,V>
      Overrides:
      updateValue in class AbstractMutableMapIterable<K,V>
    • updateValueWith

      public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
      Deprecated.
      Description copied from interface: MutableMapIterable
      Same as MutableMapIterable.updateValue(Object, Function0, Function) with a Function2 and specified parameter which is passed to the function.
      Specified by:
      updateValueWith in interface MutableMapIterable<K,V>
      Overrides:
      updateValueWith in class AbstractMutableMapIterable<K,V>
    • toImmutable

      public ImmutableMap<K,V> toImmutable()
      Deprecated.
      Description copied from interface: MutableMapIterable
      Returns an immutable copy of this map. If the map is immutable, it returns itself.
      Specified by:
      toImmutable in interface MapIterable<K,V>
      Specified by:
      toImmutable in interface MutableMapIterable<K,V>
      Specified by:
      toImmutable in interface UnsortedMapIterable<K,V>
      Overrides:
      toImmutable in class AbstractMutableMap<K,V>