|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jutil.java.collections.IntegerAccumulator | +--org.jutil.java.collections.Counter
An IntegerAccumulator that counts the number of items in a collection that satisfies some criterion.
A convenience accumulator of collections that checks
elements of a collection satisfy the criterion defined in
public boolean criterion(Object element)
.
As with the accumulator, this class can best be used as an anonymous inner class, as shown below.
int number = new Counter() {
public boolean criterion(Object element) {
// criterion code
}
}.in(collection);
Field Summary | |
static java.lang.String |
CVS_REVISION
|
Constructor Summary | |
Counter()
|
Method Summary | |
int |
accumulate(java.lang.Object element,
int acc)
also public behavior // If the element satisfies the criterion, acc + 1 is returned to // indicate 1 more element satisfies the criterion. // otherwise acc is returned. post criterion(element) == false ==> \result == acc; post criterion(element) == true ==> \result == acc + 1; |
abstract boolean |
criterion(java.lang.Object element)
//As usual, criterion must be consistent with the semantics of equals post (\forall Object o1;; (\forall Object o2; o1.equals(o2); criterion(o1) == criterion(o2))); The criterion used to determine whether or not an element has to be counted. |
int |
initialAccumulator()
also public behavior post \result == 0; |
Methods inherited from class org.jutil.java.collections.IntegerAccumulator |
in |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String CVS_REVISION
Constructor Detail |
public Counter()
Method Detail |
public int initialAccumulator()
initialAccumulator
in class IntegerAccumulator
public int accumulate(java.lang.Object element, int acc)
accumulate
in class IntegerAccumulator
org.jutil.java.collections.IntegerAccumulator
element
- The object the method will process and change the accumulator with.acc
- The accumulator for the accumulation.
For the first element to be processed, the result of initialAccumulator
is used. For the other elements, the result of this method applied on
the previous element is used.public abstract boolean criterion(java.lang.Object element)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |