public class PairCounter<T> extends Object implements Counter<Pair<T>>, Serializable
Pair
instance.
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. Unless otherwise noted, all methods will
throw a NullPointerException
if passed a null
element or a
Pair
with a null
element.
Constructor and Description |
---|
PairCounter()
Creates an empty
Counter . |
PairCounter(Collection<? extends Pair<T>> items)
Creates a
Counter whose initial state has counted all of the
specified items. |
Modifier and Type | Method and Description |
---|---|
void |
add(Counter<? extends Pair<T>> counter)
Adds the counts from the provided
Counter to the current counts,
adding new elements as needed. |
int |
count(Pair<T> obj)
Counts the pair of objects, increasing its total count by 1.
|
int |
count(Pair<T> obj,
int count)
Counts the pair, increasing its total count by the specified positive amount.
|
int |
count(T x,
T y)
Counts the pair of objects, increasing its total count by 1.
|
int |
count(T x,
T y,
int count)
Counts the pair, increasing its total count by the specified positive amount.
|
void |
countAll(Collection<? extends Pair<T>> c)
Counts all the elements in the collection.
|
boolean |
equals(Object o) |
int |
getCount(Pair<T> obj)
Returns the number of times the specified pair of objects has been seen
by this counter.
|
int |
getCount(T x,
T y)
Returns the number of times the specified pair of objects has been seen
by this counter.
|
double |
getFrequency(Pair<T> p)
Returns the frequency of this object pair relative to the counts of all other
object pair.
|
int |
hashCode() |
Set<Pair<T>> |
items()
Returns a view of the pairs currently being counted.
|
Iterator<Map.Entry<Pair<T>,Integer>> |
iterator()
Returns an iterator over the pairs that have been counted thusfar and
their respective counts.
|
Pair<T> |
max()
Returns the pair that currently has the largest count.
|
Pair<T> |
min()
Returns the pair that currently has the smallest count.
|
void |
reset()
Resets the counts for all pairs.
|
int |
size()
Returns the number of pairs that are currently being counted.
|
int |
sum()
Returns the total number of pairs that have been counted.
|
String |
toString() |
public PairCounter()
Counter
.public PairCounter(Collection<? extends Pair<T>> items)
Counter
whose initial state has counted all of the
specified items.public void add(Counter<? extends Pair<T>> counter)
Counter
to the current counts,
adding new elements as needed.public int count(Pair<T> obj, int count)
count
in interface Counter<Pair<T>>
count
- a positive value for the number of times the object occurredIllegalArgumentException
- if count
is not a positive value.public int count(T x, T y, int count)
count
- a positive value for the number of times the object occurredIllegalArgumentException
- if count
is not a positive value.public void countAll(Collection<? extends Pair<T>> c)
public boolean equals(Object o)
public int getCount(Pair<T> obj)
public int getCount(T x, T y)
public double getFrequency(Pair<T> p)
p
being seen in the items that have been counted.getFrequency
in interface Counter<Pair<T>>
public int hashCode()
public Set<Pair<T>> items()
UnsupportedOperationException
.public Iterator<Map.Entry<Pair<T>,Integer>> iterator()
public Pair<T> max()
null
is returned. Ties in counts are
arbitrarily broken.public Pair<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()
Copyright © 2012. All Rights Reserved.