KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.expr;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.NoSuchElementException JavaDoc;
5
6 /**
7  * An iterator over a pair of objects (typically sub-expressions of an expression)
8  */

9 public class PairIterator implements Iterator JavaDoc {
10
11     private Object JavaDoc one;
12     private Object JavaDoc two;
13     private int pos = 0;
14
15     public PairIterator(Object JavaDoc one, Object JavaDoc two) {
16         this.one = one;
17         this.two = two;
18     }
19
20     /**
21      * Returns <tt>true</tt> if the iteration has more elements. (In other
22      * words, returns <tt>true</tt> if <tt>next</tt> would return an element
23      * rather than throwing an exception.)
24      *
25      * @return <tt>true</tt> if the iterator has more elements.
26      */

27
28     public boolean hasNext() {
29         return pos<2;
30     }
31
32     /**
33      * Returns the next element in the iteration.
34      *
35      * @return the next element in the iteration.
36      * @exception NoSuchElementException iteration has no more elements.
37      */

38     public Object JavaDoc next() {
39         switch (pos++) {
40             case 0: return one;
41             case 1: return two;
42             default: throw new NoSuchElementException JavaDoc();
43         }
44     }
45
46     /**
47      *
48      * Removes from the underlying collection the last element returned by the
49      * iterator (optional operation). This method can be called only once per
50      * call to <tt>next</tt>. The behavior of an iterator is unspecified if
51      * the underlying collection is modified while the iteration is in
52      * progress in any way other than by calling this method.
53      *
54      * @exception UnsupportedOperationException if the <tt>remove</tt>
55      * operation is not supported by this Iterator.
56
57      * @exception IllegalStateException if the <tt>next</tt> method has not
58      * yet been called, or the <tt>remove</tt> method has already
59      * been called after the last call to the <tt>next</tt>
60      * method.
61      */

62     public void remove() {
63         throw new UnsupportedOperationException JavaDoc();
64     }
65 }
66
67
68 //
69
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
70
// you may not use this file except in compliance with the License. You may obtain a copy of the
71
// License at http://www.mozilla.org/MPL/
72
//
73
// Software distributed under the License is distributed on an "AS IS" basis,
74
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
75
// See the License for the specific language governing rights and limitations under the License.
76
//
77
// The Original Code is: all this file.
78
//
79
// The Initial Developer of the Original Code is Michael H. Kay.
80
//
81
// Contributor(s): Michael Kay
82
//
83
Popular Tags