org.apache.commons.collections.iterators
Class FilterIterator

java.lang.Object
  |
  +--org.apache.commons.collections.iterators.ProxyIterator
        |
        +--org.apache.commons.collections.iterators.FilterIterator
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
FilterIterator, UniqueFilterIterator

public class FilterIterator
extends ProxyIterator

A Proxy Iterator which takes a Predicate instance to filter out objects from an underlying Iterator instance. Only objects for which the specified Predicate evaluates to true are returned.

Since:
1.0
Author:
James Strachan, Jan Sorensen

Constructor Summary
FilterIterator()
          Constructs a new FilterIterator that will not function until setIterator is invoked.
FilterIterator(java.util.Iterator iterator)
          Constructs a new FilterIterator that will not function until setPredicate is invoked.
FilterIterator(java.util.Iterator iterator, Predicate predicate)
          Constructs a new FilterIterator that will use the given iterator and predicate.
 
Method Summary
 Predicate getPredicate()
          Getter for property predicate.
 boolean hasNext()
          Returns true if the underlying iterator contains an object that matches the predicate.
 java.lang.Object next()
          Returns the next object that matches the predicate.
 void remove()
          Always throws UnsupportedOperationException as this class does look-ahead with its internal iterator.
 void setPredicate(Predicate predicate)
          Setter for property predicate.
 
Methods inherited from class org.apache.commons.collections.iterators.ProxyIterator
getIterator, setIterator
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilterIterator

public FilterIterator()
Constructs a new FilterIterator that will not function until setIterator is invoked.


FilterIterator

public FilterIterator(java.util.Iterator iterator)
Constructs a new FilterIterator that will not function until setPredicate is invoked.

Parameters:
iterator - the iterator to use

FilterIterator

public FilterIterator(java.util.Iterator iterator,
                      Predicate predicate)
Constructs a new FilterIterator that will use the given iterator and predicate.

Parameters:
iterator - the iterator to use
predicate - the predicate to use
Method Detail

hasNext

public boolean hasNext()
Returns true if the underlying iterator contains an object that matches the predicate.

Specified by:
hasNext in interface java.util.Iterator
Overrides:
hasNext in class ProxyIterator
Returns:
true if there is another object that matches the predicate

next

public java.lang.Object next()
Returns the next object that matches the predicate.

Specified by:
next in interface java.util.Iterator
Overrides:
next in class ProxyIterator
Returns:
the next object which matches the given predicate
Throws:
java.util.NoSuchElementException - if there are no more elements that match the predicate

remove

public void remove()
Always throws UnsupportedOperationException as this class does look-ahead with its internal iterator.

Specified by:
remove in interface java.util.Iterator
Overrides:
remove in class ProxyIterator
Throws:
java.lang.UnsupportedOperationException - always

getPredicate

public Predicate getPredicate()
Getter for property predicate.

Returns:
Value of property predicate.

setPredicate

public void setPredicate(Predicate predicate)
Setter for property predicate.

Parameters:
predicate - New value of property predicate.


Copyright © 2001-2004 The Apache Software Foundation. All Rights Reserved.