Class IteratorTransform

  extended by net.sourceforge.nite.util.IteratorTransform
All Implemented Interfaces:

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 If you want to avoid these exceptions, use IteratorTransformFilter.
By default, the IteratorTransform does not allow removal of objects.
.. 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.

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

Constructor Summary
IteratorTransform(java.util.Iterator it, Transform trans)
Method Summary
 boolean hasNext()
 java.lang.Object next()
 void remove()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public IteratorTransform(java.util.Iterator it,
                         Transform trans)
it - The Iterator to filter
trans - The Transform
Method Detail


public void remove()
Specified by:
remove in interface java.util.Iterator


public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator


public java.lang.Object next()
Specified by:
next in interface java.util.Iterator