|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.ObjectCounter<E>
E
- Type of element storedpublic class ObjectCounter<E>
Class to which arbitrary objects may be added
,
and statistical inquiries may be made about
(e.g. getSet
, getMostCommon
, getFraction
,
getCountTotal
, getCount
).
This class is multithread safe: all public methods are synchronized.
Nested Class Summary | |
---|---|
static class |
ObjectCounter.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private long |
countTotal
|
private Map<E,AtomicLong> |
objectToCount
|
Constructor Summary | |
---|---|
ObjectCounter()
|
Method Summary | |
---|---|
void |
add(E obj)
Places obj into an internal Map field and increments its occurrence count. |
long |
getCount(E obj)
Returns obj's count (i.e. the number of objects that have been added to this instance which equal obj). |
long |
getCountTotal()
Returns the total count (i.e. the total number of objects that have been added to this instance). |
double |
getFraction(E obj)
Returns the fraction of the total population of objects stored by this instance which equal obj (i.e. |
E |
getMostCommon()
Returns that object (of this instance's parameterized type E) which is the most common (i.e. has been added to this instance the most times, and thus has the largest count). |
Set<E> |
getSet()
Returns the set of all objects that have been added to this instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Map<E,AtomicLong> objectToCount
private long countTotal
Constructor Detail |
---|
public ObjectCounter()
Method Detail |
---|
public void add(E obj) throws IllegalStateException
Using a Map means that the set of Objects added via this method which are considered equivalent (and thus share a common count) is determined on the basis of their equals method.
obj
- an arbitrary Object (of this instance's parameterized type E) or null
IllegalStateException
- if countTotal == Long.MAX_VALUEpublic Set<E> getSet() throws IllegalStateException
Contract: the result may be zero-length, but is never null.
IllegalStateException
public E getMostCommon() throws IllegalStateException
IllegalStateException
- if zero objects have been added to this instancepublic double getFraction(E obj) throws IllegalStateException
getCount
(obj) divided by getCountTotal
).
IllegalStateException
- if zero objects have been added to this instancepublic long getCountTotal()
public long getCount(E obj)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |