Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public Class TransformIterator<I, O>

extends Object
implements Iterator<O>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Imports
java.util.Iterator, org.apache.commons.collections4.Transformer

Decorates an iterator such that each element returned is transformed.
Since
1.0

Field Summary

Modifier and TypeField and Description
private Iterator<? extends I>
iterator

The iterator being used

private Transformer<? super I, ? extends O>
transformer

The transformer being used

Constructor Summary

AccessConstructor and Description
public
TransformIterator()

Constructs a new TransformIterator that will not function until the setIterator and setTransformer(Transformer) methods are invoked.

public
TransformIterator(final Iterator<? extends I>
the iterator to use
iterator
)

Constructs a new TransformIterator that won't transform elements from the given iterator.

public
TransformIterator(final Iterator<? extends I>
the iterator to use
iterator
,
final Transformer<? super I, ? extends O>
the transformer to use
transformer
)

Constructs a new TransformIterator that will use the given iterator and transformer.

Method Summary

Modifier and TypeMethod and Description
public Iterator<? extends I>

Returns:

the iterator.
getIterator
()

Gets the iterator this iterator is using.

public Transformer<? super I, ? extends O>

Returns:

the transformer.
getTransformer
()

Gets the transformer this iterator is using.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public O

Returns:

the next object
next
()

Implements java.util.Iterator.next.

Gets the next object from the iteration, transforming it using the current transformer.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
public void
setIterator(final Iterator<? extends I>
the iterator to use
iterator
)

Sets the iterator for this iterator to use.

public void
setTransformer(final Transformer<? super I, ? extends O>
the transformer to use
transformer
)

Sets the transformer this the iterator to use.

protected O

Returns:

the transformed object
transform
(final I
the object to transform
source
)

Transforms the given object using the transformer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
private Iterator<? extends I> iterator

The iterator being used

transformerback to summary
private Transformer<? super I, ? extends O> transformer

The transformer being used

Constructor Detail

TransformIteratorback to summary
public TransformIterator()

Constructs a new TransformIterator that will not function until the setIterator and setTransformer(Transformer) methods are invoked.

TransformIteratorback to summary
public TransformIterator(final Iterator<? extends I> iterator)

Constructs a new TransformIterator that won't transform elements from the given iterator.

Parameters
iterator:Iterator<? extends I>

the iterator to use

TransformIteratorback to summary
public TransformIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transformer)

Constructs a new TransformIterator that will use the given iterator and transformer. If the given transformer is null, then objects will not be transformed.

Parameters
iterator:Iterator<? extends I>

the iterator to use

transformer:Transformer<? super I, ? extends O>

the transformer to use

Method Detail

getIteratorback to summary
public Iterator<? extends I> getIterator()

Gets the iterator this iterator is using.

Returns:Iterator<? extends I>

the iterator.

getTransformerback to summary
public Transformer<? super I, ? extends O> getTransformer()

Gets the transformer this iterator is using.

Returns:Transformer<? super I, ? extends O>

the transformer.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public O next()

Implements java.util.Iterator.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.

Returns:O

the next object

Annotations
@Override
Exceptions
NoSuchElementException:
if there are no more elements
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
setIteratorback to summary
public void setIterator(final Iterator<? extends I> iterator)

Sets the iterator for this iterator to use. If iteration has started, this effectively resets the iterator.

Parameters
iterator:Iterator<? extends I>

the iterator to use

setTransformerback to summary
public void setTransformer(final Transformer<? super I, ? extends O> transformer)

Sets the transformer this the iterator to use. A null transformer is a no-op transformer.

Parameters
transformer:Transformer<? super I, ? extends O>

the transformer to use

transformback to summary
protected O transform(final I source)

Transforms the given object using the transformer. If the transformer is null, the original object is returned as-is.

Parameters
source:I

the object to transform

Returns:O

the transformed object