KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > expr > MultiIterator


1 package net.sf.saxon.expr;
2
3 import java.util.Iterator JavaDoc;
4
5 /**
6  * An iterator that combines the results of a sequence of iterators
7  */

8 public class MultiIterator implements Iterator JavaDoc {
9
10     private Iterator JavaDoc[] array;
11     private int current;
12
13     public MultiIterator(Iterator JavaDoc[] 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 JavaDoc 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 JavaDoc();
66     }
67 }
68
69
70 //
71
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
72
// you may not use this file except in compliance with the License. You may obtain a copy of the
73
// License at http://www.mozilla.org/MPL/
74
//
75
// Software distributed under the License is distributed on an "AS IS" basis,
76
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
77
// See the License for the specific language governing rights and limitations under the License.
78
//
79
// The Original Code is: all this file.
80
//
81
// The Initial Developer of the Original Code is Michael H. Kay.
82
//
83
// Contributor(s): Michael Kay
84
//
85
Popular Tags