public interface Counter<T> extends Iterable<Map.Entry<T,Integer>>
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
Modifier and Type | Method and Description |
---|---|
void |
add(Counter<? extends T> counter)
Adds the counts from the provided
Counter to the current counts,
adding new elements as needed. |
int |
count(T obj)
Counts the object, increasing its total count by 1.
|
int |
count(T obj,
int count)
Counts the object, increasing its total count by the specified positive
amount.
|
void |
countAll(Collection<? extends T> c)
Counts all the elements in the collection.
|
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.
|
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 unique instances that are currently being counted.
|
int |
sum()
Returns the total number of instances that have been counted.
|
void add(Counter<? extends T> counter)
Counter
to the current counts,
adding new elements as needed.int count(T obj)
int count(T obj, int count)
count
- a positive value for the number of times the object occurredIllegalArgumentException
- if count
is not a positive value.void countAll(Collection<? extends T> c)
c
- a collection of elements to countint getCount(T obj)
double getFrequency(T obj)
obj
being seen in the items that have been counted.Set<T> items()
UnsupportedOperationException
.Iterator<Map.Entry<T,Integer>> iterator()
T max()
null
is returned. Ties in counts are
arbitrarily broken.T min()
null
is returned. Ties in counts are
arbitrarily broken.void reset()
items()
will be
0 after this call.int size()
int sum()
Copyright © 2012. All Rights Reserved.