net.sf.molae.pipe.filter
Class FilterIterator<E>

java.lang.Object
  extended by net.sf.molae.pipe.filter.FilterIterator<E>
All Implemented Interfaces:
Iterator<E>

public final class FilterIterator<E>
extends Object
implements Iterator<E>

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


Constructor Summary
FilterIterator(Iterator<? extends E> base, TypedPredicate<? super E> filter)
          Constructs a FilterIterator object.
 
Method Summary
 Iterator<? extends E> getBase()
          Returns the underlying iterator.
 TypedPredicate<? super E> getFilter()
          Returns the underlying filter.
 boolean hasNext()
           
 E 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<? extends E> base,
                      TypedPredicate<? super E> 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<? extends E> getBase()
Returns the underlying iterator.

Returns:
the underlying iterator

getFilter

public TypedPredicate<? super E> getFilter()
Returns the underlying filter.

Returns:
the underlying filter

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>

next

public E next()
Returns the next element from the base iterator that matches the underlying predicate.

Specified by:
next in interface Iterator<E>
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<E>
Throws:
IllegalStateException - if hasNext() has already been called.
UnsupportedOperationException - depending on the base iterator