com.aliasi.util
Class Iterators.Modifier<E>

java.lang.Object
  extended by com.aliasi.util.Iterators.Modifier<E>
Type Parameters:
E - the type of objects returned by the iterator
All Implemented Interfaces:
Iterator<E>
Enclosing class:
Iterators

public abstract static class Iterators.Modifier<E>
extends Object
implements Iterator<E>

An Iterator.Modifier uses a single abstract method to operate on the elements returned by an underlying iterator to return modified objects. The remove() and hasNext() methods are simply passed to the underlying iterator. This implements the filter pattern, which is known as a map in functional programming.

Since:
LingPipe2.1
Version:
3.0
Author:
Bob Carpenter

Constructor Summary
Iterators.Modifier(Iterator<? extends E> it)
          Construct a modifier from an underlying iterator.
 
Method Summary
 boolean hasNext()
          Returns true if the underlying iterator has more elements.
abstract  E modify(E next)
          This abstract method is applied to objects returned by the underlying iterator to create the object returned by this iterator.
 E next()
          Returns the next element for this iterator, which is the object returned by the underlying iterator after undergoing modification by modify(Object).
 void remove()
          Remove the next element by delegating the call to the the underlying iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Iterators.Modifier

public Iterators.Modifier(Iterator<? extends E> it)
Construct a modifier from an underlying iterator.

Parameters:
it - Underlying iterator.
Method Detail

remove

public void remove()
Remove the next element by delegating the call to the the underlying iterator.

Specified by:
remove in interface Iterator<E>

hasNext

public boolean hasNext()
Returns true if the underlying iterator has more elements. This method is simply delegated to the underlying iterator.

Specified by:
hasNext in interface Iterator<E>
Returns:
true if this iterator has more elements.

next

public E next()
Returns the next element for this iterator, which is the object returned by the underlying iterator after undergoing modification by modify(Object).

Specified by:
next in interface Iterator<E>
Returns:
The modified next element from the underlying iterator.

modify

public abstract E modify(E next)
This abstract method is applied to objects returned by the underlying iterator to create the object returned by this iterator. This method is called once for each call to next().

Parameters:
next - Object returned by underlying iterator.
Returns:
Object returned by this iterator.