net.sf.molae.pipe.filter
Class FilterIterator

java.lang.Object
  |
  +--net.sf.molae.pipe.filter.FilterIterator
All Implemented Interfaces:
Iterator

public final class FilterIterator
extends Object
implements Iterator

Provides an Iterator that returns only the items that fulfil a specific condition.


Constructor Summary
FilterIterator(Iterator base, Predicate filter)
          Constructs a FilterIterator object.
 
Method Summary
 Iterator getBase()
          Returns the underlying iterator.
 Predicate getFilter()
          Returns the underlying filter.
 boolean hasNext()
           
 Object next()
          Returns the next element from the base iterator that matches the underlying predicate.
 void remove()
          Removes from the underlying collection of the base iterator the last element returned by this iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilterIterator

public FilterIterator(Iterator base,
                      Predicate filter)
Constructs a FilterIterator object.
Parameters:
base - base iterator
filter - a predicate that determines which objects are contained in the filtered iterator.
Throws:
NullPointerException - if the specified objects are null.
Method Detail

getBase

public Iterator getBase()
Returns the underlying iterator.
Returns:
the underlying iterator

getFilter

public Predicate getFilter()
Returns the underlying filter.
Returns:
the underlying filter

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator

next

public Object next()
Returns the next element from the base iterator that matches the underlying predicate.
Specified by:
next in interface Iterator
Returns:
the next element from the base iterator that matches the underlying predicate
Throws:
NoSuchElementException - iteration has no more elements.

remove

public void remove()
Removes from the underlying collection of the base iterator the last element returned by this iterator. This method can only be called, if next() was called, but not after hasNext(), because the hasNext() call changes the base iterator.
Specified by:
remove in interface Iterator
Throws:
IllegalStateException - if hasNext() has already been called.
UnsupportedOperationException - depending on the base iterator