T - The type of the incoming elementsA - The type of the elements returned by this iteratorpublic class AdaptingIterator<T,A> extends Object implements Iterator<A>
Note that Iterator.remove() only works as long as
Iterator.hasNext() was not called to determine if there are
further elements. The reason for that is, that in order to filter elements
of the parent iterator Iterator.next() has to be called to check
weather any further element is valid against the used Filter.
This call to Iterator.next() causes the parent Iterator to switch
to the next element, meaning that after that the remove()
method would delete a different element. To avoid that this Iterator
throws an IllegalStateException in such cases. If the parent
Iterator does not support remove() at all an
UnsupportedOperationException is thrown.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AdaptingIterator.Adapter<T,A>
Adapts values of type T to values of type A.
|
| Constructor and Description |
|---|
AdaptingIterator(Iterator<T> it,
AdaptingIterator.Adapter<T,A> adapter,
Class<A> type)
Constructs an instance based on an iterator of type T, an adapter and the
target type
|
public final void remove()
hasNext() was not yet called. This is
because hasNext() needs to call Iterator.next() on the
parent iterator to check if there are further elements that can be
adapted successfully. This causes that the current element of this
Iterator (stored in an local variable) is no longer the current element
of the parent iterator and therefore calls to remove() would
delete an other object within the collection holding the elements used
for this iteration. To prevent this this method throws an
IllegalStateException ins such cases. Users of this method need
therefore to ensure, that there are no calls to remove between a call
to hasNext() and next() (what is not the case in
typical use cases).remove in interface Iterator<A>Iterator.remove()protected A prepareNext()
Copyright © 2010-2014 The Apache Software Foundation. All Rights Reserved.