|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.stats.IntCounter<E>
public class IntCounter<E>
A specialized kind of hash table (or map) for storing numeric counts for objects. It works like a Map, but with different methods for easily getting/setting/incrementing counts for objects and computing various functions with the counts. The Counter constructor and addAll method can be used to copy another Counter's contents over. This class also provides access to Comparators that can be used to sort the keys or entries of this Counter by the counts, in either ascending or descending order.
Constructor Summary | |
---|---|
IntCounter()
Constructs a new (empty) Counter. |
|
IntCounter(IntCounter<E> c)
Constructs a new Counter with the contents of the given Counter. |
|
IntCounter(MapFactory mapFactory)
Pass in a MapFactory and the map it vends will back your counter. |
Method Summary | |
---|---|
void |
addAll(IntCounter<E> counter)
Adds the counts in the given Counter to the counts in this Counter. |
Object |
argmax()
Finds and returns the key in this Counter with the largest count. |
Object |
argmax(Comparator tieBreaker)
Finds and returns the key in this Counter with the largest count. |
Object |
argmin()
Finds and returns the key in this Counter with the smallest count. |
Object |
argmin(Comparator 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()
|
Comparator |
comparator()
Comparator that sorts objects by (increasing) count. |
Comparator |
comparator(boolean ascending)
Returns a comparator suitable for sorting this Counter's keys or entries by their respective counts. |
Comparator |
comparator(boolean ascending,
boolean useMagnitude)
Returns a comparator suitable for sorting this Counter's keys or entries by their respective value or magnitude (unsigned value). |
boolean |
containsKey(E key)
|
void |
decrementCount(E key)
Subtracts 1 from the count for the given key. |
void |
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 |
doubleMax()
Returns the value of the maximum entry in this counter, as a double. |
boolean |
equals(Object o)
|
double |
getCount(E key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
String |
getCountAsString(E key)
Returns the count for this key as a String. |
int |
getIntCount(Object key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
MapFactory |
getMapFactory()
Returns the MapFactory used by this counter. |
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()
|
void |
incrementCount(E key)
Adds 1 to the count for the given key. |
void |
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()
|
Set |
keysAbove(int countThreshold)
Returns the set of keys whose counts are at or above the given threshold. |
Set |
keysAt(int count)
Returns the set of keys that have exactly the given count. |
Set |
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. |
Object |
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,
int count)
Sets the current count for the given key. |
void |
setCount(E key,
String s)
Sets the count for this key to be the number encoded in the given String. |
void |
setCounts(Collection<E> keys,
int count)
Sets the current count for each of the given keys. |
int |
size()
Returns the number of entries 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)
|
int |
totalCount()
Returns the current total count for all objects in this Counter. |
int |
totalCount(Filter filter)
Returns the total count for all objects in this Counter that pass the given Filter. |
double |
totalDoubleCount()
Computes the total of all counts in this counter, and returns it as a double. |
double |
totalDoubleCount(Filter filter)
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public IntCounter()
public IntCounter(MapFactory mapFactory)
public IntCounter(IntCounter<E> c)
Method Detail |
---|
public MapFactory getMapFactory()
GenericCounter
getMapFactory
in interface GenericCounter<E>
public int totalCount()
public double totalDoubleCount()
GenericCounter
totalDoubleCount
in interface GenericCounter<E>
public int totalCount(Filter filter)
totalCount()
.
public double totalDoubleCount(Filter filter)
public double averageCount()
public double getCount(E key)
get
that casts
and extracts the primitive value.
getCount
in interface GenericCounter<E>
public String getCountAsString(E key)
GenericCounter
getCountAsString
in interface GenericCounter<E>
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 setCount(E key, String s)
GenericCounter
setCount
in interface GenericCounter<E>
public void setCounts(Collection<E> keys, int count)
incrementCounts(Collection,int)
.
public void incrementCount(E key, int count)
incrementCount(Object)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,int)
.
public void incrementCount(E key)
incrementCount(Object,int)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,int)
.
public 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 void decrementCount(E key, int count)
decrementCount(Object)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,int)
.
public void decrementCount(E key)
decrementCount(Object,int)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,int)
.
public 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)
public Object remove(E key)
public void removeAll(Collection<E> c)
public void clear()
public int size()
GenericCounter
size
in interface GenericCounter<E>
public boolean isEmpty()
public Set<E> keySet()
GenericCounter
keySet
in interface GenericCounter<E>
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public String toString(NumberFormat nf, String preAppend, String postAppend, String keyValSeparator, String itemSeparator)
public String toString(NumberFormat nf)
public Object clone()
clone
in class Object
public void removeZeroCounts()
public int max()
public double doubleMax()
GenericCounter
doubleMax
in interface GenericCounter<E>
public int min()
public Object argmax(Comparator tieBreaker)
public Object argmax()
argmax(Comparator)
. Returns null if this Counter is empty.
public Object argmin(Comparator tieBreaker)
public Object argmin()
argmin(Comparator)
. Returns null if this Counter is empty.
public Set keysAbove(int countThreshold)
public Set keysBelow(int countThreshold)
public Set keysAt(int count)
public Comparator comparator(boolean ascending)
Counter c = new Counter(); // add to the counter... List biggestKeys = new ArrayList(c.keySet()); Collections.sort(biggestKeys, c.comparator(false)); List smallestEntries = new ArrayList(c.entrySet()); Collections.sort(smallestEntries, c.comparator(true))
public Comparator comparator(boolean ascending, boolean useMagnitude)
Counter c = new Counter(); // add to the counter... List biggestKeys = new ArrayList(c.keySet()); Collections.sort(biggestKeys, c.comparator(false, true)); List smallestEntries = new ArrayList(c.entrySet()); Collections.sort(smallestEntries, c.comparator(true))
public Comparator comparator()
comparator(true)
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |