public class IntCounter<E> extends AbstractCounter<E> implements Serializable
Constructor and Description |
---|
IntCounter()
Constructs a new (empty) Counter.
|
IntCounter(IntCounter<E> c)
Constructs a new Counter with the contents of the given Counter.
|
IntCounter(MapFactory<E,MutableInteger> mapFactory)
Pass in a MapFactory and the map it vends will back your counter.
|
Modifier and Type | Method and Description |
---|---|
void |
addAll(IntCounter<E> counter)
Adds the counts in the given Counter to the counts in this Counter.
|
E |
argmax()
Finds and returns the key in this Counter with the largest count.
|
E |
argmax(Comparator<E> tieBreaker)
Finds and returns the key in this Counter with the largest count.
|
E |
argmin()
Finds and returns the key in this Counter with the smallest count.
|
E |
argmin(Comparator<E> tieBreaker)
Finds and returns the key in this Counter with the smallest count.
|
double |
averageCount()
Returns the mean of all the counts (totalCount/size).
|
void |
clear()
Removes all counts from this Counter.
|
Object |
clone() |
boolean |
containsKey(E key)
Returns whether a Counter contains a key.
|
double |
decrementCount(E key)
Subtracts 1 from the count for the given key.
|
int |
decrementCount(E key,
int count)
Subtracts the given count from the current count for the given key.
|
void |
decrementCounts(Collection<E> keys)
Subtracts 1 from the counts of each of the given keys.
|
void |
decrementCounts(Collection<E> keys,
int count)
Subtracts the given count from the current counts for each of the given keys.
|
double |
defaultReturnValue()
Returns the default return value.
|
double |
doubleMax() |
Set<Map.Entry<E,Double>> |
entrySet()
Returns a view of the doubles in this map.
|
boolean |
equals(Object o) |
double |
getCount(Object key)
Returns the current count for the given key, which is 0 if it hasn't
been
seen before.
|
String |
getCountAsString(E key) |
Factory<Counter<E>> |
getFactory()
Returns a factory that can create new instances of this kind of Counter.
|
int |
getIntCount(Object key)
Returns the current count for the given key, which is 0 if it hasn't
been
seen before.
|
MapFactory<E,MutableInteger> |
getMapFactory() |
double |
getNormalizedCount(E key)
This has been de-deprecated in order to reduce compilation warnings, but
really you should create a
Distribution instead of using this method. |
int |
hashCode() |
double |
incrementCount(E key)
Adds 1 to the count for the given key.
|
double |
incrementCount(E key,
double value)
Increments the count for the given key by the given value.
|
int |
incrementCount(E key,
int count)
Adds the given count to the current count for the given key.
|
void |
incrementCounts(Collection<E> keys)
Adds 1 to the counts for each of the given keys.
|
void |
incrementCounts(Collection<E> keys,
int count)
Adds the given count to the current counts for each of the given keys.
|
boolean |
isEmpty() |
Iterator<E> |
iterator() |
Set<E> |
keysAbove(int countThreshold)
Returns the set of keys whose counts are at or above the given threshold.
|
Set<E> |
keysAt(int count)
Returns the set of keys that have exactly the given count.
|
Set<E> |
keysBelow(int countThreshold)
Returns the set of keys whose counts are at or below the given threshold.
|
Set<E> |
keySet()
Returns the Set of keys in this counter.
|
int |
max()
Finds and returns the largest count in this Counter.
|
int |
min()
Finds and returns the smallest count in this Counter.
|
void |
prettyLog(Redwood.RedwoodChannels channels,
String description)
Pretty logs the current object to specific Redwood channels.
|
double |
remove(E key)
Removes the given key from this Counter.
|
void |
removeAll(Collection<E> c)
Removes all the given keys from this Counter.
|
void |
removeZeroCounts()
Removes all keys whose count is 0.
|
void |
setCount(E key,
double value)
Sets the count for the given key to be the given value.
|
void |
setCount(E key,
int count)
Sets the current count for the given key.
|
void |
setCount(E key,
String s) |
void |
setCounts(Collection<E> keys,
int count)
Sets the current count for each of the given keys.
|
void |
setDefaultReturnValue(double rv)
Sets the default return value.
|
void |
setDefaultReturnValue(int rv) |
int |
size()
Returns the number of entries stored in this counter.
|
void |
subtractAll(IntCounter<E> counter)
Subtracts the counts in the given Counter from the counts in this Counter.
|
String |
toString() |
String |
toString(NumberFormat nf) |
String |
toString(NumberFormat nf,
String preAppend,
String postAppend,
String keyValSeparator,
String itemSeparator) |
double |
totalCount()
Computes the total of all counts in this counter, and returns it
as a double.
|
double |
totalCount(java.util.function.Predicate<E> filter) |
double |
totalDoubleCount() |
double |
totalDoubleCount(java.util.function.Predicate<E> filter) |
int |
totalIntCount()
Returns the current total count for all objects in this Counter.
|
int |
totalIntCount(java.util.function.Predicate<E> filter)
Returns the total count for all objects in this Counter that pass the
given Filter.
|
Collection<Double> |
values()
Returns a copy of the values currently in this counter.
|
addAll, decrementCount, logIncrementCount
public IntCounter()
public IntCounter(MapFactory<E,MutableInteger> mapFactory)
public IntCounter(IntCounter<E> c)
public MapFactory<E,MutableInteger> getMapFactory()
public void setDefaultReturnValue(double rv)
Counter
setDefaultReturnValue
in interface Counter<E>
rv
- The default valuepublic void setDefaultReturnValue(int rv)
public double defaultReturnValue()
Counter
defaultReturnValue
in interface Counter<E>
public int totalIntCount()
public double totalDoubleCount()
public int totalIntCount(java.util.function.Predicate<E> filter)
totalCount()
.public double totalDoubleCount(java.util.function.Predicate<E> filter)
public double totalCount(java.util.function.Predicate<E> filter)
public double averageCount()
public double getCount(Object key)
get
that casts
and extracts the primitive value.public int getIntCount(Object key)
get
that casts
and extracts the primitive value.public double getNormalizedCount(E key)
Distribution
instead of using this method.public void setCount(E key, int count)
incrementCount(Object,int)
.public void setCounts(Collection<E> keys, int count)
incrementCounts(Collection,int)
.public int incrementCount(E key, int count)
incrementCount(Object)
.
To set a count to a specific value instead of incrementing it, use
setCount(Object,int)
.public double incrementCount(E key)
incrementCount(Object,int)
.
To set a count to a specific value instead of incrementing it, use
setCount(Object,int)
.incrementCount
in interface Counter<E>
incrementCount
in class AbstractCounter<E>
key
- The key to increment by 1.0public void incrementCounts(Collection<E> keys, int count)
incrementCounts(Collection)
.
To set the counts of a collection of objects to a specific value instead
of incrementing them, use setCounts(Collection,int)
.public void incrementCounts(Collection<E> keys)
incrementCounts(Collection,int)
.
To set the counts of a collection of objects to a specific value instead
of incrementing them, use setCounts(Collection,int)
.public int decrementCount(E key, int count)
decrementCount(Object)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,int)
.public double decrementCount(E key)
decrementCount(Object,int)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,int)
.decrementCount
in interface Counter<E>
decrementCount
in class AbstractCounter<E>
key
- The key to decrement by 1.0public void decrementCounts(Collection<E> keys, int count)
decrementCounts(Collection)
.
To set the counts of a collection of objects to a specific value instead
of decrementing them, use setCounts(Collection,int)
.public void decrementCounts(Collection<E> keys)
decrementCounts(Collection,int)
.
To set the counts of a collection of objects to a specifc value instead
of decrementing them, use setCounts(Collection,int)
.public void addAll(IntCounter<E> counter)
public void subtractAll(IntCounter<E> counter)
public boolean containsKey(E key)
Counter
containsKey
in interface Counter<E>
key
- The keypublic double remove(E key)
public void removeAll(Collection<E> c)
public void clear()
public int size()
Counter
public boolean isEmpty()
public Set<E> keySet()
Counter
public Set<Map.Entry<E,Double>> entrySet()
public String toString(NumberFormat nf, String preAppend, String postAppend, String keyValSeparator, String itemSeparator)
public String toString(NumberFormat nf)
public void removeZeroCounts()
public int max()
public double doubleMax()
public int min()
public E argmax(Comparator<E> tieBreaker)
public E argmax()
argmax(Comparator)
. Returns null if this Counter is empty.public E argmin(Comparator<E> tieBreaker)
public E argmin()
argmin(Comparator)
. Returns null if this Counter is empty.public Set<E> keysAbove(int countThreshold)
public Set<E> keysBelow(int countThreshold)
public Set<E> keysAt(int count)
public Factory<Counter<E>> getFactory()
Counter
getFactory
in interface Counter<E>
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>
incrementCount
in class AbstractCounter<E>
key
- The key to incrementvalue
- The amount to increment it bypublic double totalCount()
Counter
totalCount
in interface Counter<E>
public Collection<Double> values()
Counter
public void prettyLog(Redwood.RedwoodChannels channels, String description)
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.