Class TransformIterator
java.lang.Object
org.apache.commons.collections.iterators.TransformIterator
- All Implemented Interfaces:
Iterator
Decorates an iterator such that each element returned is transformed.
- Since:
- Commons Collections 1.0
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- James Strachan, Stephen Colebourne
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newTransformIteratorthat will not function until thesetIteratormethod is invoked.TransformIterator(Iterator iterator) Constructs a newTransformIteratorthat won't transform elements from the given iterator.TransformIterator(Iterator iterator, Transformer transformer) Constructs a newTransformIteratorthat will use the given iterator and transformer. -
Method Summary
Modifier and TypeMethodDescriptionGets the iterator this iterator is using.Gets the transformer this iterator is using.booleanhasNext()next()Gets the next object from the iteration, transforming it using the current transformer.voidremove()voidsetIterator(Iterator iterator) Sets the iterator for this iterator to use.voidsetTransformer(Transformer transformer) Sets the transformer this the iterator to use.protected ObjectTransforms the given object using the transformer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
TransformIterator
public TransformIterator()Constructs a newTransformIteratorthat will not function until thesetIteratormethod is invoked. -
TransformIterator
Constructs a newTransformIteratorthat won't transform elements from the given iterator.- Parameters:
iterator- the iterator to use
-
TransformIterator
Constructs a newTransformIteratorthat will use the given iterator and transformer. If the given transformer is null, then objects will not be transformed.- Parameters:
iterator- the iterator to usetransformer- the transformer to use
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
Gets the next object from the iteration, transforming it using the current transformer. If the transformer is null, no transformation occurs and the object from the iterator is returned directly.- Specified by:
nextin interfaceIterator- Returns:
- the next object
- Throws:
NoSuchElementException- if there are no more elements
-
remove
public void remove() -
getIterator
Gets the iterator this iterator is using.- Returns:
- the iterator.
-
setIterator
Sets the iterator for this iterator to use. If iteration has started, this effectively resets the iterator.- Parameters:
iterator- the iterator to use
-
getTransformer
Gets the transformer this iterator is using.- Returns:
- the transformer.
-
setTransformer
Sets the transformer this the iterator to use. A null transformer is a no-op transformer.- Parameters:
transformer- the transformer to use
-
transform
Transforms the given object using the transformer. If the transformer is null, the original object is returned as-is.- Parameters:
source- the object to transform- Returns:
- the transformed object
-