Class TransformIterator
- java.lang.Object
-
- org.apache.commons.collections.iterators.TransformIterator
-
- All Implemented Interfaces:
java.util.Iterator
public class TransformIterator extends java.lang.Object implements java.util.IteratorDecorates an iterator such that each element returned is transformed.- Since:
- Commons Collections 1.0
-
-
Constructor Summary
Constructors Constructor Description TransformIterator()Constructs a newTransformIteratorthat will not function until thesetIteratormethod is invoked.TransformIterator(java.util.Iterator iterator)Constructs a newTransformIteratorthat won't transform elements from the given iterator.TransformIterator(java.util.Iterator iterator, Transformer transformer)Constructs a newTransformIteratorthat will use the given iterator and transformer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.IteratorgetIterator()Gets the iterator this iterator is using.TransformergetTransformer()Gets the transformer this iterator is using.booleanhasNext()java.lang.Objectnext()Gets the next object from the iteration, transforming it using the current transformer.voidremove()voidsetIterator(java.util.Iterator iterator)Sets the iterator for this iterator to use.voidsetTransformer(Transformer transformer)Sets the transformer this the iterator to use.
-
-
-
Constructor Detail
-
TransformIterator
public TransformIterator()
Constructs a newTransformIteratorthat will not function until thesetIteratormethod is invoked.
-
TransformIterator
public TransformIterator(java.util.Iterator iterator)
Constructs a newTransformIteratorthat won't transform elements from the given iterator.- Parameters:
iterator- the iterator to use
-
TransformIterator
public TransformIterator(java.util.Iterator iterator, Transformer transformer)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 Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator
-
next
public java.lang.Object 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 interfacejava.util.Iterator- Returns:
- the next object
- Throws:
java.util.NoSuchElementException- if there are no more elements
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator
-
getIterator
public java.util.Iterator getIterator()
Gets the iterator this iterator is using.- Returns:
- the iterator.
-
setIterator
public void setIterator(java.util.Iterator iterator)
Sets the iterator for this iterator to use. If iteration has started, this effectively resets the iterator.- Parameters:
iterator- the iterator to use
-
getTransformer
public Transformer getTransformer()
Gets the transformer this iterator is using.- Returns:
- the transformer.
-
setTransformer
public void setTransformer(Transformer transformer)
Sets the transformer this the iterator to use. A null transformer is a no-op transformer.- Parameters:
transformer- the transformer to use
-
-