FileDocCategorySizeDatePackage
JoinedIterator.javaAPI DocHibernate 3.2.52211Mon Jun 28 18:58:08 BST 2004org.hibernate.util

JoinedIterator

public class JoinedIterator extends Object implements 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.

Fields Summary
private static final Iterator[]
ITERATORS
private Iterator[]
iterators
private int
currentIteratorIndex
private Iterator
currentIterator
private Iterator
lastUsedIterator
Constructors Summary
public JoinedIterator(List iterators)


	   
		this( (Iterator[]) iterators.toArray(ITERATORS) );
	
public JoinedIterator(Iterator[] iterators)

		if( iterators==null )
			throw new NullPointerException("Unexpected NULL iterators argument");
		this.iterators = iterators;
	
public JoinedIterator(Iterator first, Iterator second)

		this( new Iterator[] { first, second } );
	
Methods Summary
public booleanhasNext()

		updateCurrentIterator();
		return currentIterator.hasNext();
	
public java.lang.Objectnext()

		updateCurrentIterator();
		return currentIterator.next();
	
public voidremove()

		updateCurrentIterator();
		lastUsedIterator.remove();
	
protected voidupdateCurrentIterator()


		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];
		}