net.sourceforge.nite.util
Class IteratorTransform

java.lang.Object
net.sourceforge.nite.util.IteratorTransform

All Implemented Interfaces:

java.util.Iterator

public class IteratorTransform

extends java.lang.Object

implements java.util.Iterator

An IteratorTransform is used to transform Objects in an Iterator
and present them as a new Iterator.
The filter is initialised with a Transform; for every object in the
original Iterator the transformed Object will be returned.
This implementation is lazy, meaning that the next object from the original
iterator will not be accessed before it is needed due to a call to the
next() method of this IteratorTransform.
The original Iterator will therefore be traversed only once and the elements
will not be stored in an intermediate array or something like that.

NB: If the transformation results in an exception, this exception will be
thrown at the call of iterator.next(). If you want to avoid these exceptions,
use IteratorTransformFilter.
By default, the IteratorTransform does not allow removal of objects.
Example:
..
Iterator it = someSetOfStrings.iterator();
Transform t = new Transform() {
public boolean transform(Object o) {
return ((String)o).reverse();
}
};
Iterator tansformedIt = new IteratorTransform(it, t);
..
The new iterator will return all reversed strings from the original Iterator.
You can also implement special subclasses of Transform
to achieve more complex transformations.

Examples of the use of the different Iterator modifyers (IteratorFilter,
IteratorTransform, IteratorChain) can be found in the class RTSI.

Author:

Dennis Reidsma, UTwente
Adapted from the parlevink package (HMI group, University of Twente)