commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestFilterIterator.java
Date Mon, 25 Feb 2002 23:26:44 GMT
morgand     02/02/25 15:26:44

  Modified:    collections/src/test/org/apache/commons/collections
                        TestFilterIterator.java
  Log:
  added base class for testing iterators
  
  Revision  Changes    Path
  1.2       +53 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestFilterIterator.java
  
  Index: TestFilterIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFilterIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestFilterIterator.java	19 Oct 2001 20:33:01 -0000	1.1
  +++ TestFilterIterator.java	25 Feb 2002 23:26:43 -0000	1.2
  @@ -4,13 +4,14 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import junit.framework.Test;
  +import java.util.Iterator;
   import java.util.NoSuchElementException;
   
   /**
    *
    * @author  Jan Sorensen
    */
  -public class TestFilterIterator extends TestCase {
  +public class TestFilterIterator extends TestIterator {
   
       /** Creates new TestFilterIterator */
       public TestFilterIterator(String name) {
  @@ -41,6 +42,30 @@
           return (new TestSuite(TestFilterIterator.class));
       }
   
  +    /**
  +     * Returns an full iterator wrapped in a
  +     * FilterIterator that blocks all the elements
  +     * 
  +     * @return "empty" FilterIterator
  +     */
  +    public Iterator makeEmptyIterator() {
  +        return makeBlockAllFilter(new ArrayIterator(array));
  +    }
  +
  +    /**
  +     * Returns an array with elements wrapped in a pass-through
  +     * FilterIterator
  +     * 
  +     * @return 
  +     */
  +    public Iterator makeFullIterator() {
  +        return makePassThroughFilter(new ArrayIterator(array));
  +    }
  +
  +    public Object makeObject() {
  +        return makeFullIterator();
  +    }
  +
       public void testRepeatedHasNext() {
           for (int i = 0; i <= array.length; i++) {
               assertTrue(iterator.hasNext());
  @@ -95,11 +120,35 @@
       }
   
       private void initIterator() {
  -        iterator = new FilterIterator(new ArrayIterator(array));
  +        iterator = makePassThroughFilter(new ArrayIterator(array));
  +    }
  +
  +    /**
  +     * Returns a FilterIterator that does not filter
  +     * any of its elements
  +     * 
  +     * @param i      the Iterator to "filter"
  +     * @return "filtered" iterator
  +     */
  +    protected FilterIterator makePassThroughFilter(Iterator i) {
           Predicate pred = new Predicate() {
  -            public boolean evaluate(Object x) { return true; }
  +                public boolean evaluate(Object x) { return true; }
           };
  -        iterator.setPredicate(pred);
  +        return new FilterIterator(i,pred);
  +    }
  +
  +    /**
  +     * Returns a FilterIterator that blocks
  +     * all of its elements
  +     * 
  +     * @param i      the Iterator to "filter"
  +     * @return "filtered" iterator
  +     */
  +    protected FilterIterator makeBlockAllFilter(Iterator i) {
  +        Predicate pred = new Predicate() {
  +                public boolean evaluate(Object x) { return false; }
  +        };
  +        return new FilterIterator(i,pred);
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message