jsr166e
Class LongAdderTable<K>
java.lang.Object
jsr166e.LongAdderTable<K>
- All Implemented Interfaces:
- Serializable
public class LongAdderTable<K>
- extends Object
- implements Serializable
A keyed table of adders, that may be useful in computing frequency
counts and histograms, or may be used as a form of multiset. A
LongAdder
is associated with each key. Keys are added to
the table implicitly upon any attempt to update, or may be added
explicitly using method install(K)
.
jsr166e note: This class is targeted to be placed in
java.util.concurrent.atomic
- Since:
- 1.8
- Author:
- Doug Lea
- See Also:
- Serialized Form
Method Summary |
void |
add(K key,
long x)
Adds the given value to the sum associated with the given
key. |
void |
decrement(K key)
Decrements the sum associated with the given key. |
Set<Map.Entry<K,LongAdder>> |
entrySet()
Returns the current set of key-value mappings. |
void |
increment(K key)
Increments the sum associated with the given key. |
LongAdder |
install(K key)
If the given key does not already exist in the table, inserts
the key with initial sum of zero; in either case returning the
adder associated with this key. |
Set<K> |
keySet()
Returns the current set of keys. |
void |
remove(K key)
Removes the given key from the table. |
void |
removeAll()
Removes all keys from the table. |
void |
reset(K key)
Resets the sum associated with the given key to zero if the key
exists in the table. |
void |
resetAll()
Resets the sum associated with each key to zero. |
long |
sum(K key)
Returns the sum associated with the given key, or zero if the
key does not currently exist in the table. |
long |
sumAll()
Returns the sum totalled across all keys. |
long |
sumThenReset(K key)
Resets the sum associated with the given key to zero if the key
exists in the table. |
long |
sumThenResetAll()
Totals, then resets, the sums associated with all keys. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LongAdderTable
public LongAdderTable()
- Creates a new empty table.
install
public LongAdder install(K key)
- If the given key does not already exist in the table, inserts
the key with initial sum of zero; in either case returning the
adder associated with this key.
- Parameters:
key
- the key
- Returns:
- the adder associated with the key
add
public void add(K key,
long x)
- Adds the given value to the sum associated with the given
key. If the key does not already exist in the table, it is
inserted.
- Parameters:
key
- the keyx
- the value to add
increment
public void increment(K key)
- Increments the sum associated with the given key. If the key
does not already exist in the table, it is inserted.
- Parameters:
key
- the key
decrement
public void decrement(K key)
- Decrements the sum associated with the given key. If the key
does not already exist in the table, it is inserted.
- Parameters:
key
- the key
sum
public long sum(K key)
- Returns the sum associated with the given key, or zero if the
key does not currently exist in the table.
- Parameters:
key
- the key
- Returns:
- the sum associated with the key, or zero if the key is
not in the table
reset
public void reset(K key)
- Resets the sum associated with the given key to zero if the key
exists in the table. This method does NOT add or
remove the key from the table (see
remove(K)
).
- Parameters:
key
- the key
sumThenReset
public long sumThenReset(K key)
- Resets the sum associated with the given key to zero if the key
exists in the table. This method does NOT add or
remove the key from the table (see
remove(K)
).
- Parameters:
key
- the key
- Returns:
- the previous sum, or zero if the key is not
in the table
sumAll
public long sumAll()
- Returns the sum totalled across all keys.
- Returns:
- the sum totalled across all keys
resetAll
public void resetAll()
- Resets the sum associated with each key to zero.
sumThenResetAll
public long sumThenResetAll()
- Totals, then resets, the sums associated with all keys.
- Returns:
- the sum totalled across all keys
remove
public void remove(K key)
- Removes the given key from the table.
- Parameters:
key
- the key
removeAll
public void removeAll()
- Removes all keys from the table.
keySet
public Set<K> keySet()
- Returns the current set of keys.
- Returns:
- the current set of keys
entrySet
public Set<Map.Entry<K,LongAdder>> entrySet()
- Returns the current set of key-value mappings.
- Returns:
- the current set of key-value mappings
Copyright © 2009-2012. All Rights Reserved.