org.jutil.java.collections
Class  Counter
java.lang.Object
  |
  +--org.jutil.java.collections.IntegerAccumulator
        |
        +--org.jutil.java.collections.Counter
- All Implemented Interfaces: 
- CollectionOperator
- public abstract class Counter- extends IntegerAccumulator
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);
 
 
 
| Method Summary | 
|  int | accumulate(java.lang.Object element,
           int acc)
 | 
| abstract  boolean | criterion(java.lang.Object element)The criterion used to determine whether or not an element
 has to be counted.
 | 
|  int | initialAccumulator()
 | 
 
 
| Methods inherited from class java.lang.Object | 
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
 
 
CVS_REVISION
public static final java.lang.String CVS_REVISION
Counter
public Counter()
initialAccumulator
public int initialAccumulator()
- 
- Specifications:
-      also
- 
 public behavior
 ensures \result  == 0;
 
 
- Specifications inherited from overridden method in class IntegerAccumulator:
 --- None ---
 
 
accumulate
public int accumulate(java.lang.Object element,
                      int acc)
- 
- Specifications:
-      also
- 
 public behavior
 ensures criterion(element) == false ==> \result  == acc;
 ensures criterion(element) == true ==> \result  == acc+1;
 
 
- Specifications inherited from overridden method in class IntegerAccumulator:
- 
requires element != null;
 
 
criterion
public abstract boolean criterion(java.lang.Object element)
- The criterion used to determine whether or not an element
 has to be counted.
- 
- Specifications:
- 
ensures ( \forall Object o1; ; ( \forall Object o2; o1.equals(o2); criterion(o1) == criterion(o2)));