Class AtomicLongMap<K>
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(java.lang.Object), size(), isEmpty(),
asMap, and toString().
Instances of this class may be used by multiple threads concurrently. All operations are atomic unless otherwise noted.
Note: If your values are always positive and less than 2^31, you may wish to use a
Multiset such as
ConcurrentHashMultiset instead.
Warning: Unlike Multiset, entries whose values are zero are not automatically
removed from the map. Instead they must be removed manually with removeAllZeros().
- Since:
- 11.0
-
Method Summary
Modifier and TypeMethodDescriptionlongDeprecated.Addsdeltato the value currently associated withkey, and returns the new value.asMap()Deprecated.Returns a live, read-only view of the map backing thisAtomicLongMap.voidclear()Deprecated.Removes all of the mappings from this map.booleancontainsKey(Object key) Deprecated.Returns true if this map contains a mapping for the specified key.static <K> AtomicLongMap<K> create()Deprecated.Creates anAtomicLongMap.static <K> AtomicLongMap<K> Deprecated.Creates anAtomicLongMapwith the same mappings as the specifiedMap.longdecrementAndGet(K key) Deprecated.Decrements by one the value currently associated withkey, and returns the new value.longDeprecated.Returns the value associated withkey, or zero if there is no value associated withkey.longDeprecated.Addsdeltato the value currently associated withkey, and returns the old value.longgetAndDecrement(K key) Deprecated.Decrements by one the value currently associated withkey, and returns the old value.longgetAndIncrement(K key) Deprecated.Increments by one the value currently associated withkey, and returns the old value.longincrementAndGet(K key) Deprecated.Increments by one the value currently associated withkey, and returns the new value.booleanisEmpty()Deprecated.Returnstrueif this map contains no key-value mappings.longDeprecated.AssociatesnewValuewithkeyin this map, and returns the value previously associated withkey, or zero if there was no such value.voidDeprecated.Copies all of the mappings from the specified map to this map.longDeprecated.Removes and returns the value associated withkey.voidDeprecated.Removes all mappings from this map whose values are zero.intsize()Deprecated.Returns the number of key-value mappings in this map.longsum()Deprecated.Returns the sum of all values in this map.toString()Deprecated.
-
Method Details
-
create
Deprecated.Creates anAtomicLongMap. -
create
Deprecated.Creates anAtomicLongMapwith the same mappings as the specifiedMap. -
get
Deprecated.Returns the value associated withkey, or zero if there is no value associated withkey. -
incrementAndGet
Deprecated.Increments by one the value currently associated withkey, and returns the new value. -
decrementAndGet
Deprecated.Decrements by one the value currently associated withkey, and returns the new value. -
addAndGet
Deprecated.Addsdeltato the value currently associated withkey, and returns the new value. -
getAndIncrement
Deprecated.Increments by one the value currently associated withkey, and returns the old value. -
getAndDecrement
Deprecated.Decrements by one the value currently associated withkey, and returns the old value. -
getAndAdd
Deprecated.Addsdeltato the value currently associated withkey, and returns the old value. -
put
Deprecated.AssociatesnewValuewithkeyin this map, and returns the value previously associated withkey, or zero if there was no such value. -
putAll
Deprecated.Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from keykto valuevin the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. -
remove
Deprecated.Removes and returns the value associated withkey. Ifkeyis not in the map, this method has no effect and returns zero. -
removeAllZeros
public void removeAllZeros()Deprecated.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.
-
sum
public long sum()Deprecated.Returns the sum of all values in this map.This method is not atomic: the sum may or may not include other concurrent operations.
-
asMap
Deprecated.Returns a live, read-only view of the map backing thisAtomicLongMap. -
containsKey
Deprecated.Returns true if this map contains a mapping for the specified key. -
size
public int size()Deprecated.Returns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE. -
isEmpty
public boolean isEmpty()Deprecated.Returnstrueif this map contains no key-value mappings. -
clear
public void clear()Deprecated.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.
-
toString
Deprecated.
-