net.sourceforge.nite.util
Class IteratorTransform

java.lang.Object
  extended by 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)

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

IteratorTransform

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

remove

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

hasNext

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

next

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