org.xshare.base.iterator
Class TransformatorIterator

java.lang.Object
  |
  +--org.xshare.base.iterator.TransformatorIterator
All Implemented Interfaces:
java.util.Iterator

public final class TransformatorIterator
extends java.lang.Object
implements java.util.Iterator

Iterator with the ability to transform the elements of a given iteration according to the users specification before returning them.

Example

 ...
 Collection cats = ...
 ...
 public void getCollectionOfPets() {
  return new TransformatorIterator(cats.iterator(),
               new UnaryFunction() {
                   public Object exec(Object aCat) {
                       return new Pet((Cat)aCat);
                   }
               });
 }

Notes On The Implementation

Version:
$Revision: 1.1 $
Author:
Oliver Fischer

Constructor Summary
TransformatorIterator(java.util.Iterator aSourceIterator, UnaryFunction aTransformingFunction)
          Creates a new instance of this iterator for a given iteration whose elements are transformed by a given function.
 
Method Summary
 boolean hasNext()
          Checks if there are more elements return or not.
 java.lang.Object next()
          Returns the next object.
 void remove()
          This operation is not supported for this type of iterator, since the 'clients' of this iteration does not work directly on the source iteration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformatorIterator

public TransformatorIterator(java.util.Iterator aSourceIterator,
                             UnaryFunction aTransformingFunction)
Creates a new instance of this iterator for a given iteration whose elements are transformed by a given function.

Parameters:
aSourceIterator - a Iterator object pointing to the source iteration for this iterator.
aTransformingFunction - a UnaryFunction object specifing the transformation process for e single element of the source iteration.
Throws:
java.lang.NullPointerException - if one of both elements is null.
Method Detail

remove

public void remove()
This operation is not supported for this type of iterator, since the 'clients' of this iteration does not work directly on the source iteration.

Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException - if this method is called since it is not supported.

next

public java.lang.Object next()
Returns the next object.

Specified by:
next in interface java.util.Iterator
Throws:
java.util.NoSuchElementException - if hasNext() returns false.
See Also:
hasNext()

hasNext

public boolean hasNext()
Checks if there are more elements return or not.

Specified by:
hasNext in interface java.util.Iterator
Returns:
a boolean value which is true if there are elements left to return via next(). Otherwise false is returned.
See Also:
next()


jKiska Base 0.2.1 Release Esche [http://jkiska.sourceforge.net]