long values that can be atomically updated. While writes to a
traditional Map rely on put(K, V), the typical mechanism for writing to this map
is addAndGet(K, long), which adds a long to the value currently associated with
K. If a key has not yet been associated with a value, its implicit value is zero.
Most methods in this class treat absent values and zero values identically, as individually
documented. Exceptions to this are containsKey, size, isEmpty, asMap, and toString.
Instances of this class may be used by multiple threads concurrently. All operations are atomic unless otherwise noted.
Instances of this class are serializable if the keys are serializable.
Note
If your values are always positive and less than 2^31, you may wish to use a
com. such as com. instead.
Warning
Unlike Multiset, entries whose values are zero are not automatically
removed from the map. Instead they must be removed manually with removeAllZeros.
| Modifier and Type | Field and Description |
|---|---|
| private transient Map | |
| private final ConcurrentHashMap |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public long | accumulateAndGet(K key, long x, LongBinaryOperator accumulatorFunction)
Updates the value currently associated with |
| public long | addAndGet(K key, long delta)
Adds |
| public Map | |
| public void | |
| public boolean | |
| public static <K> AtomicLongMap | |
| public static <K> AtomicLongMap | |
| private Map | |
| public long | decrementAndGet(K key)
Decrements by one the value currently associated with |
| public long | |
| public long | getAndAccumulate(K key, long x, LongBinaryOperator accumulatorFunction)
Updates the value currently associated with |
| public long | getAndAdd(K key, long delta)
Adds |
| public long | getAndDecrement(K key)
Decrements by one the value currently associated with |
| public long | getAndIncrement(K key)
Increments by one the value currently associated with |
| public long | getAndUpdate(K key, LongUnaryOperator updaterFunction)
Updates the value currently associated with |
| public long | incrementAndGet(K key)
Increments by one the value currently associated with |
| public boolean | |
| public long | put(K key, long newValue)
Associates |
| public void | |
| pack-priv long | putIfAbsent(K key, long newValue)
If |
| public long | |
| pack-priv boolean | remove(K key, long value)
If |
| public void | |
| public boolean | |
| pack-priv boolean | replace(K key, long expectedOldValue, long newValue)
If |
| public int | |
| public long | |
| public String | |
| public long | updateAndGet(K key, LongUnaryOperator updaterFunction)
Updates the value currently associated with |
| asMap | back to summary |
|---|---|
| private transient Map<K, Long> asMap
| |
| map | back to summary |
|---|---|
| private final ConcurrentHashMap<K, Long> map | |
| AtomicLongMap | back to summary |
|---|---|
| private AtomicLongMap(ConcurrentHashMap<K, Long> map) | |
| accumulateAndGet | back to summary |
|---|---|
| public long accumulateAndGet(K key, long x, LongBinaryOperator accumulatorFunction) Updates the value currently associated with
| |
| addAndGet | back to summary |
|---|---|
| public long addAndGet(K key, long delta) Adds
| |
| asMap | back to summary |
|---|---|
| public Map Returns a live, read-only view of the map backing this | |
| clear | back to summary |
|---|---|
| public void clear() Removes all of the mappings from this map. The map will be empty after this call returns. This method is not atomic: the map may not be empty after returning if there were concurrent writes. | |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(Object key) Returns true if this map contains a mapping for the specified key. | |
| create | back to summary |
|---|---|
| public static <K> AtomicLongMap Creates an | |
| create | back to summary |
|---|---|
| public static <K> AtomicLongMap Creates an | |
| createAsMap | back to summary |
|---|---|
| private Map | |
| decrementAndGet | back to summary |
|---|---|
| public long decrementAndGet(K key) Decrements by one the value currently associated with
| |
| get | back to summary |
|---|---|
| public long get(K key) Returns the value associated with | |
| getAndAccumulate | back to summary |
|---|---|
| public long getAndAccumulate(K key, long x, LongBinaryOperator accumulatorFunction) Updates the value currently associated with
| |
| getAndAdd | back to summary |
|---|---|
| public long getAndAdd(K key, long delta) Adds
| |
| getAndDecrement | back to summary |
|---|---|
| public long getAndDecrement(K key) Decrements by one the value currently associated with
| |
| getAndIncrement | back to summary |
|---|---|
| public long getAndIncrement(K key) Increments by one the value currently associated with
| |
| getAndUpdate | back to summary |
|---|---|
| public long getAndUpdate(K key, LongUnaryOperator updaterFunction) Updates the value currently associated with
| |
| incrementAndGet | back to summary |
|---|---|
| public long incrementAndGet(K key) Increments by one the value currently associated with
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns | |
| put | back to summary |
|---|---|
| public long put(K key, long newValue) Associates
| |
| putAll | back to summary |
|---|---|
| public void putAll(Map<? extends K, ? extends Long> m) Copies all of the mappings from the specified map to this map. The effect of this call is
equivalent to that of calling | |
| putIfAbsent | back to summary |
|---|---|
| pack-priv long putIfAbsent(K key, long newValue) If | |
| remove | back to summary |
|---|---|
| public long remove(K key) Removes and returns the value associated with
| |
| remove | back to summary |
|---|---|
| pack-priv boolean remove(K key, long value) If | |
| removeAllZeros | back to summary |
|---|---|
| public void removeAllZeros() Removes all mappings from this map whose values are zero. This method is not atomic: the map may be visible in intermediate states, where some of the zero values have been removed and others have not. | |
| removeIfZero | back to summary |
|---|---|
| public boolean removeIfZero(K key) Atomically remove
| |
| replace | back to summary |
|---|---|
| pack-priv boolean replace(K key, long expectedOldValue, long newValue) If If | |
| size | back to summary |
|---|---|
| public int size() Returns the number of key-value mappings in this map. If the map contains more than | |
| sum | back to summary |
|---|---|
| public long sum() Returns the sum of all values in this map. This method is not atomic: the sum may or may not include other concurrent operations. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| updateAndGet | back to summary |
|---|---|
| public long updateAndGet(K key, LongUnaryOperator updaterFunction) Updates the value currently associated with
| |