net.sf.molae.pipe.filter
Class HeadIterator
java.lang.Object
|
+--net.sf.molae.pipe.filter.HeadIterator
- All Implemented Interfaces:
- Iterator
- public final class HeadIterator
- extends Object
- implements Iterator
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.
|
Method Summary |
boolean |
hasNext()
|
Object |
next()
|
void |
remove()
Removes from the underlying collection of the base iterator the last
element returned by this iterator. |
static Iterator |
whileIterator(Iterator base,
Predicate 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 |
HeadIterator
public HeadIterator(Iterator base,
Predicate filter)
- Constructs a new head iterator.
- Parameters:
base - The base iteratorfilter - The condition all elements but the last must fulfil.- Throws:
NullPointerException - if the specified objects are
null.
hasNext
public boolean hasNext()
- Specified by:
hasNext in interface Iterator
next
public Object next()
- Specified by:
next in interface Iterator
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
- 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 Iterator whileIterator(Iterator base,
Predicate 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 iteratorfilter - 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.