01: package net.sf.saxon.expr;
02:
03: import java.util.Iterator;
04:
05: /**
06: * An iterator that combines the results of a sequence of iterators
07: */
08: public class MultiIterator implements Iterator {
09:
10: private Iterator[] array;
11: private int current;
12:
13: public MultiIterator(Iterator[] array) {
14: this .array = array;
15: this .current = 0;
16: }
17:
18: /**
19: * Returns <tt>true</tt> if the iteration has more elements. (In other
20: * words, returns <tt>true</tt> if <tt>next</tt> would return an element
21: * rather than throwing an exception.)
22: *
23: * @return <tt>true</tt> if the iterator has more elements.
24: */
25:
26: public boolean hasNext() {
27: while (true) {
28: if (current >= array.length) {
29: return false;
30: }
31: if (array[current].hasNext()) {
32: return true;
33: }
34: current++;
35: }
36: }
37:
38: /**
39: * Returns the next element in the iteration.
40: *
41: * @return the next element in the iteration.
42: * @exception java.util.NoSuchElementException iteration has no more elements.
43: */
44: public Object next() {
45: return array[current].next();
46: }
47:
48: /**
49: *
50: * Removes from the underlying collection the last element returned by the
51: * iterator (optional operation). This method can be called only once per
52: * call to <tt>next</tt>. The behavior of an iterator is unspecified if
53: * the underlying collection is modified while the iteration is in
54: * progress in any way other than by calling this method.
55: *
56: * @exception UnsupportedOperationException if the <tt>remove</tt>
57: * operation is not supported by this Iterator.
58:
59: * @exception IllegalStateException if the <tt>next</tt> method has not
60: * yet been called, or the <tt>remove</tt> method has already
61: * been called after the last call to the <tt>next</tt>
62: * method.
63: */
64: public void remove() {
65: throw new UnsupportedOperationException();
66: }
67: }
68:
69: //
70: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
71: // you may not use this file except in compliance with the License. You may obtain a copy of the
72: // License at http://www.mozilla.org/MPL/
73: //
74: // Software distributed under the License is distributed on an "AS IS" basis,
75: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
76: // See the License for the specific language governing rights and limitations under the License.
77: //
78: // The Original Code is: all this file.
79: //
80: // The Initial Developer of the Original Code is Michael H. Kay.
81: //
82: // Contributor(s): Michael Kay
83: //
|