org.hibernate.util
public class: JoinedIterator [javadoc |
source]
java.lang.Object
org.hibernate.util.JoinedIterator
All Implemented Interfaces:
Iterator
An JoinedIterator is an Iterator that wraps a number of Iterators.
This class makes multiple iterators look like one to the caller.
When any method from the Iterator interface is called, the JoinedIterator
will delegate to a single underlying Iterator. The JoinedIterator will
invoke the Iterators in sequence until all Iterators are exhausted.
| Method from org.hibernate.util.JoinedIterator Detail: |
public boolean hasNext() {
updateCurrentIterator();
return currentIterator.hasNext();
}
|
public Object next() {
updateCurrentIterator();
return currentIterator.next();
}
|
public void remove() {
updateCurrentIterator();
lastUsedIterator.remove();
}
|
protected void updateCurrentIterator() {
if (currentIterator == null) {
if( iterators.length==0 ) {
currentIterator = EmptyIterator.INSTANCE;
}
else {
currentIterator = iterators[0];
}
// set last used iterator here, in case the user calls remove
// before calling hasNext() or next() (although they shouldn't)
lastUsedIterator = currentIterator;
}
while (! currentIterator.hasNext() && currentIteratorIndex < iterators.length - 1) {
currentIteratorIndex++;
currentIterator = iterators[currentIteratorIndex];
}
}
|