Liking cljdoc? Tell your friends :D

jdk.util.concurrent.ConcurrentMap

A Map providing thread safety and atomicity guarantees.

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a ConcurrentMap as a key or value happen-before actions subsequent to the access or removal of that object from the ConcurrentMap in another thread.

This interface is a member of the

Java Collections Framework.

A Map providing thread safety and atomicity
guarantees.

Memory consistency effects: As with other concurrent
collections, actions in a thread prior to placing an object into a
ConcurrentMap as a key or value
happen-before
actions subsequent to the access or removal of that object from
the ConcurrentMap in another thread.

This interface is a member of the

Java Collections Framework.
raw docstring

computeclj

(compute this key remapping-function)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). For example, to either create or append a String msg to a value mapping:

map.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg)) (Method merge() is often simpler to use for such purposes.)

If the function returns null, the mapping is removed (or remains absent if initially absent). If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

key - key with which the specified value is to be associated - K remapping-function - the function to compute a value - java.util.function.BiFunction

returns: the new value associated with the specified key, or null if none - default V

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)

Attempts to compute a mapping for the specified key and its current
 mapped value (or null if there is no current mapping). For
 example, to either create or append a String msg to a value
 mapping:



 map.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))
 (Method merge() is often simpler to use for such purposes.)

 If the function returns null, the mapping is removed (or
 remains absent if initially absent).  If the function itself throws an
 (unchecked) exception, the exception is rethrown, and the current mapping
 is left unchanged.

key - key with which the specified value is to be associated - `K`
remapping-function - the function to compute a value - `java.util.function.BiFunction`

returns: the new value associated with the specified key, or null if none - `default V`

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)
raw docstring

compute-if-absentclj

(compute-if-absent this key mapping-function)

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.

If the function returns null no mapping is recorded. If the function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded. The most common usage is to construct a new object serving as an initial mapped value or memoized result, as in:

map.computeIfAbsent(key, k -> new Value(f(k)));

Or to implement a multi-value map, Map<K,Collection<V>>, supporting multiple values per key:

map.computeIfAbsent(key, k -> new HashSet<V>()).add(v);

key - key with which the specified value is to be associated - K mapping-function - the function to compute a value - java.util.function.Function

returns: the current (existing or computed) value associated with the specified key, or null if the computed value is null - default V

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)

If the specified key is not already associated with a value (or is mapped
 to null), attempts to compute its value using the given mapping
 function and enters it into this map unless null.

 If the function returns null no mapping is recorded. If
 the function itself throws an (unchecked) exception, the
 exception is rethrown, and no mapping is recorded.  The most
 common usage is to construct a new object serving as an initial
 mapped value or memoized result, as in:



 map.computeIfAbsent(key, k -> new Value(f(k)));

 Or to implement a multi-value map, Map<K,Collection<V>>,
 supporting multiple values per key:



 map.computeIfAbsent(key, k -> new HashSet<V>()).add(v);

key - key with which the specified value is to be associated - `K`
mapping-function - the function to compute a value - `java.util.function.Function`

returns: the current (existing or computed) value associated with
         the specified key, or null if the computed value is null - `default V`

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)
raw docstring

compute-if-presentclj

(compute-if-present this key remapping-function)

If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.

If the function returns null, the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

key - key with which the specified value is to be associated - K remapping-function - the function to compute a value - java.util.function.BiFunction

returns: the new value associated with the specified key, or null if none - default V

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)

If the value for the specified key is present and non-null, attempts to
 compute a new mapping given the key and its current mapped value.

 If the function returns null, the mapping is removed.  If the
 function itself throws an (unchecked) exception, the exception is
 rethrown, and the current mapping is left unchanged.

key - key with which the specified value is to be associated - `K`
remapping-function - the function to compute a value - `java.util.function.BiFunction`

returns: the new value associated with the specified key, or null if none - `default V`

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)
raw docstring

for-eachclj

(for-each this action)

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of entry set iteration (if an iteration order is specified.) Exceptions thrown by the action are relayed to the caller.

action - The action to be performed for each entry - java.util.function.BiConsumer

returns: default void

throws: java.lang.NullPointerException - if the specified action is null

Performs the given action for each entry in this map until all entries
 have been processed or the action throws an exception.   Unless
 otherwise specified by the implementing class, actions are performed in
 the order of entry set iteration (if an iteration order is specified.)
 Exceptions thrown by the action are relayed to the caller.

action - The action to be performed for each entry - `java.util.function.BiConsumer`

returns: `default void`

throws: java.lang.NullPointerException - if the specified action is null
raw docstring

get-or-defaultclj

(get-or-default this key default-value)

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

key - the key whose associated value is to be returned - java.lang.Object default-value - the default mapping of the key - V

returns: the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key - default V

throws: java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional)

Returns the value to which the specified key is mapped, or
 defaultValue if this map contains no mapping for the key.

key - the key whose associated value is to be returned - `java.lang.Object`
default-value - the default mapping of the key - `V`

returns: the value to which the specified key is mapped, or
 defaultValue if this map contains no mapping for the key - `default V`

throws: java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional)
raw docstring

mergeclj

(merge this key value remapping-function)

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. This method may be of use when combining multiple mapped values for a key. For example, to either create or append a String msg to a value mapping:

map.merge(key, msg, String::concat)

If the function returns null the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

key - key with which the resulting value is to be associated - K value - the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key - V remapping-function - the function to recompute a value if present - java.util.function.BiFunction

returns: the new value associated with the specified key, or null if no value is associated with the key - default V

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)

If the specified key is not already associated with a value or is
 associated with null, associates it with the given non-null value.
 Otherwise, replaces the associated value with the results of the given
 remapping function, or removes if the result is null. This
 method may be of use when combining multiple mapped values for a key.
 For example, to either create or append a String msg to a
 value mapping:



 map.merge(key, msg, String::concat)

 If the function returns null the mapping is removed.  If the
 function itself throws an (unchecked) exception, the exception is
 rethrown, and the current mapping is left unchanged.

key - key with which the resulting value is to be associated - `K`
value - the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key - `V`
remapping-function - the function to recompute a value if present - `java.util.function.BiFunction`

returns: the new value associated with the specified key, or null if no
         value is associated with the key - `default V`

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map (optional)
raw docstring

put-if-absentclj

(put-if-absent this key value)

If the specified key is not already associated with a value, associate it with the given value. This is equivalent to

if (!map.containsKey(key)) return map.put(key, value); else return map.get(key);

except that the action is performed atomically.

key - key with which the specified value is to be associated - K value - value to be associated with the specified key - V

returns: the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.) - V

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map

If the specified key is not already associated
 with a value, associate it with the given value.
 This is equivalent to


 if (!map.containsKey(key))
   return map.put(key, value);
 else
   return map.get(key);

 except that the action is performed atomically.

key - key with which the specified value is to be associated - `K`
value - value to be associated with the specified key - `V`

returns: the previous value associated with the specified key, or
         null if there was no mapping for the key.
         (A null return can also indicate that the map
         previously associated null with the key,
         if the implementation supports null values.) - `V`

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map
raw docstring

removeclj

(remove this key value)

Removes the entry for a key only if currently mapped to a given value. This is equivalent to

if (map.containsKey(key) && Objects.equals(map.get(key), value)) { map.remove(key); return true; } else return false;

except that the action is performed atomically.

key - key with which the specified value is associated - java.lang.Object value - value expected to be associated with the specified key - java.lang.Object

returns: true if the value was removed - boolean

throws: java.lang.UnsupportedOperationException - if the remove operation is not supported by this map

Removes the entry for a key only if currently mapped to a given value.
 This is equivalent to


 if (map.containsKey(key) && Objects.equals(map.get(key), value)) {
   map.remove(key);
   return true;
 } else
   return false;

 except that the action is performed atomically.

key - key with which the specified value is associated - `java.lang.Object`
value - value expected to be associated with the specified key - `java.lang.Object`

returns: true if the value was removed - `boolean`

throws: java.lang.UnsupportedOperationException - if the remove operation is not supported by this map
raw docstring

replaceclj

(replace this key value)
(replace this key old-value new-value)

Replaces the entry for a key only if currently mapped to a given value. This is equivalent to

if (map.containsKey(key) && Objects.equals(map.get(key), oldValue)) { map.put(key, newValue); return true; } else return false;

except that the action is performed atomically.

key - key with which the specified value is associated - K old-value - value expected to be associated with the specified key - V new-value - value to be associated with the specified key - V

returns: true if the value was replaced - boolean

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map

Replaces the entry for a key only if currently mapped to a given value.
 This is equivalent to


 if (map.containsKey(key) && Objects.equals(map.get(key), oldValue)) {
   map.put(key, newValue);
   return true;
 } else
   return false;

 except that the action is performed atomically.

key - key with which the specified value is associated - `K`
old-value - value expected to be associated with the specified key - `V`
new-value - value to be associated with the specified key - `V`

returns: true if the value was replaced - `boolean`

throws: java.lang.UnsupportedOperationException - if the put operation is not supported by this map
raw docstring

replace-allclj

(replace-all this function)

Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception. Exceptions thrown by the function are relayed to the caller.

function - the function to apply to each entry - java.util.function.BiFunction

returns: default void

throws: java.lang.UnsupportedOperationException - if the set operation is not supported by this map's entry set iterator.

Replaces each entry's value with the result of invoking the given
 function on that entry until all entries have been processed or the
 function throws an exception.  Exceptions thrown by the function are
 relayed to the caller.

function - the function to apply to each entry - `java.util.function.BiFunction`

returns: `default void`

throws: java.lang.UnsupportedOperationException - if the set operation is not supported by this map's entry set iterator.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close