|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.stanbol.entityhub.servicesapi.util.AdaptingIterator<T,A>
T - The type of the incoming elementsA - The type of the elements returned by this iteratorpublic class AdaptingIterator<T,A>
Uses the parsed Adapter to convert values of type T to values of type A. If an instance of T can not be converted to A, than such values are filtered. This means that this implementation can be used for both filtering and converting of values of the base iterator. In fact the FilteringIterator is implemented based on this class.
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.
| Nested Class Summary | |
|---|---|
static interface |
AdaptingIterator.Adapter<T,A>
Adapts values of type T to values of type A. |
| Constructor Summary | |
|---|---|
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 |
|
| Method Summary | |
|---|---|
boolean |
hasNext()
|
A |
next()
|
protected A |
prepareNext()
|
void |
remove()
This implementation of remove does have an additional restriction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AdaptingIterator(Iterator<T> it,
AdaptingIterator.Adapter<T,A> adapter,
Class<A> type)
it - the base iteratoradapter - the adaptertype - the target type| Method Detail |
|---|
public final boolean hasNext()
hasNext in interface Iterator<A>public final A next()
next in interface Iterator<A>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()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||