commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pj...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/iterators TestAll.java TestArrayIterator.java TestArrayIterator2.java TestCollatingIterator.java TestFilterIterator.java TestFilterListIterator.java TestIterator.java TestIteratorChain.java TestListIteratorWrapper.java TestSingletonIterator.java TestUniqueFilterIterator.java
Date Thu, 15 Aug 2002 23:13:52 GMT
pjack       2002/08/15 16:13:52

  Modified:    collections/src/java/org/apache/commons/collections
                        ArrayIterator.java EnumerationIterator.java
                        FilterIterator.java FilterListIterator.java
                        IteratorEnumeration.java ProxyIterator.java
                        ProxyListIterator.java SingletonIterator.java
                        TransformIterator.java
               collections/src/test/org/apache/commons/collections
                        TestAll.java
  Added:       collections/src/java/org/apache/commons/collections/iterators
                        ArrayIterator.java CollatingIterator.java
                        EnumerationIterator.java FilterIterator.java
                        FilterListIterator.java IteratorChain.java
                        IteratorEnumeration.java ListIteratorWrapper.java
                        ProxyIterator.java ProxyListIterator.java
                        SingletonIterator.java TransformIterator.java
                        UniqueFilterIterator.java
               collections/src/test/org/apache/commons/collections/iterators
                        TestAll.java TestArrayIterator.java
                        TestArrayIterator2.java TestCollatingIterator.java
                        TestFilterIterator.java TestFilterListIterator.java
                        TestIterator.java TestIteratorChain.java
                        TestListIteratorWrapper.java
                        TestSingletonIterator.java
                        TestUniqueFilterIterator.java
  Removed:     collections/src/java/org/apache/commons/collections
                        CollatingIterator.java IteratorChain.java
                        ListIteratorWrapper.java
               collections/src/test/org/apache/commons/collections
                        TestArrayIterator.java TestArrayIterator2.java
                        TestCollatingIterator.java TestFilterIterator.java
                        TestFilterListIterator.java TestIterator.java
                        TestIteratorChain.java TestListIteratorWrapper.java
                        TestSingletonIterator.java
                        TestUniqueFilterIterator.java
  Log:
  Moved all iterators to new iterators subpackage.
  Deprecated all iterator classes in the main package released in 2.0.
  Removed all iterator classes from the main package that were not
   released yet.
  Moved test code for iterators into new iterators subpackage.
  Deleted old iterator test code in the main package.
  Modified main package TestAll to invoke iterators subpackage TestAll.
  
  Revision  Changes    Path
  1.16      +11 -124   jakarta-commons/collections/src/java/org/apache/commons/collections/ArrayIterator.java
  
  Index: ArrayIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ArrayIterator.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ArrayIterator.java	15 Aug 2002 20:04:31 -0000	1.15
  +++ ArrayIterator.java	15 Aug 2002 23:13:51 -0000	1.16
  @@ -71,13 +71,10 @@
     * @author Mauricio S. Moura
     * @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
     * @version $Revision$
  +  * @deprecated this class has been moved to the iterators subpackage
     */
  -public class ArrayIterator implements Iterator {
  -    
  -    private Object array;
  -    private int length = 0;
  -    private int index = 0;
  -  
  +public class ArrayIterator 
  +extends org.apache.commons.collections.iterators.ArrayIterator {
       
       /**
        *  Construct an ArrayIterator.  Using this constructor, the iterator is
  @@ -85,6 +82,7 @@
        *  called to establish the array to iterate over.
        **/
       public ArrayIterator() {
  +        super();
       }
      
       /**
  @@ -100,7 +98,7 @@
        *  if <code>array</code> is <code>null</code>
        **/
       public ArrayIterator(Object array) {
  -        setArray( array );
  +        super(array);
       }
   
       /**
  @@ -117,9 +115,7 @@
        *  if <code>array</code> is <code>null</code>
        **/
       public ArrayIterator(Object array, int start) {
  -        setArray( array );
  -        checkBound(start, "start");
  -        this.index = start;
  +        super(array, start);
       }
   
       /**
  @@ -137,116 +133,7 @@
        *  if <code>array</code> is <code>null</code>
        **/
       public ArrayIterator(Object array, int start, int end) {
  -        setArray( array );
  -        checkBound(start, "start");
  -        checkBound(end, "end");
  -        if(end <= start) {
  -            throw new IllegalArgumentException(
  -                "End index must be greater than start index. "
  -            );
  -        }
  -        this.index = start;
  -        this.length = end;
  -    }
  -
  -    private void checkBound(int bound, String type ) {
  -        if(bound > this.length) {
  -            throw new ArrayIndexOutOfBoundsException(
  -              "Attempt to make an ArrayIterator that "+type+
  -              "s beyond the end of the array. "
  -            );
  -        }
  -        if(bound < 0) {
  -            throw new ArrayIndexOutOfBoundsException(
  -              "Attempt to make an ArrayIterator that "+type+
  -              "s before the start of the array. "
  -            );
  -        }
  -    }
  -
  -    // Iterator interface
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Returns true if there are more elements to return from the array.
  -     *
  -     *  @return true if there is a next element to return
  -     */
  -    public boolean hasNext() {
  -        return index < length;
  -    }
  -
  -    /**
  -     *  Returns the next element in the array.
  -     *
  -     *  @return the next element in the array
  -     *  @throws NoSuchElementException if all the elements in the array
  -     *    have already been returned
  -     */
  -    public Object next() {
  -        if(!hasNext()) {
  -            throw new NoSuchElementException();
  -        }
  -        return Array.get( array, index++ );
  -    }
  -
  -    /**
  -     *  Throws {@link UnsupportedOperationException}.
  -     *
  -     *  @throws UnsupportedOperationException always
  -     */
  -    public void remove() {
  -        throw new UnsupportedOperationException( "remove() method is not supported" );
  +        super(array, start, end);
       }
   
  -    // Properties
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Retrieves the array that this iterator is iterating over. 
  -     *
  -     *  @return the array this iterator iterates over, or <code>null</code> if
  -     *  the no-arg constructor was used and {@link #setArray(Object)} has never
  -     *  been called with a valid array.
  -     **/
  -    public Object getArray() {
  -        return array;
  -    }
  -    
  -    /**
  -     *  Changes the array that the ArrayIterator should iterate over.  If an
  -     *  array has previously been set (using the single-arg constructor or this
  -     *  method), that array along with the current iterator position within
  -     *  that array is discarded in favor of the argument to this method.  This
  -     *  method can be used in combination with {@link #getArray()} to "reset"
  -     *  the iterator to the beginning of the array:
  -     *
  -     *  <pre>
  -     *    ArrayIterator iterator = ...
  -     *    ...
  -     *    iterator.setArray(iterator.getArray());
  -     *  </pre>
  -     *
  -     *  Note: Using i.setArray(i.getArray()) may throw a NullPointerException
  -     *  if no array has ever been set for the iterator (see {@link
  -     *  #getArray()})
  -     *
  -     *  @param array the array that the iterator should iterate over.
  -     *
  -     *  @exception IllegalArgumentException if <code>array</code> is not an
  -     *  array.
  -     *
  -     *  @exception NullPointerException 
  -     *  if <code>array</code> is <code>null</code>
  -     **/
  -    public void setArray( Object array ) {
  -        // Array.getLength throws IllegalArgumentException if the object is not
  -        // an array or NullPointerException if the object is null.  This call
  -        // is made before saving the array and resetting the index so that the
  -        // array iterator remains in a consistent state if the argument is not
  -        // an array or is null.
  -        this.length = Array.getLength( array );
  -        this.array = array;
  -        this.index = 0;
  -    }
   }
  
  
  
  1.6       +9 -84     jakarta-commons/collections/src/java/org/apache/commons/collections/EnumerationIterator.java
  
  Index: EnumerationIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/EnumerationIterator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EnumerationIterator.java	15 Aug 2002 20:04:31 -0000	1.5
  +++ EnumerationIterator.java	15 Aug 2002 23:13:51 -0000	1.6
  @@ -70,21 +70,17 @@
     * @since 1.0
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
     * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  +  * @deprecated this class has been moved to the iterators subpackage
     */
  -public class EnumerationIterator implements Iterator {
  -    
  -    private Collection collection;
  -
  -    private Enumeration enumeration;
  -
  -    private Object last;
  +public class EnumerationIterator
  +extends org.apache.commons.collections.iterators.EnumerationIterator {
       
       /**
        *  Constructs a new <Code>EnumerationIterator</Code> that will not
        *  function until {@link #setEnumeration(Enumeration)} is called.
        */
       public EnumerationIterator() {
  -        this(null, null);
  +        super();
       }
   
       /**
  @@ -94,7 +90,7 @@
        *  @param enumeration  the enumeration to use
        */
       public EnumerationIterator( Enumeration enumeration ) {
  -        this(enumeration, null);
  +        super(enumeration);
       }
   
       /**
  @@ -105,78 +101,7 @@
        *  @param collection  the collection to remove elements form
        */
       public EnumerationIterator( Enumeration enum, Collection collection ) {
  -        this.enumeration = enum;
  -        this.collection = collection;
  -        this.last = null;
  +        super(enum, collection);
       }
   
  -    // Iterator interface
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Returns true if the underlying enumeration has more elements.
  -     *
  -     *  @return true if the underlying enumeration has more elements
  -     *  @throws NullPointerException  if the underlying enumeration is null
  -     */
  -    public boolean hasNext() {
  -        return enumeration.hasMoreElements();
  -    }
  -
  -    /**
  -     *  Returns the next object from the enumeration.
  -     *
  -     *  @return the next object from the enumeration
  -     *  @throws NullPointerException if the enumeration is null
  -     */
  -    public Object next() {
  -        last = enumeration.nextElement();
  -        return last;
  -    }
  -
  -    /**
  -     * Functions if an associated <code>Collection</code> is known.
  -     * If so, the first occurrence of the last returned object from this
  -     * iterator will be removed from the collection.
  -     *
  -     * @exception IllegalStateException <code>next()</code> not called.
  -     * @exception UnsupportedOperationException No associated
  -     * <code>Collection</code>.
  -     */
  -    public void remove() {
  -        if (collection != null) {
  -            if (last != null) {
  -                collection.remove(last);
  -            }
  -            else {
  -                throw new IllegalStateException
  -                    ("next() must have been called for remove() to function");
  -            }
  -        }
  -        else {
  -            throw new UnsupportedOperationException
  -                ("No Collection associated with this Iterator");
  -        }
  -    }
  -
  -    // Properties
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Returns the underlying enumeration.
  -     *
  -     *  @return the underlying enumeration
  -     */
  -    public Enumeration getEnumeration() {
  -        return enumeration;
  -    }
  -
  -    /**
  -     *  Sets the underlying enumeration.
  -     *
  -     *  @param enumeration  the new underlying enumeration
  -     */
  -    public void setEnumeration( Enumeration enumeration ) {
  -        this.enumeration = enumeration;
  -    }
   }
  
  
  
  1.7       +8 -92     jakarta-commons/collections/src/java/org/apache/commons/collections/FilterIterator.java
  
  Index: FilterIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/FilterIterator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FilterIterator.java	15 Aug 2002 20:04:31 -0000	1.6
  +++ FilterIterator.java	15 Aug 2002 23:13:51 -0000	1.7
  @@ -72,24 +72,18 @@
     * @since 1.0
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
     * @author Jan Sorensen
  +  * @deprecated this class has been moved to the iterators subpackage
     */
   
  -public class FilterIterator extends ProxyIterator {
  -    
  -    /** Holds value of property predicate. */
  -    private Predicate predicate;
  -
  -    private Object nextObject;
  -    private boolean nextObjectSet = false;
  -    
  -    
  -    //-------------------------------------------------------------------------
  +public class FilterIterator 
  +extends org.apache.commons.collections.iterators.FilterIterator {
   
       /**
        *  Constructs a new <Code>FilterIterator</Code> that will not function
        *  until {@link #setIterator(Iterator) setIterator} is invoked.
        */
       public FilterIterator() {
  +        super();
       }
       
       /**
  @@ -110,85 +104,7 @@
        *  @param predicate  the predicate to use
        */
       public FilterIterator( Iterator iterator, Predicate predicate ) {
  -        super( iterator );
  -        this.predicate = predicate;
  -    }
  -
  -    // Iterator interface
  -    //-------------------------------------------------------------------------
  -    
  -    /** 
  -     *  Returns true if the underlying iterator contains an object that 
  -     *  matches the predicate.
  -     *
  -     *  @return true if there is another object that matches the predicate 
  -     */
  -    public boolean hasNext() {
  -        if ( nextObjectSet ) {
  -            return true;
  -        } else {
  -            return setNextObject();
  -        }
  -    }
  -
  -    /** 
  -     *  Returns the next object that matches the predicate.
  -     * 
  -     *  @return the next object which matches the given predicate
  -     *  @throws NoSuchElementException if there are no more elements that
  -     *   match the predicate 
  -     */
  -    public Object next() {
  -        if ( !nextObjectSet ) {
  -            if (!setNextObject()) {
  -                throw new NoSuchElementException();
  -            }
  -        }
  -        nextObjectSet = false;
  -        return nextObject;
  +        super( iterator, predicate );
       }
   
  -    /**
  -     * Always throws UnsupportedOperationException as this class 
  -     * does look-ahead with its internal iterator.
  -     *
  -     * @throws UnsupportedOperationException  always
  -     */
  -    public void remove() {
  -        throw new UnsupportedOperationException();
  -    }
  -        
  -
  -    // Properties
  -    //-------------------------------------------------------------------------
  -    /** Getter for property predicate.
  -     * @return Value of property predicate.
  -     */
  -    public Predicate getPredicate() {
  -        return predicate;
  -    }
  -    /** Setter for property predicate.
  -     * @param predicate New value of property predicate.
  -     */
  -    public void setPredicate(Predicate predicate) {
  -        this.predicate = predicate;
  -    }
  -
  -    /**
  -     * Set nextObject to the next object. If there are no more 
  -     * objects then return false. Otherwise, return true.
  -     */
  -    private boolean setNextObject() {
  -        Iterator iterator = getIterator();
  -        Predicate predicate = getPredicate();
  -        while ( iterator.hasNext() ) {
  -            Object object = iterator.next();
  -            if ( predicate.evaluate( object ) ) {
  -                nextObject = object;
  -                nextObjectSet = true;
  -                return true;
  -            }
  -        }
  -        return false;
  -    }
   }
  
  
  
  1.6       +10 -195   jakarta-commons/collections/src/java/org/apache/commons/collections/FilterListIterator.java
  
  Index: FilterListIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/FilterListIterator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FilterListIterator.java	15 Aug 2002 20:04:31 -0000	1.5
  +++ FilterListIterator.java	15 Aug 2002 23:13:51 -0000	1.6
  @@ -74,8 +74,10 @@
     * @since 2.0
     * @version $Revision$ $Date$
     * @author Rodney Waldhoff
  +  * @deprecated this class has been moved to the iterators subpackage
     */
  -public class FilterListIterator extends ProxyListIterator {
  +public class FilterListIterator 
  +extends org.apache.commons.collections.iterators.FilterListIterator {
   
       // Constructors    
       //-------------------------------------------------------------------------
  @@ -87,6 +89,7 @@
        *  and {@link #setPredicate(Predicate) setPredicate} are invoked.
        */
       public FilterListIterator() {
  +        super();
       }
   
       /**
  @@ -106,8 +109,7 @@
        *  @param predicate  the predicate to use
        */
       public FilterListIterator(ListIterator iterator, Predicate predicate) {
  -        super(iterator);
  -        this.predicate = predicate;
  +        super(iterator, predicate);
       }
   
       /**
  @@ -119,194 +121,7 @@
        *  @param predicate  the predicate to use.
        */
       public FilterListIterator(Predicate predicate) {
  -        this.predicate = predicate;
  -    }
  -
  -    // ListIterator interface
  -    //-------------------------------------------------------------------------
  -
  -    /** Not supported. */
  -    public void add(Object o) {
  -        throw new UnsupportedOperationException("FilterListIterator.add(Object) is not supported.");
  -    }
  -
  -    public boolean hasNext() {
  -        if(nextObjectSet) {
  -            return true;
  -        } else {
  -            return setNextObject();
  -        }
  -    }
  -
  -    public boolean hasPrevious() {
  -        if(previousObjectSet) {
  -            return true;
  -        } else {
  -            return setPreviousObject();
  -        }
  -    }
  -
  -    public Object next() {
  -        if(!nextObjectSet) {
  -            if(!setNextObject()) {
  -                throw new NoSuchElementException();
  -            }
  -        }
  -        nextIndex++;
  -        Object temp = nextObject;
  -        clearNextObject();
  -        return temp;
  -    }
  -
  -    public int nextIndex() {
  -        return nextIndex;
  -    }
  -
  -    public Object previous() {
  -        if(!previousObjectSet) {
  -            if(!setPreviousObject()) {
  -                throw new NoSuchElementException();
  -            }
  -        }
  -        nextIndex--;
  -        Object temp = previousObject;
  -        clearPreviousObject();
  -        return temp;
  -    }
  -
  -    public int previousIndex() {
  -        return (nextIndex-1);
  -    }
  -
  -    /** Not supported. */
  -    public void remove() {
  -        throw new UnsupportedOperationException("FilterListIterator.remove() is not supported.");
  -    }
  -
  -    /** Not supported. */
  -    public void set(Object o) {
  -        throw new UnsupportedOperationException("FilterListIterator.set(Object) is not supported.");
  -    }
  -
  -    // Properties
  -    //-------------------------------------------------------------------------
  -
  -    /** 
  -     * Getter for the predicate property.
  -     * @return value of the predicate property.
  -     */
  -    public Predicate getPredicate() {
  -        return predicate;
  +        super(predicate);
       }
  -    /** 
  -     * Setter for the predicate property.
  -     * @param predicate new value for the predicate property.
  -     */
  -    public void setPredicate(Predicate predicate) {
  -        this.predicate = predicate;
  -    }
  -
  -    // Private Methods
  -    //-------------------------------------------------------------------------
  -
  -    private void clearNextObject() {
  -        nextObject = null;
  -        nextObjectSet = false;
  -    }
  -
  -    private boolean setNextObject() {
  -        ListIterator iterator = getListIterator();
  -        Predicate predicate = getPredicate();
  -        
  -        // if previousObjectSet,
  -        // then we've walked back one step in the 
  -        // underlying list (due to a hasPrevious() call)
  -        // so skip ahead one matching object
  -        if(previousObjectSet) {
  -            clearPreviousObject();
  -            if(!setNextObject()) {
  -                return false;
  -            } else {
  -                clearNextObject();
  -            }
  -        }
  -
  -        while(iterator.hasNext()) {
  -            Object object = iterator.next();
  -            if(predicate.evaluate(object)) {
  -                nextObject = object;
  -                nextObjectSet = true;
  -                return true;
  -            }
  -        }
  -        return false;
  -    }
  -
  -    private void clearPreviousObject() {
  -        previousObject = null;
  -        previousObjectSet = false;
  -    }
  -
  -    private boolean setPreviousObject() {
  -        ListIterator iterator = getListIterator();
  -        Predicate predicate = getPredicate();
  -        
  -        // if nextObjectSet,
  -        // then we've walked back one step in the 
  -        // underlying list (due to a hasNext() call)
  -        // so skip ahead one matching object
  -        if(nextObjectSet) {
  -            clearNextObject();
  -            if(!setPreviousObject()) {
  -                return false;
  -            } else {
  -                clearPreviousObject();
  -            }
  -        }
  -
  -        while(iterator.hasPrevious()) {
  -            Object object = iterator.previous();
  -            if(predicate.evaluate(object)) {
  -                previousObject = object;
  -                previousObjectSet = true;
  -                return true;
  -            }
  -        }
  -        return false;
  -    }
  -
  -    // Attributes
  -    //-------------------------------------------------------------------------
  -
  -    /** Holds value of property "predicate". */
  -    private Predicate predicate;
   
  -    /** 
  -     * The value of the next (matching) object, when 
  -     * {@link #nextObjectSet} is true. 
  -     */
  -    private Object nextObject;
  -
  -    /** 
  -     * Whether or not the {@link #nextObject} has been set
  -     * (possibly to <code>null</code>). 
  -     */
  -    private boolean nextObjectSet = false;   
  -
  -    /** 
  -     * The value of the previous (matching) object, when 
  -     * {@link #previousObjectSet} is true. 
  -     */
  -    private Object previousObject;
  -
  -    /** 
  -     * Whether or not the {@link #previousObject} has been set
  -     * (possibly to <code>null</code>). 
  -     */
  -    private boolean previousObjectSet = false;   
  -
  -    /** 
  -     * The index of the element that would be returned by {@link #next}.
  -     */
  -    private int nextIndex = 0;
   }
  
  
  
  1.6       +8 -50     jakarta-commons/collections/src/java/org/apache/commons/collections/IteratorEnumeration.java
  
  Index: IteratorEnumeration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/IteratorEnumeration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- IteratorEnumeration.java	15 Aug 2002 20:04:31 -0000	1.5
  +++ IteratorEnumeration.java	15 Aug 2002 23:13:51 -0000	1.6
  @@ -67,11 +67,11 @@
     *
     * @since 1.0
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  +  * @deprecated this class has been moved to the iterators subpackage
     */
   
  -public class IteratorEnumeration implements Enumeration {
  -    
  -    private Iterator iterator;
  +public class IteratorEnumeration 
  +extends org.apache.commons.collections.iterators.IteratorEnumeration {
       
       /**
        *  Constructs a new <Code>IteratorEnumeration</Code> that will not 
  @@ -79,6 +79,7 @@
        *  invoked.
        */
       public IteratorEnumeration() {
  +        super();
       }
   
       /**
  @@ -88,51 +89,8 @@
        *  @param iterator  the iterator to use
        */
       public IteratorEnumeration( Iterator iterator ) {
  -        this.iterator = iterator;
  -    }
  -
  -    // Iterator interface
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Returns true if the underlying iterator has more elements.
  -     *
  -     *  @return true if the underlying iterator has more elements
  -     */
  -    public boolean hasMoreElements() {
  -        return iterator.hasNext();
  -    }
  -
  -    /**
  -     *  Returns the next element from the underlying iterator.
  -     *
  -     *  @return the next element from the underlying iterator.
  -     *  @throws NoSuchElementException  if the underlying iterator has no
  -     *    more elements
  -     */
  -    public Object nextElement() {
  -        return iterator.next();
  +        super(iterator);
       }
   
  -    // Properties
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Returns the underlying iterator.
  -     * 
  -     *  @return the underlying iterator
  -     */
  -    public Iterator getIterator() {
  -        return iterator;
  -    }
  -
  -    /**
  -     *  Sets the underlying iterator.
  -     *
  -     *  @param iterator  the new underlying iterator
  -     */
  -    public void setIterator( Iterator iterator ) {
  -        this.iterator = iterator;
  -    }
       
   }
  
  
  
  1.6       +9 -54     jakarta-commons/collections/src/java/org/apache/commons/collections/ProxyIterator.java
  
  Index: ProxyIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ProxyIterator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProxyIterator.java	15 Aug 2002 20:04:31 -0000	1.5
  +++ ProxyIterator.java	15 Aug 2002 23:13:51 -0000	1.6
  @@ -69,18 +69,18 @@
     * @version $Revision$ $Date$
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  +  * @deprecated this class has been moved to the iterators subpackage
     */
   
  -public class ProxyIterator implements Iterator {
  -    
  -    /** Holds value of property iterator. */
  -    private Iterator iterator;
  +public class ProxyIterator
  +extends org.apache.commons.collections.iterators.ProxyIterator {
       
       /**
        *  Constructs a new <Code>ProxyIterator</Code> that will not function
        *  until {@link #setIterator(Iterator)} is called.
        */
       public ProxyIterator() {
  +        super();
       }
       
       /**
  @@ -90,52 +90,7 @@
        *  @param iterator  the underyling iterator
        */
       public ProxyIterator( Iterator iterator ) {
  -        this.iterator = iterator;
  -    }
  -
  -    // Iterator interface
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Returns true if the underlying iterator has more elements.
  -     *
  -     *  @return true if the underlying iterator has more elements
  -     */
  -    public boolean hasNext() {
  -        return getIterator().hasNext();
  -    }
  -
  -    /**
  -     *  Returns the next element from the underlying iterator.
  -     *
  -     *  @return the next element from the underlying iterator
  -     *  @throws NoSuchElementException  if the underlying iterator 
  -     *    raises it because it has no more elements
  -     */
  -    public Object next() {
  -        return getIterator().next();
  -    }
  -
  -    /**
  -     *  Removes the last returned element from the collection that spawned
  -     *  the underlying iterator.
  -     */
  -    public void remove() {
  -        getIterator().remove();
  +        super(iterator);
       }
   
  -    // Properties
  -    //-------------------------------------------------------------------------
  -    /** Getter for property iterator.
  -     * @return Value of property iterator.
  -     */
  -    public Iterator getIterator() {
  -        return iterator;
  -    }
  -    /** Setter for property iterator.
  -     * @param iterator New value of property iterator.
  -     */
  -    public void setIterator(Iterator iterator) {
  -        this.iterator = iterator;
  -    }
   }
  
  
  
  1.4       +9 -115    jakarta-commons/collections/src/java/org/apache/commons/collections/ProxyListIterator.java
  
  Index: ProxyListIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ProxyListIterator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProxyListIterator.java	15 Aug 2002 20:04:31 -0000	1.3
  +++ ProxyListIterator.java	15 Aug 2002 23:13:51 -0000	1.4
  @@ -70,8 +70,10 @@
    * @see ProxyIterator
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  + * @deprecated this class has been moved to the iterators subpackage
    */
  -public class ProxyListIterator implements ListIterator {
  +public class ProxyListIterator 
  +extends org.apache.commons.collections.iterators.ProxyListIterator {
   
       // Constructor
       //-------------------------------------------------------------------------
  @@ -82,6 +84,7 @@
        *  is invoked.
        */
       public ProxyListIterator() {
  +        super();
       }
   
       /**
  @@ -91,117 +94,8 @@
        *  @param iterator  the list iterator to use
        */
       public ProxyListIterator(ListIterator iterator) {
  -        this.iterator = iterator;
  +        super(iterator);
       }
  -
  -    // ListIterator interface
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#add(Object)} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public void add(Object o) {
  -        getListIterator().add(o);
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#hasNext()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public boolean hasNext() {
  -        return getListIterator().hasNext();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#hasPrevious()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public boolean hasPrevious() {
  -        return getListIterator().hasPrevious();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#next()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public Object next() {
  -        return getListIterator().next();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#nextIndex()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public int nextIndex() {
  -        return getListIterator().nextIndex();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#previous()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public Object previous() {
  -        return getListIterator().previous();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#previousIndex()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public int previousIndex() {
  -        return getListIterator().previousIndex();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#remove()} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public void remove() {
  -        getListIterator().remove();
  -    }
  -
  -    /**
  -     *  Invokes the underlying {@link ListIterator#set(Object)} method.
  -     *
  -     *  @throws NullPointerException  if the underyling iterator is null
  -     */
  -    public void set(Object o) {
  -        getListIterator().set(o);
  -    }
  -
  -    // Properties
  -    //-------------------------------------------------------------------------
  -
  -    /** 
  -     * Getter for property iterator.
  -     * @return Value of property iterator.
  -     */
  -    public ListIterator getListIterator() {
  -        return iterator;
  -    }
  -
  -    /**
  -     * Setter for property iterator.
  -     * @param iterator New value of property iterator.
  -     */
  -    public void setListIterator(ListIterator iterator) {
  -        this.iterator = iterator;
  -    }
  -
  -    // Attributes
  -    //-------------------------------------------------------------------------
  -
  -    /** Holds value of property "iterator". */
  -    private ListIterator iterator;
   
   }
   
  
  
  
  1.7       +8 -43     jakarta-commons/collections/src/java/org/apache/commons/collections/SingletonIterator.java
  
  Index: SingletonIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SingletonIterator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SingletonIterator.java	15 Aug 2002 20:04:31 -0000	1.6
  +++ SingletonIterator.java	15 Aug 2002 23:13:51 -0000	1.7
  @@ -69,11 +69,10 @@
     * @since 2.0
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
     * @version $Revision$
  +  * @deprecated this class has been moved to the iterators subpackage
     */
  -public class SingletonIterator implements Iterator {
  -
  -    private boolean first = true;
  -    private Object object;
  +public class SingletonIterator 
  +extends org.apache.commons.collections.iterators.SingletonIterator {
       
       /**
        *  Constructs a new <Code>SingletonIterator</Code>.
  @@ -81,41 +80,7 @@
        *  @param object  the single object to return from the iterator
        */
       public SingletonIterator(Object object) {
  -        this.object = object;
  -    }
  -
  -    /**
  -     *  Returns true if the single object hasn't been returned yet.
  -     * 
  -     *  @return true if the single object hasn't been returned yet
  -     */
  -    public boolean hasNext() {
  -        return first;
  -    }
  -
  -    /**
  -     *  Returns the single object if it hasn't been returned yet.
  -     *
  -     *  @return the single object
  -     *  @throws NoSuchElementException if the single object has already been
  -     *    returned
  -     */
  -    public Object next() {
  -        if (! first ) {
  -            throw new NoSuchElementException();
  -        }
  -        Object answer = object;
  -        object = null;
  -        first = false;
  -        return answer;
  +        super(object);
       }
   
  -    /**
  -     *  Throws {@link UnsupportedOperationException}.
  -     *
  -     *  @throws UnsupportedOperationException always
  -     */
  -    public void remove() {
  -        throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
  -    }
   }
  
  
  
  1.6       +8 -48     jakarta-commons/collections/src/java/org/apache/commons/collections/TransformIterator.java
  
  Index: TransformIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TransformIterator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TransformIterator.java	15 Aug 2002 20:04:31 -0000	1.5
  +++ TransformIterator.java	15 Aug 2002 23:13:51 -0000	1.6
  @@ -68,13 +68,11 @@
     *
     * @since 1.0
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  +  * @deprecated this class has been moved to the iterators subpackage
     */
   
  -public class TransformIterator extends ProxyIterator {
  -    
  -    /** Holds value of property transformer. */
  -    private Transformer transformer;
  -    
  +public class TransformIterator 
  +extends org.apache.commons.collections.iterators.TransformIterator {
       
       /**
        *  Constructs a new <Code>TransformIterator</Code> that will not function
  @@ -82,6 +80,7 @@
        *  invoked.
        */
       public TransformIterator() {
  +        super();
       }
       
       /**
  @@ -103,46 +102,7 @@
        *  @param transformer  the transformer to use
        */
       public TransformIterator( Iterator iterator, Transformer transformer ) {
  -        super( iterator );
  -        this.transformer = transformer;
  -    }
  -
  -    // Iterator interface
  -    //-------------------------------------------------------------------------
  -    public Object next() {
  -        return transform( super.next() );
  +        super( iterator, transformer );
       }
   
  -    // Properties
  -    //-------------------------------------------------------------------------
  -    /** Getter for property transformer.
  -     * @return Value of property transformer.
  -     */
  -    public Transformer getTransformer() {
  -        return transformer;
  -    }
  -    /** Setter for property transformer.
  -     * @param transformer New value of property transformer.
  -     */
  -    public void setTransformer(Transformer transformer) {
  -        this.transformer = transformer;
  -    }
  -    
  -    // Implementation methods
  -    //-------------------------------------------------------------------------
  -
  -    /**
  -     *  Transforms the given object using the transformer.  If the 
  -     *  transformer is null, the original object is returned as-is.
  -     *
  -     *  @param source  the object to transform
  -     *  @return  the transformed object
  -     */
  -    protected Object transform( Object source ) {
  -        Transformer transformer = getTransformer();
  -        if ( transformer != null ) {
  -            return transformer.transform( source );
  -        }
  -        return source;
  -    }
   }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ArrayIterator.java
  
  Index: ArrayIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ArrayIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.lang.reflect.Array;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  
  /** Implements an {@link Iterator} over an array of objects.
    *
    * @since 1.0
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @author Mauricio S. Moura
    * @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
    * @version $Revision: 1.1 $
    */
  public class ArrayIterator implements Iterator {
      
      private Object array;
      private int length = 0;
      private int index = 0;
    
      
      /**
       *  Construct an ArrayIterator.  Using this constructor, the iterator is
       *  equivalent to an empty iterator until {@link #setArray(Object)} is
       *  called to establish the array to iterate over.
       **/
      public ArrayIterator() {
      }
     
      /**
       *  Construct an ArrayIterator that will iterate over the values in the
       *  specified array.
       *
       *  @param array the array to iterate over.
       *
       *  @exception IllegalArgumentException if <code>array</code> is not an
       *  array.
       *
       *  @exception NullPointerException 
       *  if <code>array</code> is <code>null</code>
       **/
      public ArrayIterator(Object array) {
          setArray( array );
      }
  
      /**
       *  Construct an ArrayIterator that will iterate over the values in the
       *  specified array.
       *
       *  @param array the array to iterate over.
       *  @param start the index to start iterating at.
       *
       *  @exception IllegalArgumentException if <code>array</code> is not an
       *  array.
       *
       *  @exception NullPointerException 
       *  if <code>array</code> is <code>null</code>
       **/
      public ArrayIterator(Object array, int start) {
          setArray( array );
          checkBound(start, "start");
          this.index = start;
      }
  
      /**
       *  Construct an ArrayIterator that will iterate over the values in the
       *  specified array.
       *
       *  @param array the array to iterate over.
       *  @param start the index to start iterating at.
       *  @param end the index to finish iterating at.
       *
       *  @exception IllegalArgumentException if <code>array</code> is not an
       *  array.
       *
       *  @exception NullPointerException 
       *  if <code>array</code> is <code>null</code>
       **/
      public ArrayIterator(Object array, int start, int end) {
          setArray( array );
          checkBound(start, "start");
          checkBound(end, "end");
          if(end <= start) {
              throw new IllegalArgumentException(
                  "End index must be greater than start index. "
              );
          }
          this.index = start;
          this.length = end;
      }
  
      private void checkBound(int bound, String type ) {
          if(bound > this.length) {
              throw new ArrayIndexOutOfBoundsException(
                "Attempt to make an ArrayIterator that "+type+
                "s beyond the end of the array. "
              );
          }
          if(bound < 0) {
              throw new ArrayIndexOutOfBoundsException(
                "Attempt to make an ArrayIterator that "+type+
                "s before the start of the array. "
              );
          }
      }
  
      // Iterator interface
      //-------------------------------------------------------------------------
  
      /**
       *  Returns true if there are more elements to return from the array.
       *
       *  @return true if there is a next element to return
       */
      public boolean hasNext() {
          return index < length;
      }
  
      /**
       *  Returns the next element in the array.
       *
       *  @return the next element in the array
       *  @throws NoSuchElementException if all the elements in the array
       *    have already been returned
       */
      public Object next() {
          if(!hasNext()) {
              throw new NoSuchElementException();
          }
          return Array.get( array, index++ );
      }
  
      /**
       *  Throws {@link UnsupportedOperationException}.
       *
       *  @throws UnsupportedOperationException always
       */
      public void remove() {
          throw new UnsupportedOperationException( "remove() method is not supported" );
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /**
       *  Retrieves the array that this iterator is iterating over. 
       *
       *  @return the array this iterator iterates over, or <code>null</code> if
       *  the no-arg constructor was used and {@link #setArray(Object)} has never
       *  been called with a valid array.
       **/
      public Object getArray() {
          return array;
      }
      
      /**
       *  Changes the array that the ArrayIterator should iterate over.  If an
       *  array has previously been set (using the single-arg constructor or this
       *  method), that array along with the current iterator position within
       *  that array is discarded in favor of the argument to this method.  This
       *  method can be used in combination with {@link #getArray()} to "reset"
       *  the iterator to the beginning of the array:
       *
       *  <pre>
       *    ArrayIterator iterator = ...
       *    ...
       *    iterator.setArray(iterator.getArray());
       *  </pre>
       *
       *  Note: Using i.setArray(i.getArray()) may throw a NullPointerException
       *  if no array has ever been set for the iterator (see {@link
       *  #getArray()})
       *
       *  @param array the array that the iterator should iterate over.
       *
       *  @exception IllegalArgumentException if <code>array</code> is not an
       *  array.
       *
       *  @exception NullPointerException 
       *  if <code>array</code> is <code>null</code>
       **/
      public void setArray( Object array ) {
          // Array.getLength throws IllegalArgumentException if the object is not
          // an array or NullPointerException if the object is null.  This call
          // is made before saving the array and resetting the index so that the
          // array iterator remains in a consistent state if the argument is not
          // an array or is null.
          this.length = Array.getLength( array );
          this.array = array;
          this.index = 0;
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/CollatingIterator.java
  
  Index: CollatingIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/CollatingIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Comparator;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import java.util.ArrayList;
  import java.util.BitSet;
  
  /**
   * Provides an ordered iteration over the elements contained in
   * a collection of ordered {@link Iterator}s.  In other words,
   * given two ordered {@link Iterator}s <code>A</code> and <code>B</code>,
   * my {@link #next} method will return the lesser of 
   * <code>A.next()</code> and <code>B.next()</code>.
   *
   * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:51 $
   * @author Rodney Waldhoff
   * @since 2.1
   */
  public class CollatingIterator implements Iterator {
  
      //------------------------------------------------------------ Constructors
      
      /**
       *  Constructs a new <Code>CollatingIterator</Code>.  Natural sort order
       *  will be used, and child iterators will have to be manually added 
       *  using the {@link #addIterator(Iterator)} method.
       */
      public CollatingIterator() {
          this(null,2);
      }
      
      /**
       *  Constructs a new <Code>CollatingIterator</Code> that will used the
       *  specified comparator for ordering.  Child iterators will have to be 
       *  manually added using the {@link #addIterator(Iterator)} method.
       *
       *  @param comp  the comparator to use for ordering, or <Code>null</Code>
       *    to use natural sort order
       */
      public CollatingIterator(Comparator comp) {
          this(comp,2);
      }
      
      /**
       *  Constructs a new <Code>CollatingIterator</Code> that will used the
       *  specified comparator for ordering and have the specified initial
       *  capacity.  Child iterators will have to be 
       *  manually added using the {@link #addIterator(Iterator)} method.
       *
       *  @param comp  the comparator to use for ordering, or <Code>null</Code>
       *    to use natural sort order
       *  @param initIterCapacity  the initial capacity for the internal list
       *    of child iterators
       */
      public CollatingIterator(Comparator comp, int initIterCapacity) {
          iterators = new ArrayList(initIterCapacity);
          setComparator(comp);
      }
  
      /**
       *  Constructs a new <Code>CollatingIterator</Code> that will use the
       *  specified comparator to provide ordered iteration over the two
       *  given iterators.
       *
       *  @param comp  the comparator to use to sort, or null to use natural
       *    sort order
       *  @param a  the first child ordered iterator
       *  @param b  the second child ordered iterator
       */
      public CollatingIterator(Comparator comp, Iterator a, Iterator b) {
          this(comp,2);
          addIterator(a);
          addIterator(b);
      }
  
      //--------------------------------------------------------- Public Methods
  
      /**
       * Add the given {@link Iterator} to my collection to collate.
       * @throws IllegalStateException if I've already started iterating
       */
      public void addIterator(Iterator iter) throws IllegalStateException {
          checkNotStarted();
          iterators.add(iter);
      }
  
      /**
       * Set the {@link Comparator} by which I collate.
       * @throws IllegalStateException if I've already started iterating
       */
      public void setComparator(Comparator comp) throws IllegalStateException {
          checkNotStarted();
          comparator = comp;
      }
  
      /**
       * Get the {@link Comparator} by which I collate.
       */
      public Comparator getComparator() {
          return comparator;
      }
  
      //------------------------------------------------------- Iterator Methods
  
      /**
       *  Returns <Code>true</Code> if any child iterator has remaining elements.
       *
       *  @return true if this iterator has remaining elements
       */
      public boolean hasNext() {
          start();
          return anyValueSet(valueSet) || anyHasNext(iterators);
      }
  
      /**
       *  Returns the next ordered element from a child iterator.
       *
       *  @return the next ordered element
       *  @throws NoSuchElementException  if no child iterator has any more
       *    elements
       */
      public Object next() throws NoSuchElementException {
          if(!hasNext()) {
              throw new NoSuchElementException();
          } else {
              int leastIndex = least();
              if(leastIndex == -1) {
                  throw new NoSuchElementException();
              } else {
                  Object val = values.get(leastIndex);
                  clear(leastIndex);
                  lastReturned = leastIndex;
                  return val;
              }
          }        
      }
  
      /**
       *  Removes the last returned element from the child iterator that 
       *  produced it.
       *
       *  @throws IllegalStateException  if there is no last returned element,
       *    or if the last returned element has already been removed
       */
      public void remove() {
          if(-1 == lastReturned) {
              throw new NoSuchElementException("No value has been returned yet.");
          } else {
              Iterator iter = (Iterator)(iterators.get(lastReturned));
              iter.remove();
          }
      }
  
      //--------------------------------------------------------- Private Methods
  
      /** Initialize my collating state if it hasn't been already. */
      private void start() {
          if(null == values) {
              values = new ArrayList(iterators.size());
              valueSet = new BitSet(iterators.size());
              for(int i=0;i<iterators.size();i++) {
                  values.add(null);
                  valueSet.clear(i);
              }
          }
      }
  
      /** 
       * Set the {@link #values} and {@link #valueSet} attributes 
       * at position <i>i</i> to the next value of the 
       * {@link #iterators iterator} at position <i>i</i>, or 
       * clear them if the <i>i</i><sup>th</sup> iterator
       * has no next value.
       *
       * @return <tt>false</tt> iff there was no value to set
       */
      private boolean set(int i) {
          Iterator iter = (Iterator)(iterators.get(i));
          if(iter.hasNext()) {
              values.set(i,iter.next());
              valueSet.set(i);
              return true;
          } else {
              values.set(i,null);
              valueSet.clear(i);
              return false;
          }
      }
  
      /** 
       * Clear the {@link #values} and {@link #valueSet} attributes 
       * at position <i>i</i>.
       */
      private void clear(int i) {
          values.set(i,null);
          valueSet.clear(i);
      }
  
      /** 
       * Throw {@link IllegalStateException} iff I've been {@link #start started}.
       * @throws IllegalStateException iff I've been {@link #start started}
       */
      private void checkNotStarted() throws IllegalStateException {
          if(null != values) {
              throw new IllegalStateException("Can't do that after next or hasNext has been called.");
          }
      }
  
      /** 
       * Returns the index of the least element in {@link #values},
       * {@link #set(int) setting} any uninitialized values.
       */
      private int least() throws IllegalStateException {
          int leastIndex = -1;
          Object leastObject = null;                
          for(int i=0;i<values.size();i++) {
              if(!valueSet.get(i)) {
                  set(i);
              }
              if(valueSet.get(i)) {
                  if(leastIndex == -1) {
                      leastIndex = i;
                      leastObject = values.get(i);
                  } else {
                      Object curObject = values.get(i);
                      if(comparator.compare(curObject,leastObject) < 0) {
                          leastObject = curObject;
                          leastIndex = i;
                      }
                  }
              }
          }
          return leastIndex;
      }
  
      /**
       * Returns <code>true</code> iff any bit in the given set is 
       * <code>true</code>.
       */
      private boolean anyValueSet(BitSet set) {
          for(int i=0;i<set.size();i++) {
              if(set.get(i)) {
                  return true;
              }
          }
          return false;
      }
  
      /**
       * Returns <code>true</code> iff any {@link Iterator} 
       * in the given list has a next value.
       */
      private boolean anyHasNext(ArrayList iters) {
          for(int i=0;i<iters.size();i++) {
              Iterator iter = (Iterator)iters.get(i);
              if(iter.hasNext()) {
                  return true;
              }
          }
          return false;
      }
  
      //--------------------------------------------------------- Private Members
  
      /** My {@link Comparator}. */
      private Comparator comparator = null;
  
      /** My list of {@link Iterator}s. */
      private ArrayList iterators = null;
     
      /** {@link Iterator#next Next} objects peeked from each iterator. */
      private ArrayList values = null;
      
      /** Whether or not each {@link #values} element has been set. */
      private BitSet valueSet = null;
  
      /** Index of the {@link #iterators iterator} from whom the last returned value was obtained. */
      private int lastReturned = -1;
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/EnumerationIterator.java
  
  Index: EnumerationIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/EnumerationIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Collection;
  import java.util.Enumeration;
  import java.util.Iterator;
  
  /** Adapter to make {@link Enumeration Enumeration} instances appear
    * to be {@link Iterator Iterator} instances.
    *
    * @since 1.0
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
    */
  public class EnumerationIterator implements Iterator {
      
      private Collection collection;
  
      private Enumeration enumeration;
  
      private Object last;
      
      /**
       *  Constructs a new <Code>EnumerationIterator</Code> that will not
       *  function until {@link #setEnumeration(Enumeration)} is called.
       */
      public EnumerationIterator() {
          this(null, null);
      }
  
      /**
       *  Constructs a new <Code>EnumerationIterator</Code> that provides
       *  an iterator view of the given enumeration.
       *
       *  @param enumeration  the enumeration to use
       */
      public EnumerationIterator( Enumeration enumeration ) {
          this(enumeration, null);
      }
  
      /**
       *  Constructs a new <Code>EnumerationIterator</Code> that will remove
       *  elements from the specified collection.
       *
       *  @param enum  the enumeration to use
       *  @param collection  the collection to remove elements form
       */
      public EnumerationIterator( Enumeration enum, Collection collection ) {
          this.enumeration = enum;
          this.collection = collection;
          this.last = null;
      }
  
      // Iterator interface
      //-------------------------------------------------------------------------
  
      /**
       *  Returns true if the underlying enumeration has more elements.
       *
       *  @return true if the underlying enumeration has more elements
       *  @throws NullPointerException  if the underlying enumeration is null
       */
      public boolean hasNext() {
          return enumeration.hasMoreElements();
      }
  
      /**
       *  Returns the next object from the enumeration.
       *
       *  @return the next object from the enumeration
       *  @throws NullPointerException if the enumeration is null
       */
      public Object next() {
          last = enumeration.nextElement();
          return last;
      }
  
      /**
       * Functions if an associated <code>Collection</code> is known.
       * If so, the first occurrence of the last returned object from this
       * iterator will be removed from the collection.
       *
       * @exception IllegalStateException <code>next()</code> not called.
       * @exception UnsupportedOperationException No associated
       * <code>Collection</code>.
       */
      public void remove() {
          if (collection != null) {
              if (last != null) {
                  collection.remove(last);
              }
              else {
                  throw new IllegalStateException
                      ("next() must have been called for remove() to function");
              }
          }
          else {
              throw new UnsupportedOperationException
                  ("No Collection associated with this Iterator");
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /**
       *  Returns the underlying enumeration.
       *
       *  @return the underlying enumeration
       */
      public Enumeration getEnumeration() {
          return enumeration;
      }
  
      /**
       *  Sets the underlying enumeration.
       *
       *  @param enumeration  the new underlying enumeration
       */
      public void setEnumeration( Enumeration enumeration ) {
          this.enumeration = enumeration;
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterIterator.java
  
  Index: FilterIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import org.apache.commons.collections.Predicate;
  
  
  /** A Proxy {@link Iterator Iterator} which takes a {@link Predicate Predicate} instance to filter
    * out objects from an underlying {@link Iterator Iterator} instance.
    * Only objects for which the
    * specified <code>Predicate</code> evaluates to <code>true</code> are
    * returned.
    *
    * @since 1.0
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @author Jan Sorensen
    */
  
  public class FilterIterator extends ProxyIterator {
      
      /** Holds value of property predicate. */
      private Predicate predicate;
  
      private Object nextObject;
      private boolean nextObjectSet = false;
      
      
      //-------------------------------------------------------------------------
  
      /**
       *  Constructs a new <Code>FilterIterator</Code> that will not function
       *  until {@link #setIterator(Iterator) setIterator} is invoked.
       */
      public FilterIterator() {
      }
      
      /**
       *  Constructs a new <Code>FilterIterator</Code> that will not function
       *  until {@link #setPredicate(Predicate) setPredicate} is invoked.
       *
       *  @param iterator  the iterator to use
       */
      public FilterIterator( Iterator iterator ) {
          super( iterator );
      }
  
      /**
       *  Constructs a new <Code>FilterIterator</Code> that will use the
       *  given iterator and predicate.
       *
       *  @param iterator  the iterator to use
       *  @param predicate  the predicate to use
       */
      public FilterIterator( Iterator iterator, Predicate predicate ) {
          super( iterator );
          this.predicate = predicate;
      }
  
      // Iterator interface
      //-------------------------------------------------------------------------
      
      /** 
       *  Returns true if the underlying iterator contains an object that 
       *  matches the predicate.
       *
       *  @return true if there is another object that matches the predicate 
       */
      public boolean hasNext() {
          if ( nextObjectSet ) {
              return true;
          } else {
              return setNextObject();
          }
      }
  
      /** 
       *  Returns the next object that matches the predicate.
       * 
       *  @return the next object which matches the given predicate
       *  @throws NoSuchElementException if there are no more elements that
       *   match the predicate 
       */
      public Object next() {
          if ( !nextObjectSet ) {
              if (!setNextObject()) {
                  throw new NoSuchElementException();
              }
          }
          nextObjectSet = false;
          return nextObject;
      }
  
      /**
       * Always throws UnsupportedOperationException as this class 
       * does look-ahead with its internal iterator.
       *
       * @throws UnsupportedOperationException  always
       */
      public void remove() {
          throw new UnsupportedOperationException();
      }
          
  
      // Properties
      //-------------------------------------------------------------------------
      /** Getter for property predicate.
       * @return Value of property predicate.
       */
      public Predicate getPredicate() {
          return predicate;
      }
      /** Setter for property predicate.
       * @param predicate New value of property predicate.
       */
      public void setPredicate(Predicate predicate) {
          this.predicate = predicate;
      }
  
      /**
       * Set nextObject to the next object. If there are no more 
       * objects then return false. Otherwise, return true.
       */
      private boolean setNextObject() {
          Iterator iterator = getIterator();
          Predicate predicate = getPredicate();
          while ( iterator.hasNext() ) {
              Object object = iterator.next();
              if ( predicate.evaluate( object ) ) {
                  nextObject = object;
                  nextObjectSet = true;
                  return true;
              }
          }
          return false;
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
  
  Index: FilterListIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterListIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.ListIterator;
  import java.util.NoSuchElementException;
  import org.apache.commons.collections.Predicate;
  
  /** 
    * A proxy {@link ListIterator ListIterator} which 
    * takes a {@link Predicate Predicate} instance to filter
    * out objects from an underlying <code>ListIterator</code> 
    * instance. Only objects for which the specified 
    * <code>Predicate</code> evaluates to <code>true</code> are
    * returned by the iterator.
    * 
    * @since 2.0
    * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:51 $
    * @author Rodney Waldhoff
    */
  public class FilterListIterator extends ProxyListIterator {
  
      // Constructors    
      //-------------------------------------------------------------------------
      
      /**
       *  Constructs a new <Code>FilterListIterator</Code> that will not 
       *  function until 
       *  {@link ProxyListIterator#setListIterator(ListIterator) setListIterator}
       *  and {@link #setPredicate(Predicate) setPredicate} are invoked.
       */
      public FilterListIterator() {
      }
  
      /**
       *  Constructs a new <Code>FilterListIterator</Code> that will not 
       *  function until {@link #setPredicate(Predicate) setPredicate} is invoked.
       *
       *  @param iterator  the iterator to use
       */
      public FilterListIterator(ListIterator iterator ) {
          super(iterator);
      }
  
      /**
       *  Constructs a new <Code>FilterListIterator</Code>.
       *
       *  @param iterator  the iterator to use
       *  @param predicate  the predicate to use
       */
      public FilterListIterator(ListIterator iterator, Predicate predicate) {
          super(iterator);
          this.predicate = predicate;
      }
  
      /**
       *  Constructs a new <Code>FilterListIterator</Code> that will not 
       *  function until 
       *  {@link ProxyListIterator#setListIterator(ListIterator) setListIterator}
       *  is invoked.
       *
       *  @param predicate  the predicate to use.
       */
      public FilterListIterator(Predicate predicate) {
          this.predicate = predicate;
      }
  
      // ListIterator interface
      //-------------------------------------------------------------------------
  
      /** Not supported. */
      public void add(Object o) {
          throw new UnsupportedOperationException("FilterListIterator.add(Object) is not supported.");
      }
  
      public boolean hasNext() {
          if(nextObjectSet) {
              return true;
          } else {
              return setNextObject();
          }
      }
  
      public boolean hasPrevious() {
          if(previousObjectSet) {
              return true;
          } else {
              return setPreviousObject();
          }
      }
  
      public Object next() {
          if(!nextObjectSet) {
              if(!setNextObject()) {
                  throw new NoSuchElementException();
              }
          }
          nextIndex++;
          Object temp = nextObject;
          clearNextObject();
          return temp;
      }
  
      public int nextIndex() {
          return nextIndex;
      }
  
      public Object previous() {
          if(!previousObjectSet) {
              if(!setPreviousObject()) {
                  throw new NoSuchElementException();
              }
          }
          nextIndex--;
          Object temp = previousObject;
          clearPreviousObject();
          return temp;
      }
  
      public int previousIndex() {
          return (nextIndex-1);
      }
  
      /** Not supported. */
      public void remove() {
          throw new UnsupportedOperationException("FilterListIterator.remove() is not supported.");
      }
  
      /** Not supported. */
      public void set(Object o) {
          throw new UnsupportedOperationException("FilterListIterator.set(Object) is not supported.");
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /** 
       * Getter for the predicate property.
       * @return value of the predicate property.
       */
      public Predicate getPredicate() {
          return predicate;
      }
      /** 
       * Setter for the predicate property.
       * @param predicate new value for the predicate property.
       */
      public void setPredicate(Predicate predicate) {
          this.predicate = predicate;
      }
  
      // Private Methods
      //-------------------------------------------------------------------------
  
      private void clearNextObject() {
          nextObject = null;
          nextObjectSet = false;
      }
  
      private boolean setNextObject() {
          ListIterator iterator = getListIterator();
          Predicate predicate = getPredicate();
          
          // if previousObjectSet,
          // then we've walked back one step in the 
          // underlying list (due to a hasPrevious() call)
          // so skip ahead one matching object
          if(previousObjectSet) {
              clearPreviousObject();
              if(!setNextObject()) {
                  return false;
              } else {
                  clearNextObject();
              }
          }
  
          while(iterator.hasNext()) {
              Object object = iterator.next();
              if(predicate.evaluate(object)) {
                  nextObject = object;
                  nextObjectSet = true;
                  return true;
              }
          }
          return false;
      }
  
      private void clearPreviousObject() {
          previousObject = null;
          previousObjectSet = false;
      }
  
      private boolean setPreviousObject() {
          ListIterator iterator = getListIterator();
          Predicate predicate = getPredicate();
          
          // if nextObjectSet,
          // then we've walked back one step in the 
          // underlying list (due to a hasNext() call)
          // so skip ahead one matching object
          if(nextObjectSet) {
              clearNextObject();
              if(!setPreviousObject()) {
                  return false;
              } else {
                  clearPreviousObject();
              }
          }
  
          while(iterator.hasPrevious()) {
              Object object = iterator.previous();
              if(predicate.evaluate(object)) {
                  previousObject = object;
                  previousObjectSet = true;
                  return true;
              }
          }
          return false;
      }
  
      // Attributes
      //-------------------------------------------------------------------------
  
      /** Holds value of property "predicate". */
      private Predicate predicate;
  
      /** 
       * The value of the next (matching) object, when 
       * {@link #nextObjectSet} is true. 
       */
      private Object nextObject;
  
      /** 
       * Whether or not the {@link #nextObject} has been set
       * (possibly to <code>null</code>). 
       */
      private boolean nextObjectSet = false;   
  
      /** 
       * The value of the previous (matching) object, when 
       * {@link #previousObjectSet} is true. 
       */
      private Object previousObject;
  
      /** 
       * Whether or not the {@link #previousObject} has been set
       * (possibly to <code>null</code>). 
       */
      private boolean previousObjectSet = false;   
  
      /** 
       * The index of the element that would be returned by {@link #next}.
       */
      private int nextIndex = 0;
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/IteratorChain.java
  
  Index: IteratorChain.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/IteratorChain.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.NoSuchElementException;
  
  /**
   * <p>An IteratorChain is an Iterator that wraps one or
   * more Iterators.  When any method from the
   * Iterator interface is called, the IteratorChain will
   * proxy to a single underlying Iterator.  The 
   * IteratorChain will invoke the Iterators in sequence until 
   * all Iterators are exhausted completely.</p>
   * 
   * <p>Under many circumstances, linking Iterators together
   * in this manner is more efficient (and convenient)
   * than reading out the contents of each Iterator into a
   * List and creating a new Iterator.</p>
   * 
   * <p>Calling a method that adds new Iterator<i>after
   * a method in the Iterator interface
   * has been called</i> will result in an
   * UnsupportedOperationException.  However, <i>take care</i>
   * to not alter the underlying List of Iterators.</p>
   * 
   * @author Morgan Delagrange
   * @version $Id: IteratorChain.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * @since 2.1
   */
  public class IteratorChain implements Iterator {
  
      protected List iteratorChain = null;
      protected int currentIteratorIndex = 0;
      protected Iterator currentIterator = null;
      // the "last used" Iterator is the Iterator upon which
      // next() or hasNext() was most recently called
      // used for the remove() operation only
      protected Iterator lastUsedIterator = null;
  
      // ComparatorChain is "locked" after the first time
      // compare(Object,Object) is called
      protected boolean isLocked = false;
  
      /**
       * Construct an IteratorChain with no Iterators.
       * You must add at least Iterator before calling
       * any method from the Iterator interface, or an 
       * UnsupportedOperationException is thrown
       */
      public IteratorChain() {
          this(new ArrayList());
      }
  
      /**
       * Construct an IteratorChain with a single Iterator.
       * 
       * @param iterator first Iterator in the IteratorChain
       */
      public IteratorChain(Iterator iterator) {
          iteratorChain = new ArrayList();
          iteratorChain.add(iterator);
      }
  
      /**
       * Construct an IteratorChain from the Iterators in the
       * List.
       * 
       * @param list   List of Iterators
       */
      public IteratorChain(List list) {
          iteratorChain = list;
      }
  
      /**
       * Add an Iterator to the end of the chain 
       * 
       * @param iterator Iterator to add
       */
      public void addIterator(Iterator iterator) {
          checkLocked();
  
          iteratorChain.add(iterator);
      }
  
      /**
       * Replace the Iterator at the given index     
       * 
       * @param index      index of the Iterator to replace
       * @param iterator   Iterator to place at the given index
       * @exception IndexOutOfBoundsException
       *                   if index < 0 or index > size()
       */
      public void setIterator(int index, Iterator iterator) 
      throws IndexOutOfBoundsException {
          checkLocked();
  
          iteratorChain.set(index,iterator);
      }
  
      /**
       * Number of Iterators in the current IteratorChain.
       * 
       * @return Iterator count
       */
      public int size() {
          return iteratorChain.size();
      }
  
      /**
       * Determine if modifications can still be made to the
       * IteratorChain.  IteratorChains cannot be modified
       * once they have executed a method from the Iterator
       * interface.
       * 
       * @return true = IteratorChain cannot be modified; false = 
       *         IteratorChain can still be modified.
       */
      public boolean isLocked() {
          return isLocked;
      }
  
      // throw an exception if the IteratorChain is locked
      private void checkLocked() {
          if (isLocked == true) {
              throw new UnsupportedOperationException("IteratorChain cannot be changed after the first use of a method from the Iterator interface");
          }
      }
  
      private void checkChainIntegrity() {
          if (iteratorChain.size() == 0) {
              throw new UnsupportedOperationException("IteratorChains must contain at least one Iterator");
          }
      }
  
      // you MUST call this method whenever you call a method in the Iterator interface, because
      // this method also assigns the initial value of the currentIterator variable
      private void lockChain() {
          if (isLocked == false) {
              checkChainIntegrity();
              isLocked = true;
          }
      }
  
      // call this before any Iterator method to make sure that the current Iterator
      // is not exhausted
      protected void updateCurrentIterator() {
          if (currentIterator == null) {
              currentIterator = (Iterator) iteratorChain.get(0);
              // set last used iterator here, in case the user calls remove
              // before calling hasNext() or next() (although they shouldn't)
              lastUsedIterator = currentIterator;
              return;
          }
  
          if (currentIteratorIndex == (iteratorChain.size() - 1)) {
              return;
          }
  
          while (currentIterator.hasNext() == false) {
              ++currentIteratorIndex;
              currentIterator = (Iterator) iteratorChain.get(currentIteratorIndex);
  
              if (currentIteratorIndex == (iteratorChain.size() - 1)) {
                  return;
              }
          }
      }
  
      /**
       * Return true if any Iterator in the IteratorChain has a remaining
       * element.
       * 
       * @return true if elements remain
       * @exception UnsupportedOperationException
       *                   if the IteratorChain does not contain at least one
       *                   Iterator
       */
      public boolean hasNext() throws UnsupportedOperationException {
          lockChain();
          updateCurrentIterator();
          lastUsedIterator = currentIterator;
  
          return currentIterator.hasNext();
      }
  
      /**
       * Returns the next Object of the current Iterator
       * 
       * @return Object from the current Iterator
       * @exception NoSuchElementException
       *                   if all the Iterators are exhausted
       * @exception UnsupportedOperationException
       *                   if the IteratorChain does not contain at least one
       *                   Iterator
       */
      public Object next() throws NoSuchElementException, UnsupportedOperationException {
          lockChain();
          updateCurrentIterator();
          lastUsedIterator = currentIterator;
  
          return currentIterator.next();
      }
  
      /**
       * Removes from the underlying collection the last element 
       * returned by the Iterator.  As with next() and hasNext(),
       * this method calls remove() on the underlying Iterator.
       * Therefore, this method may throw an 
       * UnsupportedOperationException if the underlying
       * Iterator does not support this method. 
       * 
       * @exception UnsupportedOperationException
       *                   if the remove operator is not supported by the underlying
       *                   Iterator or if there are no Iterators in the IteratorChain
       * @exception IllegalStateException
       *                   if the next method has not yet been called, or the
       *                   remove method has already been called after the last
       *                   call to the next method.
       */
      public void remove() throws UnsupportedOperationException, IllegalStateException  {
          lockChain();
          updateCurrentIterator();
  
          lastUsedIterator.remove();
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/IteratorEnumeration.java
  
  Index: IteratorEnumeration.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/IteratorEnumeration.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Enumeration;
  import java.util.Iterator;
  
  /** Adapter to make an {@link Iterator Iterator} instance appear to be an {@link Enumeration Enumeration} instances
    *
    * @since 1.0
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    */
  
  public class IteratorEnumeration implements Enumeration {
      
      private Iterator iterator;
      
      /**
       *  Constructs a new <Code>IteratorEnumeration</Code> that will not 
       *  function until {@link #setIterator(Iterator) setIterator} is  
       *  invoked.
       */
      public IteratorEnumeration() {
      }
  
      /**
       *  Constructs a new <Code>IteratorEnumeration</Code> that will use
       *  the given iterator. 
       * 
       *  @param iterator  the iterator to use
       */
      public IteratorEnumeration( Iterator iterator ) {
          this.iterator = iterator;
      }
  
      // Iterator interface
      //-------------------------------------------------------------------------
  
      /**
       *  Returns true if the underlying iterator has more elements.
       *
       *  @return true if the underlying iterator has more elements
       */
      public boolean hasMoreElements() {
          return iterator.hasNext();
      }
  
      /**
       *  Returns the next element from the underlying iterator.
       *
       *  @return the next element from the underlying iterator.
       *  @throws NoSuchElementException  if the underlying iterator has no
       *    more elements
       */
      public Object nextElement() {
          return iterator.next();
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /**
       *  Returns the underlying iterator.
       * 
       *  @return the underlying iterator
       */
      public Iterator getIterator() {
          return iterator;
      }
  
      /**
       *  Sets the underlying iterator.
       *
       *  @param iterator  the new underlying iterator
       */
      public void setIterator( Iterator iterator ) {
          this.iterator = iterator;
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java
  
  Index: ListIteratorWrapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.ListIterator;
  import java.util.NoSuchElementException;
  
  /**
   * As the wrapped Iterator is traversed, ListIteratorWrapper
   * builds a LinkedList of its values, permitting all required
   * operations of ListIterator.
   * 
   * @author Morgan Delagrange
   * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:51 $
   * @since 2.1
   */
  public class ListIteratorWrapper implements ListIterator {
  
      // Constructor
      //-------------------------------------------------------------------------
  
      /**
       *  Constructs a new <Code>ListIteratorWrapper</Code> that will wrap
       *  the given iterator.
       *
       *  @param iterator  the iterator to wrap
       */
      public ListIteratorWrapper(Iterator iterator) {
          this.iterator = iterator;
      }
  
      // ListIterator interface
      //-------------------------------------------------------------------------
  
      /**
       *  Throws {@link UnsupportedOperationException}.
       *
       *  @param o  ignored
       *  @throws UnsupportedOperationException always
       */
      public void add(Object o) throws UnsupportedOperationException {
          throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE);
      }
  
  
      /**
       *  Returns true if there are more elements in the iterator.
       *
       *  @return true if there are more elements
       */
      public boolean hasNext() {
          if (currentIndex == wrappedIteratorIndex) {
              return iterator.hasNext();
          }
  
          return true;
      }
  
      /**
       *  Returns true if there are previous elements in the iterator.
       *
       *  @return true if there are previous elements
       */
      public boolean hasPrevious() {
          if (currentIndex == 0) {
              return false;
          }
  
          return true;
      }
  
      /**
       *  Returns the next element from the iterator.
       *
       *  @return the next element from the iterator
       *  @throws NoSuchElementException if there are no more elements
       */
      public Object next() throws NoSuchElementException {
          if (currentIndex < wrappedIteratorIndex) {
              ++currentIndex;
              return list.get(currentIndex - 1);
          }
  
          Object retval = iterator.next();
          list.add(retval);
          ++currentIndex;
          ++wrappedIteratorIndex;
          return retval;
      }
  
      /**
       *  Returns in the index of the next element.
       *
       *  @return the index of the next element
       */
      public int nextIndex() {
          return currentIndex;
      }
  
      /**
       *  Returns the the previous element.
       *
       *  @return the previous element
       *  @throws NoSuchElementException  if there are no previous elements
       */
      public Object previous() throws NoSuchElementException {
          if (currentIndex == 0) {
              throw new NoSuchElementException();
          }
  
          --currentIndex;
          return list.get(currentIndex);    
      }
  
      /**
       *  Returns the index of the previous element.
       *
       *  @return  the index of the previous element
       */
      public int previousIndex() {
          return currentIndex - 1;
      }
  
      /**
       *  Throws {@link UnsupportedOperationException}.
       *
       *  @throws UnsupportedOperationException always
       */
      public void remove() throws UnsupportedOperationException {
          throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE);
      }
  
      /**
       *  Throws {@link UnsupportedOperationException}.
       *
       *  @param o  ignored
       *  @throws UnsupportedOperationException always
       */
      public void set(Object o) throws UnsupportedOperationException {
          throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE);
      }
  
      // Attributes
      //-------------------------------------------------------------------------
  
      /** Holds value of property "iterator". */
      private Iterator iterator = null;
      private LinkedList list = new LinkedList();
      
      // position of this iterator
      private int currentIndex = 0;
      // position of the wrapped iterator
      // this Iterator should only be used to populate the list
      private int wrappedIteratorIndex = 0;
  
      private static final String UNSUPPORTED_OPERATION_MESSAGE =
          "ListIteratorWrapper does not support optional operations of ListIterator.";
  
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyIterator.java
  
  Index: ProxyIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Iterator;
  
  /** A Proxy {@link Iterator Iterator} which delegates its methods to a proxy instance.
    *
    * @since 1.0
    * @see ProxyListIterator
    * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:51 $
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    */
  
  public class ProxyIterator implements Iterator {
      
      /** Holds value of property iterator. */
      private Iterator iterator;
      
      /**
       *  Constructs a new <Code>ProxyIterator</Code> that will not function
       *  until {@link #setIterator(Iterator)} is called.
       */
      public ProxyIterator() {
      }
      
      /**
       *  Constructs a new <Code>ProxyIterator</Code> that will use the
       *  given iterator.
       *
       *  @param iterator  the underyling iterator
       */
      public ProxyIterator( Iterator iterator ) {
          this.iterator = iterator;
      }
  
      // Iterator interface
      //-------------------------------------------------------------------------
  
      /**
       *  Returns true if the underlying iterator has more elements.
       *
       *  @return true if the underlying iterator has more elements
       */
      public boolean hasNext() {
          return getIterator().hasNext();
      }
  
      /**
       *  Returns the next element from the underlying iterator.
       *
       *  @return the next element from the underlying iterator
       *  @throws NoSuchElementException  if the underlying iterator 
       *    raises it because it has no more elements
       */
      public Object next() {
          return getIterator().next();
      }
  
      /**
       *  Removes the last returned element from the collection that spawned
       *  the underlying iterator.
       */
      public void remove() {
          getIterator().remove();
      }
  
      // Properties
      //-------------------------------------------------------------------------
      /** Getter for property iterator.
       * @return Value of property iterator.
       */
      public Iterator getIterator() {
          return iterator;
      }
      /** Setter for property iterator.
       * @param iterator New value of property iterator.
       */
      public void setIterator(Iterator iterator) {
          this.iterator = iterator;
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java
  
  Index: ProxyListIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.ListIterator;
  
  /**
   * A proxy {@link ListIterator ListIterator} which delegates its
   * methods to a proxy instance.
   *
   * @since 2.0
   * @see ProxyIterator
   * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:51 $
   * @author Rodney Waldhoff
   */
  public class ProxyListIterator implements ListIterator {
  
      // Constructor
      //-------------------------------------------------------------------------
  
      /**
       *  Constructs a new <Code>ProxyListIterator</Code> that will not 
       *  function until {@link #setListIterator(ListIterator) setListIterator}
       *  is invoked.
       */
      public ProxyListIterator() {
      }
  
      /**
       *  Constructs a new <Code>ProxyListIterator</Code> that will use the
       *  given list iterator.
       *
       *  @param iterator  the list iterator to use
       */
      public ProxyListIterator(ListIterator iterator) {
          this.iterator = iterator;
      }
  
      // ListIterator interface
      //-------------------------------------------------------------------------
  
      /**
       *  Invokes the underlying {@link ListIterator#add(Object)} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public void add(Object o) {
          getListIterator().add(o);
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#hasNext()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public boolean hasNext() {
          return getListIterator().hasNext();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#hasPrevious()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public boolean hasPrevious() {
          return getListIterator().hasPrevious();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#next()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public Object next() {
          return getListIterator().next();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#nextIndex()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public int nextIndex() {
          return getListIterator().nextIndex();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#previous()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public Object previous() {
          return getListIterator().previous();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#previousIndex()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public int previousIndex() {
          return getListIterator().previousIndex();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#remove()} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public void remove() {
          getListIterator().remove();
      }
  
      /**
       *  Invokes the underlying {@link ListIterator#set(Object)} method.
       *
       *  @throws NullPointerException  if the underyling iterator is null
       */
      public void set(Object o) {
          getListIterator().set(o);
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /** 
       * Getter for property iterator.
       * @return Value of property iterator.
       */
      public ListIterator getListIterator() {
          return iterator;
      }
  
      /**
       * Setter for property iterator.
       * @param iterator New value of property iterator.
       */
      public void setListIterator(ListIterator iterator) {
          this.iterator = iterator;
      }
  
      // Attributes
      //-------------------------------------------------------------------------
  
      /** Holds value of property "iterator". */
      private ListIterator iterator;
  
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/SingletonIterator.java
  
  Index: SingletonIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/SingletonIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  
  /** <p><code>SingletonIterator</code> is an {@link Iterator} over a single 
    * object instance.</p>
    *
    * @since 2.0
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class SingletonIterator implements Iterator {
  
      private boolean first = true;
      private Object object;
      
      /**
       *  Constructs a new <Code>SingletonIterator</Code>.
       *
       *  @param object  the single object to return from the iterator
       */
      public SingletonIterator(Object object) {
          this.object = object;
      }
  
      /**
       *  Returns true if the single object hasn't been returned yet.
       * 
       *  @return true if the single object hasn't been returned yet
       */
      public boolean hasNext() {
          return first;
      }
  
      /**
       *  Returns the single object if it hasn't been returned yet.
       *
       *  @return the single object
       *  @throws NoSuchElementException if the single object has already been
       *    returned
       */
      public Object next() {
          if (! first ) {
              throw new NoSuchElementException();
          }
          Object answer = object;
          object = null;
          first = false;
          return answer;
      }
  
      /**
       *  Throws {@link UnsupportedOperationException}.
       *
       *  @throws UnsupportedOperationException always
       */
      public void remove() {
          throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/TransformIterator.java
  
  Index: TransformIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/TransformIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.Enumeration;
  import java.util.Iterator;
  import org.apache.commons.collections.Transformer;
  
  /** A Proxy {@link Iterator Iterator} which uses a {@link Transformer Transformer} instance to 
    * transform the contents of the {@link Iterator Iterator} into some other form
    *
    * @since 1.0
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    */
  
  public class TransformIterator extends ProxyIterator {
      
      /** Holds value of property transformer. */
      private Transformer transformer;
      
      
      /**
       *  Constructs a new <Code>TransformIterator</Code> that will not function
       *  until the {@link #setIterator(Iterator) setIterator} method is 
       *  invoked.
       */
      public TransformIterator() {
      }
      
      /**
       *  Constructs a new <Code>TransformIterator</Code> that won't transform
       *  elements from the given iterator.
       *
       *  @param iterator  the iterator to use
       */
      public TransformIterator( Iterator iterator ) {
          super( iterator );
      }
  
      /**
       *  Constructs a new <Code>TransformIterator</Code> that will use the
       *  given iterator and transformer.  If the given transformer is null,
       *  then objects will not be transformed.
       *
       *  @param iterator  the iterator to use
       *  @param transformer  the transformer to use
       */
      public TransformIterator( Iterator iterator, Transformer transformer ) {
          super( iterator );
          this.transformer = transformer;
      }
  
      // Iterator interface
      //-------------------------------------------------------------------------
      public Object next() {
          return transform( super.next() );
      }
  
      // Properties
      //-------------------------------------------------------------------------
      /** Getter for property transformer.
       * @return Value of property transformer.
       */
      public Transformer getTransformer() {
          return transformer;
      }
      /** Setter for property transformer.
       * @param transformer New value of property transformer.
       */
      public void setTransformer(Transformer transformer) {
          this.transformer = transformer;
      }
      
      // Implementation methods
      //-------------------------------------------------------------------------
  
      /**
       *  Transforms the given object using the transformer.  If the 
       *  transformer is null, the original object is returned as-is.
       *
       *  @param source  the object to transform
       *  @return  the transformed object
       */
      protected Object transform( Object source ) {
          Transformer transformer = getTransformer();
          if ( transformer != null ) {
              return transformer.transform( source );
          }
          return source;
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/UniqueFilterIterator.java
  
  Index: UniqueFilterIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/UniqueFilterIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import org.apache.commons.collections.Predicate;
  
  /** A FilterIterator which only returns "unique" Objects.  Internally,
    * the Iterator maintains a Set of objects it has already encountered,
    * and duplicate Objects are skipped.
    *
    * @author Morgan Delagrange
    * @version $Id: UniqueFilterIterator.java,v 1.1 2002/08/15 23:13:51 pjack Exp $
    * @since 2.1
    */
  
  public class UniqueFilterIterator extends FilterIterator {
         
      //-------------------------------------------------------------------------
      
      /**
       *  Constructs a new <Code>UniqueFilterIterator</Code>.
       *
       *  @param iterator  the iterator to use
       */
      public UniqueFilterIterator( Iterator iterator ) {
          super( iterator, new UniquePredicate() );
      }
  
      private static class UniquePredicate implements Predicate {
  
          HashSet set = new HashSet();
  
          public boolean evaluate(Object object) {
              return set.add(object);       
          }
  
      }
  
  }
  
  
  
  1.33      +5 -13     jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- TestAll.java	13 Aug 2002 00:26:52 -0000	1.32
  +++ TestAll.java	15 Aug 2002 23:13:52 -0000	1.33
  @@ -76,14 +76,11 @@
   
       public static Test suite() {
           TestSuite suite = new TestSuite();
  -        suite.addTest(TestArrayIterator.suite());
  -        suite.addTest(TestArrayIterator2.suite());
           suite.addTest(TestArrayStack.suite());
           suite.addTest(TestBeanMap.suite());
           suite.addTest(TestBinaryHeap.suite());
           suite.addTest(TestBoundedFifoBuffer.suite());
           suite.addTest(TestBoundedFifoBuffer2.suite());
  -        suite.addTest(TestCollatingIterator.suite());
           suite.addTest(TestCollectionUtils.suite());
           suite.addTest(TestBufferUtils.suite());
           suite.addTest(TestSetUtils.suite());
  @@ -100,22 +97,17 @@
           suite.addTest(TestFastHashMap1.suite());
           suite.addTest(TestFastTreeMap.suite());
           suite.addTest(TestFastTreeMap1.suite());
  -        suite.addTest(TestFilterIterator.suite());
  -        suite.addTest(TestFilterListIterator.suite());
           suite.addTest(TestHashBag.suite());
  -        suite.addTest(TestIteratorChain.suite());
  -        suite.addTest(TestListIteratorWrapper.suite());
           suite.addTest(TestLRUMap.suite());
           suite.addTest(TestMultiHashMap.suite());
           suite.addTest(TestReverseComparator.suite());
   	suite.addTest(TestNullComparator.suite());
           suite.addTest(TestSequencedHashMap.suite());
  -        suite.addTest(TestSingletonIterator.suite());
           suite.addTest(TestStaticBucketMap.suite());
           suite.addTest(TestTreeBag.suite());
           suite.addTest(TestUnboundedFifoBuffer.suite());
  -        suite.addTest(TestUniqueFilterIterator.suite());
           suite.addTest(TestReferenceMap.suite());
  +        suite.addTest(org.apache.commons.collections.iterators.TestAll.suite());
           suite.addTest(org.apache.commons.collections.primitives.TestAll.suite());
           return suite;
       }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestAll.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * Entry point for all Collections tests.
   * @author Rodney Waldhoff
   * @version $Id: TestAll.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestAll extends TestCase {
      public TestAll(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite();
          suite.addTest(TestArrayIterator.suite());
          suite.addTest(TestArrayIterator2.suite());
          suite.addTest(TestCollatingIterator.suite());
          suite.addTest(TestFilterIterator.suite());
          suite.addTest(TestFilterListIterator.suite());
          suite.addTest(TestIteratorChain.suite());
          suite.addTest(TestListIteratorWrapper.suite());
          suite.addTest(TestSingletonIterator.suite());
          suite.addTest(TestUniqueFilterIterator.suite());
          return suite;
      }
          
      public static void main(String args[]) {
          String[] testCaseName = { TestAll.class.getName() };
          junit.textui.TestRunner.main(testCaseName);
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestArrayIterator.java
  
  Index: TestArrayIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestArrayIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  
  /**
   * Tests the ArrayIterator to ensure that the next() method will actually
   * perform the iteration rather than the hasNext() method.
   * The code of this test was supplied by Mauricio S. Moura
   * 
   * @author James Strachan
   * @author Mauricio S. Moura
   * @author Morgan Delagrange
   * @version $Id: TestArrayIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestArrayIterator extends TestIterator {
      
      protected String[] testArray = {
          "One", "Two", "Three"
      };
      
      public static Test suite() {
          return new TestSuite(TestArrayIterator.class);
      }
      
      public TestArrayIterator(String testName) {
          super(testName);
      }
  
      public Iterator makeEmptyIterator() {
          return new ArrayIterator(new Object[0]);
      }
  
      public Iterator makeFullIterator() {
          return new ArrayIterator(testArray);
      }
      
      /**
       * Return a new, empty {@link Object} to used for testing.
       */
      public Object makeObject() {
          return makeFullIterator();
      }
      
      public void testIterator() {
          Iterator iter = (Iterator) makeFullIterator();
          for ( int i = 0; i < testArray.length; i++ ) {
              Object testValue = testArray[i];            
              Object iterValue = iter.next();
              
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
          
          assertTrue("Iterator should now be empty", ! iter.hasNext() );
  
  	try {
  	    Object testValue = iter.next();
  	} catch (Exception e) {
  	  assertTrue("NoSuchElementException must be thrown", 
  		 e.getClass().equals((new NoSuchElementException()).getClass()));
  	}
      }
  
      public void testNullArray() {
          try {
              Iterator iter = new ArrayIterator(null);
              
              fail("Constructor should throw a NullPointerException when " +
                   "constructed with a null array");
          } catch (NullPointerException e) {
              // expected
          }
  
          ArrayIterator iter = new ArrayIterator();
          try {
              iter.setArray(null);
  
              fail("setArray(null) should throw a NullPointerException");
          } catch (NullPointerException e) {
              // expected
          }
      }
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestArrayIterator2.java
  
  Index: TestArrayIterator2.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestArrayIterator2.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  
  /**
   * Tests the ArrayIterator with primitive type arrays
   * 
   * @author Morgan Delagrange
   * @author James Strachan
   * @version $Id: TestArrayIterator2.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestArrayIterator2 extends TestIterator {
      
      protected int[] testArray = {
          2, 4, 6, 8
      };
      
      public static Test suite() {
          return new TestSuite(TestArrayIterator2.class);
      }
      
      public TestArrayIterator2(String testName) {
          super(testName);
      }
      
      public Iterator makeEmptyIterator() {
          return new ArrayIterator(new int[0]);
      }
  
      public Iterator makeFullIterator() {
          return new ArrayIterator(testArray);
      }
  
      /**
       * Return a new, empty {@link Object} to used for testing.
       */
      public Object makeObject() {
          return makeFullIterator();
      }
      
      public void testIterator() {
          Iterator iter = (Iterator) makeFullIterator();
          for ( int i = 0; i < testArray.length; i++ ) {
              Integer testValue = new Integer( testArray[i] );            
              Number iterValue = (Number) iter.next();
              
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
          
          assertTrue("Iterator should now be empty", ! iter.hasNext() );
  
  	try {
  	    Object testValue = iter.next();
  	} catch (Exception e) {
  	  assertTrue("NoSuchElementException must be thrown", 
  		 e.getClass().equals((new NoSuchElementException()).getClass()));
  	}
      }
  
      // proves that an ArrayIterator set with the constructor has the same number of elements
      // as an ArrayIterator set with setArray(Object) 
      public void testSetArray() {
          Iterator iter1 = new ArrayIterator(testArray);
          int count1 = 0;
          while (iter1.hasNext()) {
              ++count1;
              iter1.next();
          }
  
          assertEquals("the count should be right using the constructor",
                       count1,testArray.length);
  
          ArrayIterator iter2 = new ArrayIterator();
          iter2.setArray(testArray);
          int count2 = 0;
          while (iter2.hasNext()) {
              ++count2;
              iter2.next();
          }
  
          assertEquals("the count should be right using setArray(Object)",
                       count2,testArray.length);
      }
  
      public void testIndexedArray() {
          Iterator iter = new ArrayIterator(testArray,2);
          int count = 0;
          while (iter.hasNext()) {
              ++count;
              iter.next();
          }
  
          assertEquals("the count should be right using ArrayIterator(Object,2) ",
                       count,testArray.length-2);
  
          iter = new ArrayIterator(testArray,1,testArray.length-1);
          count = 0;
          while (iter.hasNext()) {
              ++count;
              iter.next();
          }
  
          assertEquals("the count should be right using ArrayIterator(Object,1,"+
                       (testArray.length-1)+") ", count, testArray.length-2);
  
          try {
              iter = new ArrayIterator(testArray,-1);
              fail("new ArrayIterator(Object,-1) should throw an "+
                   "ArrayIndexOutOfBoundsException");
          } catch(ArrayIndexOutOfBoundsException aioobe) {
              // expected
          }
  
          try {
              iter = new ArrayIterator(testArray,testArray.length+1);
              fail("new ArrayIterator(Object,length+1) should throw an "+
                   "ArrayIndexOutOfBoundsException");
          } catch(ArrayIndexOutOfBoundsException aioobe) {
              // expected
          }
  
          try {
              iter = new ArrayIterator(testArray,0,-1);
              fail("new ArrayIterator(Object,0,-1) should throw an "+
                   "ArrayIndexOutOfBoundsException");
          } catch(ArrayIndexOutOfBoundsException aioobe) {
              // expected
          }
  
          try {
              iter = new ArrayIterator(testArray,0,testArray.length+1);
              fail("new ArrayIterator(Object,0,length+1) should throw an "+
                   "ArrayIndexOutOfBoundsException");
          } catch(ArrayIndexOutOfBoundsException aioobe) {
              // expected
          }
  
          try {
              iter = new ArrayIterator(testArray,1,1);
              fail("new ArrayIterator(Object,1,1) should throw an "+
                   "IllegalArgumentException");
          } catch(IllegalArgumentException iae) {
              // expected
          }
  
          try {
              iter = new ArrayIterator(testArray,testArray.length-1,testArray.length-2);
              fail("new ArrayIterator(Object,length-2,length-1) should throw an "+
                   "IllegalArgumentException");
          } catch(IllegalArgumentException iae) {
              // expected
          }
      }
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java
  
  Index: TestCollatingIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.util.Iterator;
  import java.util.Comparator;
  import java.util.ArrayList;
  import org.apache.commons.collections.comparators.ComparableComparator;
  
  /**
   * Unit test suite for {@link CollatingIterator}.
   * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:52 $
   * @author Rodney Waldhoff
   */
  public class TestCollatingIterator extends TestIterator {
  
      //------------------------------------------------------------ Conventional
      
      public TestCollatingIterator(String testName) {
          super(testName);
      }
      
      public static Test suite() {
          return new TestSuite(TestCollatingIterator.class);
      }
  
      //--------------------------------------------------------------- Lifecycle
  
      private Comparator comparator = null;
      private ArrayList evens = null; 
      private ArrayList odds = null; 
      private ArrayList fib = null; 
  
      public void setUp() throws Exception {
          super.setUp();
          comparator = new ComparableComparator();
          evens = new ArrayList();
          odds = new ArrayList();
          for(int i=0;i<20;i++) {
              if(0 == i%2) {
                  evens.add(new Integer(i));
              } else {
                  odds.add(new Integer(i));
              }
          }
          fib = new ArrayList();
          fib.add(new Integer(1));
          fib.add(new Integer(1));
          fib.add(new Integer(2));
          fib.add(new Integer(3));
          fib.add(new Integer(5));
          fib.add(new Integer(8));
          fib.add(new Integer(13));
          fib.add(new Integer(21));
      }       
  
      //---------------------------------------------------- TestIterator Methods
      
      public Iterator makeEmptyIterator() {
          return new CollatingIterator(comparator);
      }
  
      public Iterator makeFullIterator() {
          CollatingIterator iter = new CollatingIterator(comparator);
          iter.addIterator(evens.iterator());
          iter.addIterator(odds.iterator());
          iter.addIterator(fib.iterator());
          return iter;
      }
  
      public Object makeObject() {
          return makeFullIterator();
      }
      
      public boolean supportsEmptyIterator() {
          return true;
      }
  
      //------------------------------------------------------------------- Tests
  
      public void testGetSetComparator() {
          CollatingIterator iter = new CollatingIterator();
          assertNull(iter.getComparator());
          iter.setComparator(comparator);
          assertSame(comparator,iter.getComparator());
          iter.setComparator(null);
          assertNull(iter.getComparator());
      }
  
      public void testIterateEven() {
          CollatingIterator iter = new CollatingIterator(comparator);
          iter.addIterator(evens.iterator());
          for(int i=0;i<evens.size();i++) {
              assertTrue(iter.hasNext());
              assertEquals(evens.get(i),iter.next());
          }
          assertTrue(!iter.hasNext());
      }
  
      public void testIterateEvenOdd() {
          CollatingIterator iter = new CollatingIterator(comparator,evens.iterator(),odds.iterator());
          for(int i=0;i<20;i++) {
              assertTrue(iter.hasNext());
              assertEquals(new Integer(i),iter.next());
          }
          assertTrue(!iter.hasNext());
      }
  
      public void testIterateOddEven() {
          CollatingIterator iter = new CollatingIterator(comparator,odds.iterator(),evens.iterator());
          for(int i=0;i<20;i++) {
              assertTrue(iter.hasNext());
              assertEquals(new Integer(i),iter.next());
          }
          assertTrue(!iter.hasNext());
      }
  
      public void testIterateEvenEven() {
          CollatingIterator iter = new CollatingIterator(comparator);
          iter.addIterator(evens.iterator());
          iter.addIterator(evens.iterator());
          for(int i=0;i<evens.size();i++) {
              assertTrue(iter.hasNext());
              assertEquals(evens.get(i),iter.next());
              assertTrue(iter.hasNext());
              assertEquals(evens.get(i),iter.next());
          }
          assertTrue(!iter.hasNext());
      }
  
  
      public void testIterateFibEvenOdd() {
          CollatingIterator iter = new CollatingIterator(comparator);
          iter.addIterator(fib.iterator());
          iter.addIterator(evens.iterator());
          iter.addIterator(odds.iterator());
          
          assertEquals(new Integer(0),iter.next());  // even   0
          assertEquals(new Integer(1),iter.next());  // fib    1
          assertEquals(new Integer(1),iter.next());  // fib    1
          assertEquals(new Integer(1),iter.next());  // odd    1
          assertEquals(new Integer(2),iter.next());  // fib    2
          assertEquals(new Integer(2),iter.next());  // even   2
          assertEquals(new Integer(3),iter.next());  // fib    3
          assertEquals(new Integer(3),iter.next());  // odd    3
          assertEquals(new Integer(4),iter.next());  // even   4
          assertEquals(new Integer(5),iter.next());  // fib    5
          assertEquals(new Integer(5),iter.next());  // odd    5
          assertEquals(new Integer(6),iter.next());  // even   6
          assertEquals(new Integer(7),iter.next());  // odd    7
          assertEquals(new Integer(8),iter.next());  // fib    8
          assertEquals(new Integer(8),iter.next());  // even   8
          assertEquals(new Integer(9),iter.next());  // odd    9
          assertEquals(new Integer(10),iter.next()); // even  10
          assertEquals(new Integer(11),iter.next()); // odd   11
          assertEquals(new Integer(12),iter.next()); // even  12
          assertEquals(new Integer(13),iter.next()); // fib   13
          assertEquals(new Integer(13),iter.next()); // odd   13
          assertEquals(new Integer(14),iter.next()); // even  14
          assertEquals(new Integer(15),iter.next()); // odd   15
          assertEquals(new Integer(16),iter.next()); // even  16
          assertEquals(new Integer(17),iter.next()); // odd   17
          assertEquals(new Integer(18),iter.next()); // even  18
          assertEquals(new Integer(19),iter.next()); // odd   19
          assertEquals(new Integer(21),iter.next()); // fib   21
  
          assertTrue(!iter.hasNext());
      }
  
      public void testRemoveFromSingle() {
          CollatingIterator iter = new CollatingIterator(comparator);
          iter.addIterator(evens.iterator());
          int expectedSize = evens.size();
          while(iter.hasNext()) {
              Integer val = (Integer)(iter.next());
              if(val.intValue() % 4 == 0) {
                  expectedSize--;
                  iter.remove();
              }
          }
          assertEquals(expectedSize,evens.size());
      }
  
      public void testRemoveFromDouble() {
          CollatingIterator iter = new CollatingIterator(comparator);
          iter.addIterator(evens.iterator());
          iter.addIterator(odds.iterator());
          int expectedSize = evens.size() + odds.size();
          while(iter.hasNext()) {
              Integer val = (Integer)(iter.next());
              if(val.intValue() % 4 == 0 || val.intValue() % 3 == 0 ) {
                  expectedSize--;
                  iter.remove();
              }
          }
          assertEquals(expectedSize,(evens.size() + odds.size()));
      }   
  
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
  
  Index: TestFilterIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  // TestFilterIterator.java 
  package org.apache.commons.collections.iterators;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.framework.Test;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import org.apache.commons.collections.Predicate;
  
  /**
   *
   * @author  Jan Sorensen
   */
  public class TestFilterIterator extends TestIterator {
  
      /** Creates new TestFilterIterator */
      public TestFilterIterator(String name) {
          super(name);
      }
  
      private String[] array;
      private FilterIterator iterator;
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() {
          array = new String[] { "a", "b", "c" };
          initIterator();
      }
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown() {
          iterator = null;
      }
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
          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());
          }
      }
  
      public void testRepeatedNext() {
          for (int i = 0; i < array.length; i++)
              iterator.next();
          verifyNoMoreElements();
      }
  
      public void testReturnValues() {
          verifyElementsInPredicate(new String[0]);
          verifyElementsInPredicate(new String[] { "a" });
          verifyElementsInPredicate(new String[] { "b" });
          verifyElementsInPredicate(new String[] { "c" });
          verifyElementsInPredicate(new String[] { "a", "b" });
          verifyElementsInPredicate(new String[] { "a", "c" });
          verifyElementsInPredicate(new String[] { "b", "c" });
          verifyElementsInPredicate(new String[] { "a", "b", "c" });
      }
  
      private void verifyNoMoreElements() {
          assertTrue(!iterator.hasNext());
          try {
              iterator.next();
              fail("NoSuchElementException expected");
          }
          catch (NoSuchElementException e) {
              // success
          }
      }
  
      private void verifyElementsInPredicate(final String[] elements) {
          Predicate pred = new Predicate() {
              public boolean evaluate(Object x) {
                  for (int i = 0; i < elements.length; i++)
                      if (elements[i].equals(x))
                          return true;
                  return false;
              }
          };
          initIterator();
          iterator.setPredicate(pred);
          for (int i = 0; i < elements.length; i++) {
              String s = (String)iterator.next();
              assertEquals(elements[i], s);
              assertTrue(i == elements.length - 1 ? !iterator.hasNext() : iterator.hasNext());
          }
          verifyNoMoreElements();
      }
  
      private void initIterator() {
          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; }
          };
          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);
      }
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
  
  Index: TestFilterListIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.iterators;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.framework.Test;
  import java.util.NoSuchElementException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.ListIterator;
  import java.util.Random;
  import org.apache.commons.collections.Predicate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2002/08/15 23:13:52 $
   * @author Rodney Waldhoff
   */
  public class TestFilterListIterator extends TestCase {
      public TestFilterListIterator(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestFilterListIterator.class);
      }
  
      public static void main(String args[]) {
          String[] testCaseName = { TestFilterListIterator.class.getName() };
          junit.textui.TestRunner.main(testCaseName);
      }
  
      private ArrayList list = null;
      private ArrayList odds = null;
      private ArrayList evens = null;
      private ArrayList threes = null;
      private ArrayList fours = null;
      private ArrayList sixes = null;
      private Predicate truePred = null;
      private Predicate falsePred = null;
      private Predicate evenPred = null;
      private Predicate oddPred = null;
      private Predicate threePred = null;
      private Predicate fourPred = null;
      private Random random = new Random();
  
      public void setUp() {
          list = new ArrayList();
          odds = new ArrayList();
          evens = new ArrayList();
          threes = new ArrayList();
          fours = new ArrayList();
          sixes = new ArrayList();
          for(int i=0;i<20;i++) {
              list.add(new Integer(i));
              if(i%2 == 0) { evens.add(new Integer(i)); }
              if(i%2 == 1) { odds.add(new Integer(i)); }
              if(i%3 == 0) { threes.add(new Integer(i)); }
              if(i%4 == 0) { fours.add(new Integer(i)); }
              if(i%6 == 0) { sixes.add(new Integer(i)); }
          }
  
          truePred = new Predicate() {
              public boolean evaluate(Object x) { 
                  return true;
              }
          };
  
          falsePred = new Predicate() {
              public boolean evaluate(Object x) { 
                  return true;
              }
          };
  
          evenPred = new Predicate() {
              public boolean evaluate(Object x) { 
                  return (((Integer)x).intValue()%2 == 0);
              }
          };
  
          oddPred = new Predicate() {
              public boolean evaluate(Object x) { 
                  return (((Integer)x).intValue()%2 == 1);
              }
          };
  
          threePred = new Predicate() {
              public boolean evaluate(Object x) { 
                  return (((Integer)x).intValue()%3 == 0);
              }
          };
  
          fourPred = new Predicate() {
              public boolean evaluate(Object x) { 
                  return (((Integer)x).intValue()%4 == 0);
              }
          };
  
      }
  
      public void tearDown() {
          list = null;
          odds = null;
          evens = null;
          threes = null;
          fours = null;
          sixes = null;
          truePred = null;
          falsePred = null;
          evenPred = null;
          oddPred = null;
          threePred = null;
          fourPred = null;
      }
  
      public void testWalkLists() {
          // this just confirms that our walkLists method works OK
          walkLists(list,list.listIterator());
      }
  
      public void testManual() {
          // do this one "by hand" as a sanity check
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
          
          assertEquals(new Integer(0),filtered.next());
          assertEquals(new Integer(3),filtered.next());
          assertEquals(new Integer(6),filtered.next());
          assertEquals(new Integer(9),filtered.next());
          assertEquals(new Integer(12),filtered.next());
          assertEquals(new Integer(15),filtered.next());
          assertEquals(new Integer(18),filtered.next());
  
          assertEquals(new Integer(18),filtered.previous());
          assertEquals(new Integer(15),filtered.previous());
          assertEquals(new Integer(12),filtered.previous());
          assertEquals(new Integer(9),filtered.previous());
          assertEquals(new Integer(6),filtered.previous());
          assertEquals(new Integer(3),filtered.previous());
          assertEquals(new Integer(0),filtered.previous());
      
          assertTrue(!filtered.hasPrevious());
  
          assertEquals(new Integer(0),filtered.next());
          assertEquals(new Integer(3),filtered.next());
          assertEquals(new Integer(6),filtered.next());
          assertEquals(new Integer(9),filtered.next());
          assertEquals(new Integer(12),filtered.next());
          assertEquals(new Integer(15),filtered.next());
          assertEquals(new Integer(18),filtered.next());
  
          assertTrue(!filtered.hasNext());
  
          assertEquals(new Integer(18),filtered.previous());
          assertEquals(new Integer(15),filtered.previous());
          assertEquals(new Integer(12),filtered.previous());
          assertEquals(new Integer(9),filtered.previous());
          assertEquals(new Integer(6),filtered.previous());
          assertEquals(new Integer(3),filtered.previous());
          assertEquals(new Integer(0),filtered.previous());
  
          assertEquals(new Integer(0),filtered.next());
          assertEquals(new Integer(0),filtered.previous());
          assertEquals(new Integer(0),filtered.next());
          
          assertEquals(new Integer(3),filtered.next());
          assertEquals(new Integer(6),filtered.next());
          assertEquals(new Integer(6),filtered.previous());
          assertEquals(new Integer(3),filtered.previous());
          assertEquals(new Integer(3),filtered.next());
          assertEquals(new Integer(6),filtered.next());
  
          assertEquals(new Integer(9),filtered.next());
          assertEquals(new Integer(12),filtered.next());
          assertEquals(new Integer(15),filtered.next());
          assertEquals(new Integer(15),filtered.previous());
          assertEquals(new Integer(12),filtered.previous());
          assertEquals(new Integer(9),filtered.previous());
  
      }
  
      public void testTruePredicate() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),truePred);
          walkLists(list,filtered);
      }
      
      public void testFalsePredicate() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),falsePred);
          walkLists(new ArrayList(),filtered);
      }
  
      public void testEvens() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),evenPred);
          walkLists(evens,filtered);
      }
      
      public void testOdds() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),oddPred);
          walkLists(odds,filtered);
      }
  
      public void testThrees() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
          walkLists(threes,filtered);
      }
  
      public void testFours() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),fourPred);
          walkLists(fours,filtered);
      }
  
      public void testNestedSixes() {
          FilterListIterator filtered = new FilterListIterator(
                                          new FilterListIterator(list.listIterator(),threePred),
                                          evenPred
                                        );
          walkLists(sixes,filtered);
      }
  
      public void testNestedSixes2() {
          FilterListIterator filtered = new FilterListIterator(
                                          new FilterListIterator(list.listIterator(),evenPred),
                                          threePred
                                        );
          walkLists(sixes,filtered);
      }
  
      public void testNestedSixes3() {        
          FilterListIterator filtered = new FilterListIterator(
                                          new FilterListIterator(list.listIterator(),threePred),
                                          evenPred
                                        );
          walkLists(sixes,new FilterListIterator(filtered,truePred));
      }
  
      public void testNextChangesPrevious() {
          {
              FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
              nextNextPrevious(threes.listIterator(),filtered);
          }
      
          {
              FilterListIterator filtered = new FilterListIterator(list.listIterator(),truePred);
              nextNextPrevious(list.listIterator(),filtered);
          }
      }
  
      public void testPreviousChangesNext() {
          {
              FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
              ListIterator expected = threes.listIterator();
              walkForward(expected,filtered);
              previousPreviousNext(expected,filtered);
          }
          {
              FilterListIterator filtered = new FilterListIterator(list.listIterator(),truePred);
              ListIterator expected = list.listIterator();
              walkForward(expected,filtered);
              previousPreviousNext(expected,filtered);
          }
      }
  
      public void testFailingHasNextBug() {
          FilterListIterator filtered = new FilterListIterator(list.listIterator(),fourPred);
          ListIterator expected = fours.listIterator();
          while(expected.hasNext()) {
              expected.next();
              filtered.next();
          }
          assertTrue(filtered.hasPrevious());
          assertTrue(!filtered.hasNext());
          assertEquals(expected.previous(),filtered.previous());
      }
  
      // Utilities
  
      private void walkForward(ListIterator expected, ListIterator testing) {
          while(expected.hasNext()) {
              assertEquals(expected.nextIndex(),testing.nextIndex());
              assertEquals(expected.previousIndex(),testing.previousIndex());
              assertTrue(testing.hasNext());
              assertEquals(expected.next(),testing.next());
          }
      }
  
      private void walkBackward(ListIterator expected, ListIterator testing) {
          while(expected.hasPrevious()) {
              assertEquals(expected.nextIndex(),testing.nextIndex());
              assertEquals(expected.previousIndex(),testing.previousIndex());
              assertTrue(testing.hasPrevious());
              assertEquals(expected.previous(),testing.previous());
          }
      }
  
      private void nextNextPrevious(ListIterator expected, ListIterator testing) {
          // calls to next() should change the value returned by previous()
          // even after previous() has been set by a call to hasPrevious()
          assertEquals(expected.next(),testing.next());
          assertEquals(expected.hasPrevious(),testing.hasPrevious());
          Object expecteda = expected.next();
          Object testinga = testing.next();
          assertEquals(expecteda,testinga);
          Object expectedb = expected.previous();
          Object testingb = testing.previous();
          assertEquals(expecteda,expectedb);
          assertEquals(testinga,testingb);
      }
  
      private void previousPreviousNext(ListIterator expected, ListIterator testing) {
          // calls to previous() should change the value returned by next()
          // even after next() has been set by a call to hasNext()
          assertEquals(expected.previous(),testing.previous());
          assertEquals(expected.hasNext(),testing.hasNext());
          Object expecteda = expected.previous();
          Object testinga = testing.previous();
          assertEquals(expecteda,testinga);
          Object expectedb = expected.next();
          Object testingb = testing.next();
          assertEquals(expecteda,testingb);
          assertEquals(expecteda,expectedb);
          assertEquals(testinga,testingb);
      }
  
      private void walkLists(List list, ListIterator testing) {
          ListIterator expected = list.listIterator();
  
          // walk all the way forward
          walkForward(expected,testing);
  
          // walk all the way back
          walkBackward(expected,testing);
  
          // forward,back,foward
          while(expected.hasNext()) {
              assertEquals(expected.nextIndex(),testing.nextIndex());
              assertEquals(expected.previousIndex(),testing.previousIndex());
              assertTrue(testing.hasNext());
              assertEquals(expected.next(),testing.next());
              assertTrue(testing.hasPrevious());
              assertEquals(expected.previous(),testing.previous());
              assertTrue(testing.hasNext());
              assertEquals(expected.next(),testing.next());
          }
  
  
          // walk all the way back
          walkBackward(expected,testing);
  
          for(int i=0;i<list.size();i++) {
              // walk forward i
              for(int j=0;j<i;j++) {
                  assertEquals(expected.nextIndex(),testing.nextIndex());
                  assertEquals(expected.previousIndex(),testing.previousIndex());
                  assertTrue(expected.hasNext()); // if this one fails we've got a logic error in the test
                  assertTrue(testing.hasNext());
                  assertEquals(expected.next(),testing.next());
              }
              // walk back i/2
              for(int j=0;j<i/2;j++) {
                  assertEquals(expected.nextIndex(),testing.nextIndex());
                  assertEquals(expected.previousIndex(),testing.previousIndex());
                  assertTrue(expected.hasPrevious()); // if this one fails we've got a logic error in the test
                  assertTrue(testing.hasPrevious());
                  assertEquals(expected.previous(),testing.previous());
              }
              // walk foward i/2
              for(int j=0;j<i/2;j++) {
                  assertEquals(expected.nextIndex(),testing.nextIndex());
                  assertEquals(expected.previousIndex(),testing.previousIndex());
                  assertTrue(expected.hasNext()); // if this one fails we've got a logic error in the test
                  assertTrue(testing.hasNext());
                  assertEquals(expected.next(),testing.next());
              }
              // walk back i
              for(int j=0;j<i;j++) {
                  assertEquals(expected.nextIndex(),testing.nextIndex());
                  assertEquals(expected.previousIndex(),testing.previousIndex());
                  assertTrue(expected.hasPrevious()); // if this one fails we've got a logic error in the test
                  assertTrue(testing.hasPrevious());
                  assertEquals(expected.previous(),testing.previous());
              }
          }
  
          // random walk
          StringBuffer walkdescr = new StringBuffer(500);
          for(int i=0;i<500;i++) {
              if(random.nextBoolean()) {
                  // step foward
                  walkdescr.append("+");
                  if(expected.hasNext()) {
                      assertEquals(walkdescr.toString(),expected.next(),testing.next());
                  }
              } else {
                  // step backward
                  walkdescr.append("-");
                  if(expected.hasPrevious()) {
                      assertEquals(walkdescr.toString(),expected.previous(),testing.previous());
                  }
              }
              assertEquals(walkdescr.toString(),expected.nextIndex(),testing.nextIndex());
              assertEquals(walkdescr.toString(),expected.previousIndex(),testing.previousIndex());
          }
  
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestIterator.java
  
  Index: TestIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
       
  package org.apache.commons.collections.iterators;
  
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import org.apache.commons.collections.TestObject;
  
  /**
   * Base class for tetsing Iterator interface
   * 
   * @author Morgan Delagrange
   */
  public abstract class TestIterator extends TestObject {
  
      public TestIterator(String testName) {
          super(testName);
      }
  
      public abstract Iterator makeEmptyIterator();
  
      public abstract Iterator makeFullIterator();
  
      /**
       * Whether or not we are testing an iterator that can be
       * empty.  Default is true.
       * 
       * @return true if Iterators can be empty
       */
      public boolean supportsEmptyIterator() {
          return true;
      }
  
      /**
       * Whether or not we are testing an iterator that can contain
       * elements.  Default is true.
       * 
       * @return true if Iterators can be empty
       */
      public boolean supportsFullIterator() {
          return true;
      }
  
      /**
       * Should throw a NoSuchElementException.
       */
      public void testEmptyIterator() {
          if (supportsEmptyIterator() == false) {
              return;
          }
  
          Iterator iter = makeEmptyIterator();
          assertTrue("hasNext() should return false for empty iterators",iter.hasNext() == false);
          try {
  	    iter.next();
              fail("NoSuchElementException must be thrown when Iterator is exhausted");
  	} catch (NoSuchElementException e) {
  	}
      }
  
      /**
       * NoSuchElementException (or any other exception)
       * should not be thrown for the first element.  
       * NoSuchElementException must be thrown when
       * hasNext() returns false
       */
      public void testFullIterator() {
          if (supportsFullIterator() == false) {
              return;
          }
  
          Iterator iter = makeFullIterator();
  
          assertTrue("hasNext() should return true for at least one element",iter.hasNext());
  
          try {
  	    iter.next();
  	} catch (NoSuchElementException e) {
              fail("Full iterators must have at least one element");
  	}
  
          while (iter.hasNext()) {
              iter.next();
          }
  
          try {
  	    iter.next();
              fail("NoSuchElementException must be thrown when Iterator is exhausted");
  	} catch (NoSuchElementException e) {
  	}
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java
  
  Index: TestIteratorChain.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.NoSuchElementException;
  
  /**
   * Tests the ArrayIterator to ensure that the next() method will actually
   * perform the iteration rather than the hasNext() method.
   * The code of this test was supplied by Mauricio S. Moura
   * 
   * @author James Strachan
   * @author Mauricio S. Moura
   * @author Morgan Delagrange
   * @version $Id: TestIteratorChain.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestIteratorChain extends TestIterator {
  
      protected String[] testArray = {
          "One", "Two", "Three", "Four", "Five", "Six"
      };
  
      protected List list1 = null;
      protected List list2 = null;
      protected List list3 = null;
  
      public static Test suite() {
          return new TestSuite(TestIteratorChain.class);
      }
  
      public TestIteratorChain(String testName) {
          super(testName);
      }
  
      public void setUp() {
          list1 = new ArrayList();
          list1.add("One");
          list1.add("Two");
          list1.add("Three");
          list2 = new ArrayList();
          list2.add("Four");
          list3 = new ArrayList();
          list3.add("Five");
          list3.add("Six");        
      }
  
      public Iterator makeEmptyIterator() {
          ArrayList list = new ArrayList();
          return new IteratorChain(list.iterator());
      }
  
      public Iterator makeFullIterator() {
          IteratorChain chain = new IteratorChain();
  
          Iterator i = list1.iterator();
  
          chain.addIterator(list1.iterator());
          chain.addIterator(list2.iterator());
          chain.addIterator(list3.iterator());
          return chain;
      }
  
      /**
       * Return a new, empty {@link Object} to used for testing.
       */
      public Object makeObject() {
          return makeFullIterator();
      }
  
      public void testIterator() {
          Iterator iter = (Iterator) makeFullIterator();
          for ( int i = 0; i < testArray.length; i++ ) {
              Object testValue = testArray[i];            
              Object iterValue = iter.next();
  
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
  
          assertTrue("Iterator should now be empty", ! iter.hasNext() );
  
          try {
              Object testValue = iter.next();
          } catch (Exception e) {
              assertTrue("NoSuchElementException must be thrown", 
                         e.getClass().equals((new NoSuchElementException()).getClass()));
          }
      }
  
      public void testRemove() {
          Iterator iter = (Iterator) makeFullIterator();
  
          try {
              iter.remove();
              fail("Calling remove before the first call to next() should throw an exception");
          } catch (IllegalStateException e) {
  
          }
  
          for ( int i = 0; i < testArray.length; i++ ) {
              Object testValue = testArray[i];            
              Object iterValue = iter.next();
  
              assertEquals( "Iteration value is correct", testValue, iterValue );
  
              if (! iterValue.equals("Four")) {
                  iter.remove();
              }
          }
  
          assertTrue("List is empty",list1.size() == 0);
          assertTrue("List is empty",list2.size() == 1);
          assertTrue("List is empty",list3.size() == 0);
      }
  
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestListIteratorWrapper.java
  
  Index: TestListIteratorWrapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestListIteratorWrapper.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ListIterator;
  import java.util.NoSuchElementException;
  
  /**
   * Tests the ListIteratorWrapper to insure that it simulates
   * a ListIterator correctly.
   *
   * @author Morgan Delagrange
   * @version $Id: TestListIteratorWrapper.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestListIteratorWrapper extends TestIterator {
  
      protected String[] testArray = {
          "One", "Two", "Three", "Four", "Five", "Six"
      };
  
      protected List list1 = null;
  
      public static Test suite() {
          return new TestSuite(TestListIteratorWrapper.class);
      }
  
      public TestListIteratorWrapper(String testName) {
          super(testName);
      }
  
      public void setUp() {
          list1 = new ArrayList();
          list1.add("One");
          list1.add("Two");
          list1.add("Three");
          list1.add("Four");
          list1.add("Five");
          list1.add("Six");
      }
  
      public Iterator makeEmptyIterator() {
          ArrayList list = new ArrayList();
          return new ListIteratorWrapper(list.iterator());
      }
  
      public Iterator makeFullIterator() {
          Iterator i = list1.iterator();
  
          return new ListIteratorWrapper(i);
      }
  
      /**
       * Return a new, empty {@link Object} to used for testing.
       */
      public Object makeObject() {
          return makeFullIterator();
      }
  
      public void testIterator() {
          ListIterator iter = (ListIterator) makeFullIterator();
          for ( int i = 0; i < testArray.length; i++ ) {
              Object testValue = testArray[i];            
              Object iterValue = iter.next();
  
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
  
          assertTrue("Iterator should now be empty", ! iter.hasNext() );
  
          try {
              Object testValue = iter.next();
          } catch (Exception e) {
              assertTrue("NoSuchElementException must be thrown", 
                         e.getClass().equals((new NoSuchElementException()).getClass()));
          }
  
          // now, read it backwards
          for (int i = testArray.length - 1; i > -1; --i) {
              Object testValue = testArray[i];
              Object iterValue = iter.previous();
  
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
  
          try {
              Object testValue = iter.previous();
          } catch (Exception e) {
              assertTrue("NoSuchElementException must be thrown", 
                         e.getClass().equals((new NoSuchElementException()).getClass()));
          }
  
          // now, read it forwards again
          for ( int i = 0; i < testArray.length; i++ ) {
              Object testValue = testArray[i];            
              Object iterValue = iter.next();
  
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
  
      }
  
      public void testRemove() {
          Iterator iter = (Iterator) makeFullIterator();
  
          try {
              iter.remove();
              fail("FilterIterator does not support the remove() method");
          } catch (UnsupportedOperationException e) {
  
          }
  
      }
  
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestSingletonIterator.java
  
  Index: TestSingletonIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestSingletonIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  
  /**
   * Tests the SingletonIterator to ensure that the next() method will actually
   * perform the iteration rather than the hasNext() method.
   *
   * @author James Strachan
   * @version $Id: TestSingletonIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestSingletonIterator extends TestIterator {
  
      private static final Object testValue = "foo";
      
      public static Test suite() {
          return new TestSuite(TestSingletonIterator.class);
      }
      
      public TestSingletonIterator(String testName) {
          super(testName);
      }
      
      /**
       * Returns null. SingletonIterators can never be empty;
       * they always have exactly one element.
       * 
       * @return null
       */
      public Iterator makeEmptyIterator() {
          return null;
      }
  
      public Iterator makeFullIterator() {
          return new SingletonIterator( testValue );
      }
  
      /**
       * Return a new, empty {@link Object} to used for testing.
       */
      public Object makeObject() {
          return makeFullIterator();
      }
      
      /**
       * Whether or not we are testing an iterator that can be
       * empty.  SingletonIterators are never empty;
       * 
       * @return false
       */
      public boolean supportsEmptyIterator() {
          return false;
      }
  
      public void testIterator() {
          Iterator iter = (Iterator) makeObject();
          assertTrue( "Iterator has a first item", iter.hasNext() );
          
          Object iterValue = iter.next();
          assertEquals( "Iteration value is correct", testValue, iterValue );
          
          assertTrue("Iterator should now be empty", ! iter.hasNext() );
  
  	try {
  	    Object testValue = iter.next();
  	} 
          catch (Exception e) {
  	  assertTrue("NoSuchElementException must be thrown", 
  		 e.getClass().equals((new NoSuchElementException()).getClass()));
  	}
      }
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestUniqueFilterIterator.java
  
  Index: TestUniqueFilterIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestUniqueFilterIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/15 23:13:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.iterators;
  
  import junit.framework.*;
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.NoSuchElementException;
  
  /**
   * Tests the ArrayIterator to ensure that the next() method will actually
   * perform the iteration rather than the hasNext() method.
   * The code of this test was supplied by Mauricio S. Moura
   * 
   * @author James Strachan
   * @author Mauricio S. Moura
   * @author Morgan Delagrange
   * @version $Id: TestUniqueFilterIterator.java,v 1.1 2002/08/15 23:13:52 pjack Exp $
   */
  public class TestUniqueFilterIterator extends TestIterator {
  
      protected String[] testArray = {
          "One", "Two", "Three", "Four", "Five", "Six"
      };
  
      protected List list1 = null;
  
      public static Test suite() {
          return new TestSuite(TestUniqueFilterIterator.class);
      }
  
      public TestUniqueFilterIterator(String testName) {
          super(testName);
      }
  
      public void setUp() {
          list1 = new ArrayList();
          list1.add("One");
          list1.add("Two");
          list1.add("Three");
          list1.add("Two");
          list1.add("One");
          list1.add("Four");
          list1.add("Five");
          list1.add("Five");
          list1.add("Six");
          list1.add("Five");
      }
  
      public Iterator makeEmptyIterator() {
          ArrayList list = new ArrayList();
          return new UniqueFilterIterator(list.iterator());
      }
  
      public Iterator makeFullIterator() {
          Iterator i = list1.iterator();
  
          return new UniqueFilterIterator(i);
      }
  
      /**
       * Return a new, empty {@link Object} to used for testing.
       */
      public Object makeObject() {
          return makeFullIterator();
      }
  
      public void testIterator() {
          Iterator iter = (Iterator) makeFullIterator();
          for ( int i = 0; i < testArray.length; i++ ) {
              Object testValue = testArray[i];            
              Object iterValue = iter.next();
  
              assertEquals( "Iteration value is correct", testValue, iterValue );
          }
  
          assertTrue("Iterator should now be empty", ! iter.hasNext() );
  
          try {
              Object testValue = iter.next();
          } catch (Exception e) {
              assertTrue("NoSuchElementException must be thrown", 
                         e.getClass().equals((new NoSuchElementException()).getClass()));
          }
      }
  
      public void testRemove() {
          Iterator iter = (Iterator) makeFullIterator();
  
          try {
              iter.remove();
              fail("FilterIterator does not support the remove() method");
          } catch (UnsupportedOperationException e) {
  
          }
  
      }
  
  }
  
  
  
  

--
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