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

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

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

Returns all elements of the base iterator while the elements fulfil a specific condition. The first element that does not fulfil the condition is also returned.


Constructor Summary
HeadIterator(Iterator<? extends E> base, TypedPredicate<? super E> filter)
          Constructs a new head iterator.
 
Method Summary
 boolean hasNext()
           
 E next()
           
 void remove()
          Removes from the underlying collection of the base iterator the last element returned by this iterator.
static
<E> Iterator<E>
whileIterator(Iterator<? extends E> base, TypedPredicate<? super E> filter)
          Returns an iterator that returns all elements of the base iterator while the elements fulfil the specified condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeadIterator

public HeadIterator(Iterator<? extends E> base,
                    TypedPredicate<? super E> filter)
Constructs a new head iterator.

Parameters:
base - The base iterator
filter - The condition all elements but the last must fulfil.
Throws:
NullPointerException - if the specified objects are null.
Method Detail

hasNext

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

next

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

remove

public void remove()
Removes from the underlying collection of the base iterator the last element returned by this iterator.

Specified by:
remove in interface Iterator<E>
Throws:
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.
UnsupportedOperationException - depending on the base iterator

whileIterator

public static <E> Iterator<E> whileIterator(Iterator<? extends E> base,
                                            TypedPredicate<? super E> filter)
Returns an iterator that returns all elements of the base iterator while the elements fulfil the specified condition. The first element that does not fulfil the condition is not returned.

Parameters:
base - The base iterator
filter - The condition all elements but the last must fulfil.
Returns:
an iterator that returns all elements of the base iterator while the elements fulfil the specified condition.