E
- Element type to storepublic class ConcurrentHashCounter<E> extends java.lang.Object implements java.io.Serializable, Counter<E>, java.lang.Iterable<E>
Constructor and Description |
---|
ConcurrentHashCounter() |
ConcurrentHashCounter(int initialCapacity) |
Modifier and Type | Method and Description |
---|---|
void |
addAll(Counter<E> counter)
Adds the counts in the given Counter to the counts in this Counter.
|
void |
clear()
Removes all entries from the counter.
|
boolean |
containsKey(E key)
Returns whether a Counter contains a key.
|
double |
decrementCount(E key)
Decrements the count for this key by 1.0.
|
double |
decrementCount(E key,
double value)
Decrements the count for this key by the given value.
|
double |
defaultReturnValue()
Returns the default return value.
|
java.util.Set<java.util.Map.Entry<E,java.lang.Double>> |
entrySet()
Returns a view of the entries in this counter.
|
boolean |
equals(java.lang.Object o) |
double |
getCount(java.lang.Object key)
Returns the count for this key as a double.
|
Factory<Counter<E>> |
getFactory()
Returns a factory that can create new instances of this kind of Counter.
|
int |
hashCode()
Returns a hashCode which is the underlying Map's hashCode.
|
double |
incrementCount(E key)
Increments the count for this key by 1.0.
|
double |
incrementCount(E key,
double value)
Increments the count for the given key by the given value.
|
java.util.Iterator<E> |
iterator() |
java.util.Set<E> |
keySet()
Returns the Set of keys in this counter.
|
double |
logIncrementCount(E key,
double value)
Increments the count stored in log space for this key by the given
log-transformed value.
|
void |
prettyLog(Redwood.RedwoodChannels channels,
java.lang.String description)
Pretty logs the current object to specific Redwood channels.
|
double |
remove(E key)
Removes the given key and its associated value from this Counter.
|
void |
setCount(E key,
double value)
Sets the count for the given key to be the given value.
|
void |
setDefaultReturnValue(double value)
Sets the default return value.
|
int |
size()
Returns the number of entries stored in this counter.
|
java.lang.String |
toString()
Returns a String representation of the Counter, as formatted by
the underlying Map.
|
double |
totalCount()
Computes the total of all counts in this counter, and returns it
as a double.
|
java.util.Collection<java.lang.Double> |
values()
Returns a copy of the values currently in this counter.
|
public ConcurrentHashCounter()
public ConcurrentHashCounter(int initialCapacity)
public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E>
public Factory<Counter<E>> getFactory()
Counter
getFactory
in interface Counter<E>
public void setDefaultReturnValue(double value)
Counter
setDefaultReturnValue
in interface Counter<E>
value
- The default valuepublic double defaultReturnValue()
Counter
defaultReturnValue
in interface Counter<E>
public double getCount(java.lang.Object key)
Counter
public void setCount(E key, double value)
Counter
Counter.incrementCount(Object,double)
.public double incrementCount(E key, double value)
Counter
Counter.incrementCount(Object)
.
To set a count to a specific value instead of incrementing it, use
Counter.setCount(Object,double)
.incrementCount
in interface Counter<E>
key
- The key to incrementvalue
- The amount to increment it bypublic double incrementCount(E key)
Counter
Counter.incrementCount(Object,double)
.
To set a count to a specific value instead of incrementing it, use
Counter.setCount(Object,double)
.incrementCount
in interface Counter<E>
key
- The key to increment by 1.0public double decrementCount(E key, double value)
Counter
incrementCount
.
To more conveniently decrement the count by 1.0, use
Counter.decrementCount(Object)
.
To set a count to a specific value instead of decrementing it, use
Counter.setCount(Object,double)
.decrementCount
in interface Counter<E>
key
- The key to decrementvalue
- The amount to decrement it bypublic double decrementCount(E key)
Counter
Counter.decrementCount(Object,double)
.
To set a count to a specific value instead of decrementing it, use
Counter.setCount(Object,double)
.decrementCount
in interface Counter<E>
key
- The key to decrement by 1.0public double logIncrementCount(E key, double value)
Counter
Counter.setCount(Object,double)
.logIncrementCount
in interface Counter<E>
key
- The key to incrementvalue
- The amount to increment it by, in log spacepublic void addAll(Counter<E> counter)
Counter
public double remove(E key)
Counter
public boolean containsKey(E key)
Counter
containsKey
in interface Counter<E>
key
- The keypublic java.util.Set<E> keySet()
Counter
public java.util.Collection<java.lang.Double> values()
Counter
public java.util.Set<java.util.Map.Entry<E,java.lang.Double>> entrySet()
Counter
public void clear()
Counter
public int size()
Counter
public double totalCount()
Counter
totalCount
in interface Counter<E>
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void prettyLog(Redwood.RedwoodChannels channels, java.lang.String description)
PrettyLoggable
prettyLog
in interface PrettyLoggable
channels
- the channels which should be logged to -- all logging calls should
use logging methods on the channels (e.g. channels.log(), etc.)description
- The description of the object. It will potentially identify the
object's functional role or (failing that) its class. This is
typically used as a track name surrounding the contents of this
object.