K
- the type of keys maintained by this mapV
- the type of mapped valuesclass ConcurrentHashMapV8<K,V>
extends AbstractMap<K,V>
implements ConcurrentMap<K,V>, Serializable
Hashtable
, and
includes versions of methods corresponding to each method of
Hashtable
. However, even though all operations are
thread-safe, retrieval operations do not entail locking,
and there is not any support for locking the entire table
in a way that prevents all access. This class is fully
interoperable with Hashtable
in programs that rely on its
thread safety but not on its synchronization details.
Retrieval operations (including get
) generally do not
block, so may overlap with update operations (including put
and remove
). Retrievals reflect the results of the most
recently completed update operations holding upon their
onset. (More formally, an update operation for a given key bears a
happens-before relation with any (non-null) retrieval for
that key reporting the updated value.) For aggregate operations
such as putAll
and clear
, concurrent retrievals may
reflect insertion or removal of only some entries. Similarly,
Iterators and Enumerations return elements reflecting the state of
the hash table at some point at or since the creation of the
iterator/enumeration. They do not throw ConcurrentModificationException
. However, iterators are designed
to be used by only one thread at a time. Bear in mind that the
results of aggregate status methods including size
, isEmpty
, and containsValue
are typically useful only when
a map is not undergoing concurrent updates in other threads.
Otherwise the results of these methods reflect transient states
that may be adequate for monitoring or estimation purposes, but not
for program control.
The table is dynamically expanded when there are too many
collisions (i.e., keys that have distinct hash codes but fall into
the same slot modulo the table size), with the expected average
effect of maintaining roughly two bins per mapping (corresponding
to a 0.75 load factor threshold for resizing). There may be much
variance around this average as mappings are added and removed, but
overall, this maintains a commonly accepted time/space tradeoff for
hash tables. However, resizing this or any other kind of hash
table may be a relatively slow operation. When possible, it is a
good idea to provide a size estimate as an optional initialCapacity
constructor argument. An additional optional
loadFactor
constructor argument provides a further means of
customizing initial table capacity by specifying the table density
to be used in calculating the amount of space to allocate for the
given number of elements. Also, for compatibility with previous
versions of this class, constructors may optionally specify an
expected concurrencyLevel
as an additional hint for
internal sizing. Note that using many keys with exactly the same
hashCode()
is a sure way to slow down performance of any
hash table. To ameliorate impact, when keys are Comparable
,
this class may use comparison order among keys to help break ties.
A Set
projection of a ConcurrentHashMapV8 may be created
(using newKeySet()
or newKeySet(int)
), or viewed
(using keySet(Object)
when only keys are of interest, and the
mapped values are (perhaps transiently) not used or all take the
same mapping value.
This class and its views and iterators implement all of the
optional methods of the Map
and Iterator
interfaces.
Like Hashtable
but unlike HashMap
, this class
does not allow null
to be used as a key or value.
ConcurrentHashMapV8s support a set of sequential and parallel bulk
operations that are designed
to be safely, and often sensibly, applied even with maps that are
being concurrently updated by other threads; for example, when
computing a snapshot summary of the values in a shared registry.
There are three kinds of operation, each with four forms, accepting
functions with Keys, Values, Entries, and (Key, Value) arguments
and/or return values. Because the elements of a ConcurrentHashMapV8
are not ordered in any particular way, and may be processed in
different orders in different parallel executions, the correctness
of supplied functions should not depend on any ordering, or on any
other objects or values that may transiently change while
computation is in progress; and except for forEach actions, should
ideally be side-effect-free. Bulk operations on Map.Entry
objects do not support method setValue
.
These bulk operations accept a parallelismThreshold
argument. Methods proceed sequentially if the current map size is
estimated to be less than the given threshold. Using a value of
Long.MAX_VALUE
suppresses all parallelism. Using a value
of 1
results in maximal parallelism by partitioning into
enough subtasks to fully utilize the ForkJoinPool#commonPool() that is used for all parallel
computations. Normally, you would initially choose one of these
extreme values, and then measure performance of using in-between
values that trade off overhead versus throughput.
The concurrency properties of bulk operations follow
from those of ConcurrentHashMapV8: Any non-null result returned
from get(key)
and related access methods bears a
happens-before relation with the associated insertion or
update. The result of any bulk operation reflects the
composition of these per-element relations (but is not
necessarily atomic with respect to the map as a whole unless it
is somehow known to be quiescent). Conversely, because keys
and values in the map are never null, null serves as a reliable
atomic indicator of the current lack of any result. To
maintain this property, null serves as an implicit basis for
all non-scalar reduction operations. For the double, long, and
int versions, the basis should be one that, when combined with
any other value, returns that other value (more formally, it
should be the identity element for the reduction). Most common
reductions have these properties; for example, computing a sum
with basis 0 or a minimum with basis MAX_VALUE.
Search and transformation functions provided as arguments should similarly return null to indicate the lack of any result (in which case it is not used). In the case of mapped reductions, this also enables transformations to serve as filters, returning null (or, in the case of primitive specializations, the identity basis) if the element should not be combined. You can create compound transformations and filterings by composing them yourself under this "null means there is nothing there now" rule before using them in search or reduce operations.
Methods accepting and/or returning Entry arguments maintain
key-value associations. They may be useful for example when
finding the key for the greatest value. Note that "plain" Entry
arguments can be supplied using new
AbstractMap.SimpleEntry(k,v)
.
Bulk operations may complete abruptly, throwing an exception encountered in the application of a supplied function. Bear in mind when handling such exceptions that other concurrently executing functions could also have thrown exceptions, or would have done so if the first exception had not occurred.
Speedups for parallel compared to sequential forms are common but not guaranteed. Parallel operations involving brief functions on small maps may execute more slowly than sequential forms if the underlying work to parallelize the computation is more expensive than the computation itself. Similarly, parallelization may not lead to much actual parallelism if all processors are busy performing unrelated tasks.
All arguments to all task methods must be non-null.
jsr166e note: During transition, this class uses nested functional interfaces with different names but the same forms as those expected for JDK8.
This class is a member of the Java Collections Framework.
Modifier and Type | Class and Description |
---|---|
static interface |
ConcurrentHashMapV8.Action<A>
Interface describing a void action of one argument
|
(package private) static class |
ConcurrentHashMapV8.BaseIterator<K,V>
Base of key, value, and entry Iterators.
|
static interface |
ConcurrentHashMapV8.BiAction<A,B>
Interface describing a void action of two arguments
|
static interface |
ConcurrentHashMapV8.BiFun<A,B,T>
Interface describing a function of two arguments
|
(package private) static class |
ConcurrentHashMapV8.CollectionView<K,V,E>
Base class for views.
|
static interface |
ConcurrentHashMapV8.ConcurrentHashMapSpliterator<T>
An object for traversing and partitioning elements of a source.
|
(package private) static class |
ConcurrentHashMapV8.CounterCell |
(package private) static class |
ConcurrentHashMapV8.CounterHashCode
Holder for the thread-local hash code determining which
CounterCell to use.
|
static interface |
ConcurrentHashMapV8.DoubleByDoubleToDouble
Interface describing a function mapping two doubles to a double
|
(package private) static class |
ConcurrentHashMapV8.EntryIterator<K,V> |
(package private) static class |
ConcurrentHashMapV8.EntrySetView<K,V>
A view of a ConcurrentHashMapV8 as a
Set of (key, value)
entries. |
(package private) static class |
ConcurrentHashMapV8.EntrySpliterator<K,V> |
(package private) static class |
ConcurrentHashMapV8.ForwardingNode<K,V>
A node inserted at head of bins during transfer operations.
|
static interface |
ConcurrentHashMapV8.Fun<A,T>
Interface describing a function of one argument
|
static interface |
ConcurrentHashMapV8.IntByIntToInt
Interface describing a function mapping two ints to an int
|
(package private) static class |
ConcurrentHashMapV8.KeyIterator<K,V> |
static class |
ConcurrentHashMapV8.KeySetView<K,V>
A view of a ConcurrentHashMapV8 as a
Set of keys, in
which additions may optionally be enabled by mapping to a
common value. |
(package private) static class |
ConcurrentHashMapV8.KeySpliterator<K,V> |
static interface |
ConcurrentHashMapV8.LongByLongToLong
Interface describing a function mapping two longs to a long
|
(package private) static class |
ConcurrentHashMapV8.MapEntry<K,V>
Exported Entry for EntryIterator
|
(package private) static class |
ConcurrentHashMapV8.Node<K,V>
Key-value entry.
|
static interface |
ConcurrentHashMapV8.ObjectByObjectToDouble<A,B>
Interface describing a function mapping two arguments to a double
|
static interface |
ConcurrentHashMapV8.ObjectByObjectToInt<A,B>
Interface describing a function mapping two arguments to an int
|
static interface |
ConcurrentHashMapV8.ObjectByObjectToLong<A,B>
Interface describing a function mapping two arguments to a long
|
static interface |
ConcurrentHashMapV8.ObjectToDouble<A>
Interface describing a function mapping its argument to a double
|
static interface |
ConcurrentHashMapV8.ObjectToInt<A>
Interface describing a function mapping its argument to an int
|
static interface |
ConcurrentHashMapV8.ObjectToLong<A>
Interface describing a function mapping its argument to a long
|
(package private) static class |
ConcurrentHashMapV8.ReservationNode<K,V>
A place-holder node used in computeIfAbsent and compute
|
(package private) static class |
ConcurrentHashMapV8.Segment<K,V>
Stripped-down version of helper class used in previous version,
declared for the sake of serialization compatibility
|
(package private) static class |
ConcurrentHashMapV8.Traverser<K,V>
Encapsulates traversal for methods such as containsValue; also
serves as a base class for other iterators and spliterators.
|
(package private) static class |
ConcurrentHashMapV8.TreeBin<K,V>
TreeNodes used at the heads of bins.
|
(package private) static class |
ConcurrentHashMapV8.TreeNode<K,V>
Nodes for use in TreeBins
|
(package private) static class |
ConcurrentHashMapV8.ValueIterator<K,V> |
(package private) static class |
ConcurrentHashMapV8.ValueSpliterator<K,V> |
(package private) static class |
ConcurrentHashMapV8.ValuesView<K,V>
A view of a ConcurrentHashMapV8 as a
Collection of
values, in which additions are disabled. |
Modifier and Type | Field and Description |
---|---|
(package private) static AtomicInteger |
counterHashCodeGenerator
Generates initial value for per-thread CounterHashCodes.
|
(package private) static int |
HASH_BITS |
(package private) static int |
MAX_ARRAY_SIZE
The largest possible (non-power of two) array size.
|
(package private) static int |
MIN_TREEIFY_CAPACITY
The smallest table capacity for which bins may be treeified.
|
(package private) static int |
MOVED |
(package private) static int |
NCPU
Number of CPUS, to place bounds on some sizings
|
(package private) static int |
RESERVED |
(package private) static int |
SEED_INCREMENT
Increment for counterHashCodeGenerator.
|
(package private) ConcurrentHashMapV8.Node<K,V>[] |
table
The array of bins.
|
(package private) static ThreadLocal<ConcurrentHashMapV8.CounterHashCode> |
threadCounterHashCode
Per-thread counter hash codes.
|
(package private) static int |
TREEBIN |
(package private) static int |
TREEIFY_THRESHOLD
The bin count threshold for using a tree rather than list for a
bin.
|
(package private) static int |
UNTREEIFY_THRESHOLD
The bin count threshold for untreeifying a (split) bin during a
resize operation.
|
Constructor and Description |
---|
ConcurrentHashMapV8()
Creates a new, empty map with the default initial table size (16).
|
ConcurrentHashMapV8(int initialCapacity)
Creates a new, empty map with an initial table size
accommodating the specified number of elements without the need
to dynamically resize.
|
ConcurrentHashMapV8(int initialCapacity,
float loadFactor)
Creates a new, empty map with an initial table size based on
the given number of elements (
initialCapacity ) and
initial table density (loadFactor ). |
ConcurrentHashMapV8(int initialCapacity,
float loadFactor,
int concurrencyLevel)
Creates a new, empty map with an initial table size based on
the given number of elements (
initialCapacity ), table
density (loadFactor ), and number of concurrently
updating threads (concurrencyLevel ). |
ConcurrentHashMapV8(Map<? extends K,? extends V> m)
Creates a new map with the same mappings as the given map.
|
Modifier and Type | Method and Description |
---|---|
(package private) static <K,V> boolean |
casTabAt(ConcurrentHashMapV8.Node<K,V>[] tab,
int i,
ConcurrentHashMapV8.Node<K,V> c,
ConcurrentHashMapV8.Node<K,V> v) |
void |
clear()
Removes all of the mappings from this map.
|
(package private) static Class<?> |
comparableClassFor(Object x)
Returns x's Class if it is of the form "class C implements
Comparable
|
(package private) static int |
compareComparables(Class<?> kc,
Object k,
Object x)
Returns k.compareTo(x) if x matches kc (k's screened comparable
class), else 0.
|
V |
compute(K key,
ConcurrentHashMapV8.BiFun<? super K,? super V,? extends V> remappingFunction)
Attempts to compute a mapping for the specified key and its
current mapped value (or
null if there is no current
mapping). |
V |
computeIfAbsent(K key,
ConcurrentHashMapV8.Fun<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value,
attempts to compute its value using the given mapping function
and enters it into this map unless
null . |
V |
computeIfPresent(K key,
ConcurrentHashMapV8.BiFun<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present, attempts to
compute a new mapping given the key and its current mapped
value.
|
boolean |
contains(Object value)
Deprecated.
|
boolean |
containsKey(Object key)
Tests if the specified object is a key in this table.
|
boolean |
containsValue(Object value)
Returns
true if this map maps one or more keys to the
specified value. |
Enumeration<V> |
elements()
Returns an enumeration of the values in this table.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
boolean |
equals(Object o)
Compares the specified object with this map for equality.
|
void |
forEach(ConcurrentHashMapV8.BiAction<? super K,? super V> action) |
V |
get(Object key)
Returns the value to which the specified key is mapped,
or
null if this map contains no mapping for the key. |
V |
getOrDefault(Object key,
V defaultValue)
Returns the value to which the specified key is mapped, or the
given default value if this map contains no mapping for the
key.
|
int |
hashCode()
Returns the hash code value for this
Map , i.e.,
the sum of, for each key-value pair in the map,
key.hashCode() ^ value.hashCode() . |
(package private) ConcurrentHashMapV8.Node<K,V>[] |
helpTransfer(ConcurrentHashMapV8.Node<K,V>[] tab,
ConcurrentHashMapV8.Node<K,V> f)
Helps transfer if a resize is in progress.
|
boolean |
isEmpty() |
Enumeration<K> |
keys()
Returns an enumeration of the keys in this table.
|
ConcurrentHashMapV8.KeySetView<K,V> |
keySet()
Returns a
Set view of the keys contained in this map. |
ConcurrentHashMapV8.KeySetView<K,V> |
keySet(V mappedValue)
Returns a
Set view of the keys in this map, using the
given common mapped value for any additions (i.e., Collection.add(E) and Collection.addAll(Collection) ). |
long |
mappingCount()
Returns the number of mappings.
|
V |
merge(K key,
V value,
ConcurrentHashMapV8.BiFun<? super V,? super V,? extends V> remappingFunction)
If the specified key is not already associated with a
(non-null) value, associates it with the given value.
|
static <K> ConcurrentHashMapV8.KeySetView<K,Boolean> |
newKeySet()
Creates a new
Set backed by a ConcurrentHashMapV8
from the given type to Boolean.TRUE . |
static <K> ConcurrentHashMapV8.KeySetView<K,Boolean> |
newKeySet(int initialCapacity)
Creates a new
Set backed by a ConcurrentHashMapV8
from the given type to Boolean.TRUE . |
V |
put(K key,
V value)
Maps the specified key to the specified value in this table.
|
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this one.
|
V |
putIfAbsent(K key,
V value) |
(package private) V |
putVal(K key,
V value,
boolean onlyIfAbsent)
Implementation for put and putIfAbsent
|
V |
remove(Object key)
Removes the key (and its corresponding value) from this map.
|
boolean |
remove(Object key,
Object value) |
V |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
void |
replaceAll(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends V> function) |
(package private) V |
replaceNode(Object key,
V value,
Object cv)
Implementation for the four public remove/replace methods:
Replaces node value with v, conditional upon match of cv if
non-null.
|
(package private) static <K,V> void |
setTabAt(ConcurrentHashMapV8.Node<K,V>[] tab,
int i,
ConcurrentHashMapV8.Node<K,V> v) |
int |
size() |
(package private) static int |
spread(int h)
Spreads (XORs) higher bits of hash to lower and also forces top
bit to 0.
|
(package private) long |
sumCount() |
(package private) static <K,V> ConcurrentHashMapV8.Node<K,V> |
tabAt(ConcurrentHashMapV8.Node<K,V>[] tab,
int i) |
String |
toString()
Returns a string representation of this map.
|
(package private) static <K,V> ConcurrentHashMapV8.Node<K,V> |
untreeify(ConcurrentHashMapV8.Node<K,V> b)
Returns a list on non-TreeNodes replacing those in given list.
|
Collection<V> |
values()
Returns a
Collection view of the values contained in this map. |
static final int MAX_ARRAY_SIZE
static final int TREEIFY_THRESHOLD
static final int UNTREEIFY_THRESHOLD
static final int MIN_TREEIFY_CAPACITY
static final int MOVED
static final int TREEBIN
static final int RESERVED
static final int HASH_BITS
static final int NCPU
transient volatile ConcurrentHashMapV8.Node<K,V>[] table
static final AtomicInteger counterHashCodeGenerator
static final int SEED_INCREMENT
static final ThreadLocal<ConcurrentHashMapV8.CounterHashCode> threadCounterHashCode
public ConcurrentHashMapV8()
public ConcurrentHashMapV8(int initialCapacity)
initialCapacity
- The implementation performs internal
sizing to accommodate this many elements.IllegalArgumentException
- if the initial capacity of
elements is negativepublic ConcurrentHashMapV8(Map<? extends K,? extends V> m)
m
- the mappublic ConcurrentHashMapV8(int initialCapacity, float loadFactor)
initialCapacity
) and
initial table density (loadFactor
).initialCapacity
- the initial capacity. The implementation
performs internal sizing to accommodate this many elements,
given the specified load factor.loadFactor
- the load factor (table density) for
establishing the initial table sizeIllegalArgumentException
- if the initial capacity of
elements is negative or the load factor is nonpositivepublic ConcurrentHashMapV8(int initialCapacity, float loadFactor, int concurrencyLevel)
initialCapacity
), table
density (loadFactor
), and number of concurrently
updating threads (concurrencyLevel
).initialCapacity
- the initial capacity. The implementation
performs internal sizing to accommodate this many elements,
given the specified load factor.loadFactor
- the load factor (table density) for
establishing the initial table sizeconcurrencyLevel
- the estimated number of concurrently
updating threads. The implementation may use this value as
a sizing hint.IllegalArgumentException
- if the initial capacity is
negative or the load factor or concurrencyLevel are
nonpositivestatic final int spread(int h)
static Class<?> comparableClassFor(Object x)
static int compareComparables(Class<?> kc, Object k, Object x)
static final <K,V> ConcurrentHashMapV8.Node<K,V> tabAt(ConcurrentHashMapV8.Node<K,V>[] tab, int i)
static final <K,V> boolean casTabAt(ConcurrentHashMapV8.Node<K,V>[] tab, int i, ConcurrentHashMapV8.Node<K,V> c, ConcurrentHashMapV8.Node<K,V> v)
static final <K,V> void setTabAt(ConcurrentHashMapV8.Node<K,V>[] tab, int i, ConcurrentHashMapV8.Node<K,V> v)
public int size()
public boolean isEmpty()
public V get(Object key)
null
if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key
k
to a value v
such that key.equals(k)
,
then this method returns v
; otherwise it returns
null
. (There can be at most one such mapping.)
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
key
- possible keytrue
if and only if the specified object
is a key in this table, as determined by the
equals
method; false
otherwiseNullPointerException
- if the specified key is nullpublic boolean containsValue(Object value)
true
if this map maps one or more keys to the
specified value. Note: This method may require a full traversal
of the map, and is much slower than method containsKey
.containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
value
- value whose presence in this map is to be testedtrue
if this map maps one or more keys to the
specified valueNullPointerException
- if the specified value is nullpublic V put(K key, V value)
The value can be retrieved by calling the get
method
with a key that is equal to the original key.
put
in interface Map<K,V>
put
in class AbstractMap<K,V>
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keykey
, or
null
if there was no mapping for key
NullPointerException
- if the specified key or value is nullpublic void putAll(Map<? extends K,? extends V> m)
public V remove(Object key)
final V replaceNode(Object key, V value, Object cv)
public void clear()
public ConcurrentHashMapV8.KeySetView<K,V> keySet()
Set
view of the keys contained in this map.
The set is backed by the map, so changes to the map are
reflected in the set, and vice-versa. The set supports element
removal, which removes the corresponding mapping from this map,
via the Iterator.remove
, Set.remove
,
removeAll
, retainAll
, and clear
operations. It does not support the add
or
addAll
operations.
The view's iterator
is a "weakly consistent" iterator
that will never throw ConcurrentModificationException
,
and guarantees to traverse elements as they existed upon
construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.
public Collection<V> values()
Collection
view of the values contained in this map.
The collection is backed by the map, so changes to the map are
reflected in the collection, and vice-versa. The collection
supports element removal, which removes the corresponding
mapping from this map, via the Iterator.remove
,
Collection.remove
, removeAll
,
retainAll
, and clear
operations. It does not
support the add
or addAll
operations.
The view's iterator
is a "weakly consistent" iterator
that will never throw ConcurrentModificationException
,
and guarantees to traverse elements as they existed upon
construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.
public Set<Map.Entry<K,V>> entrySet()
Set
view of the mappings contained in this map.
The set is backed by the map, so changes to the map are
reflected in the set, and vice-versa. The set supports element
removal, which removes the corresponding mapping from the map,
via the Iterator.remove
, Set.remove
,
removeAll
, retainAll
, and clear
operations.
The view's iterator
is a "weakly consistent" iterator
that will never throw ConcurrentModificationException
,
and guarantees to traverse elements as they existed upon
construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.
public int hashCode()
Map
, i.e.,
the sum of, for each key-value pair in the map,
key.hashCode() ^ value.hashCode()
.public String toString()
{}
"). Adjacent
mappings are separated by the characters ", "
(comma
and space). Each key-value mapping is rendered as the key
followed by an equals sign ("=
") followed by the
associated value.public boolean equals(Object o)
true
if the given object is a map with the same
mappings as this map. This operation may return misleading
results if either map is concurrently modified during execution
of this method.public boolean remove(Object key, Object value)
public V getOrDefault(Object key, V defaultValue)
getOrDefault
in interface ConcurrentMap<K,V>
getOrDefault
in interface Map<K,V>
key
- the key whose associated value is to be returneddefaultValue
- the value to return if this map contains
no mapping for the given keyNullPointerException
- if the specified key is nullpublic void forEach(ConcurrentHashMapV8.BiAction<? super K,? super V> action)
public void replaceAll(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends V> function)
public V computeIfAbsent(K key, ConcurrentHashMapV8.Fun<? super K,? extends V> mappingFunction)
null
. The entire
method invocation is performed atomically, so the function is
applied at most once per key. Some attempted update operations
on this map by other threads may be blocked while computation
is in progress, so the computation should be short and simple,
and must not attempt to update any other mappings of this map.key
- key with which the specified value is to be associatedmappingFunction
- the function to compute a valueNullPointerException
- if the specified key or mappingFunction
is nullIllegalStateException
- if the computation detectably
attempts a recursive update to this map that would
otherwise never completeRuntimeException
- or Error if the mappingFunction does so,
in which case the mapping is left unestablishedpublic V computeIfPresent(K key, ConcurrentHashMapV8.BiFun<? super K,? super V,? extends V> remappingFunction)
key
- key with which a value may be associatedremappingFunction
- the function to compute a valueNullPointerException
- if the specified key or remappingFunction
is nullIllegalStateException
- if the computation detectably
attempts a recursive update to this map that would
otherwise never completeRuntimeException
- or Error if the remappingFunction does so,
in which case the mapping is unchangedpublic V compute(K key, ConcurrentHashMapV8.BiFun<? super K,? super V,? extends V> remappingFunction)
null
if there is no current
mapping). The entire method invocation is performed atomically.
Some attempted update operations on this map by other threads
may be blocked while computation is in progress, so the
computation should be short and simple, and must not attempt to
update any other mappings of this Map.key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a valueNullPointerException
- if the specified key or remappingFunction
is nullIllegalStateException
- if the computation detectably
attempts a recursive update to this map that would
otherwise never completeRuntimeException
- or Error if the remappingFunction does so,
in which case the mapping is unchangedpublic V merge(K key, V value, ConcurrentHashMapV8.BiFun<? super V,? super V,? extends V> remappingFunction)
null
. The entire
method invocation is performed atomically. Some attempted
update operations on this map by other threads may be blocked
while computation is in progress, so the computation should be
short and simple, and must not attempt to update any other
mappings of this Map.key
- key with which the specified value is to be associatedvalue
- the value to use if absentremappingFunction
- the function to recompute a value if presentNullPointerException
- if the specified key or the
remappingFunction is nullRuntimeException
- or Error if the remappingFunction does so,
in which case the mapping is unchanged@Deprecated public boolean contains(Object value)
containsValue(Object)
, and exists solely to ensure
full compatibility with class Hashtable
,
which supported this method prior to introduction of the
Java Collections framework.value
- a value to search fortrue
if and only if some key maps to the
value
argument in this table as
determined by the equals
method;
false
otherwiseNullPointerException
- if the specified value is nullpublic Enumeration<K> keys()
keySet()
public Enumeration<V> elements()
values()
public long mappingCount()
size()
because a ConcurrentHashMapV8 may
contain more mappings than can be represented as an int. The
value returned is an estimate; the actual count may differ if
there are concurrent insertions or removals.public static <K> ConcurrentHashMapV8.KeySetView<K,Boolean> newKeySet()
Set
backed by a ConcurrentHashMapV8
from the given type to Boolean.TRUE
.public static <K> ConcurrentHashMapV8.KeySetView<K,Boolean> newKeySet(int initialCapacity)
Set
backed by a ConcurrentHashMapV8
from the given type to Boolean.TRUE
.initialCapacity
- The implementation performs internal
sizing to accommodate this many elements.IllegalArgumentException
- if the initial capacity of
elements is negativepublic ConcurrentHashMapV8.KeySetView<K,V> keySet(V mappedValue)
Set
view of the keys in this map, using the
given common mapped value for any additions (i.e., Collection.add(E)
and Collection.addAll(Collection)
).
This is of course only appropriate if it is acceptable to use
the same value for all additions from this view.mappedValue
- the mapped value to use for any additionsNullPointerException
- if the mappedValue is nullfinal ConcurrentHashMapV8.Node<K,V>[] helpTransfer(ConcurrentHashMapV8.Node<K,V>[] tab, ConcurrentHashMapV8.Node<K,V> f)
static <K,V> ConcurrentHashMapV8.Node<K,V> untreeify(ConcurrentHashMapV8.Node<K,V> b)
final long sumCount()
Copyright © 2010-2020 Toolsverse. All Rights Reserved.