|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgov.llnl.ontology.util.Counter<T>
public class Counter<T>
A utility for counting unique instance of an object.
This class supports iterating over the set of instances being counted as well as the instances and counts together. All collections views that are returned are unmodifiable and will throw an exception if a mutating method is called.
This class is not thread-safe
Nested Class Summary | |
---|---|
class |
Counter.EntryComparator
Compares the integer value of two Map#Entry object based on
ascending or descending order. |
Constructor Summary | |
---|---|
Counter()
Creates an empty Counter . |
|
Counter(Collection<? extends T> items)
Creates a Counter whose initial state has counted all of the
specified items. |
Method Summary | |
---|---|
int |
count(T obj)
Counts the object, increasing its total count by 1. |
int |
count(T obj,
int delta)
Counts the object, increasing its total count by 1. |
boolean |
equals(Object o)
|
int |
getCount(T obj)
Returns the number of times the specified object has been seen by this counter. |
double |
getFrequency(T obj)
Returns the frequency of this object relative to the counts of all other objects. |
int |
hashCode()
|
Set<T> |
items()
Returns a view of the items currently being counted. |
List<T> |
itemsSorted(boolean sortAscending)
Returns a view of the items currently being counted in sorted order. |
Iterator<Map.Entry<T,Integer>> |
iterator()
Returns an interator over the elements that have been counted thusfar and their respective counts. |
T |
max()
Returns the element that currently has the largest count. |
T |
min()
Returns the element that currently has the smallest count. |
void |
reset()
Resets the counts for all objects. |
int |
size()
Returns the number of instances that are currently being counted. |
int |
sum()
Returns the total number of instances that have been counted. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Counter()
Counter
.
public Counter(Collection<? extends T> items)
Counter
whose initial state has counted all of the
specified items.
Method Detail |
---|
public int count(T obj)
public int count(T obj, int delta)
public boolean equals(Object o)
equals
in class Object
public int getCount(T obj)
public double getFrequency(T obj)
obj
being seen in the items that have been counted.
public int hashCode()
hashCode
in class Object
public Set<T> items()
UnsupportedOperationException
.
public List<T> itemsSorted(boolean sortAscending)
public Iterator<Map.Entry<T,Integer>> iterator()
iterator
in interface Iterable<Map.Entry<T,Integer>>
public T max()
null
is returned. Ties in counts are
arbitrarily broken.
public T min()
null
is returned. Ties in counts are
arbitrarily broken.
public void reset()
items()
will be
0 after this call.
public int size()
public int sum()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |