KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > algorithms > CountIfNot


1 package uk.co.jezuk.mango.algorithms;
2
3 import uk.co.jezuk.mango.iterators.SkippingIterator;
4 import java.util.Iterator JavaDoc;
5
6 /**
7  * <code>CountIfNot</code> is the complement of <code>CountIf</code>.
8  * It counts the number of elements in the sequence which fail some condition.
9  * The condition is a described in the user-supplied <code>test</code> object, and
10  * <code>CountIfNot</code> computes the number of objects such that <code>test.test(o)</code>
11  * is <code>false</code>.
12  * @see Count
13  * @see CountIf
14  * @version $Id: CountIfNot.java 97 2004-05-26 08:35:52Z jez $
15  */

16 public class CountIfNot
17 {
18   static public int execute(java.util.Iterator JavaDoc iterator, uk.co.jezuk.mango.Predicate test)
19   {
20     if((iterator == null) || (test == null))
21       return 0;
22
23     int c = 0;
24     for(Iterator filter = new SkippingIterator(iterator, test);
25     filter.hasNext();
26     filter.next(), ++c);
27
28     return c;
29   } // execute
30

31   /////////////////////////////////////////////////////////
32
private CountIfNot() { }
33 } // CountNotIf
34
Popular Tags