KickJava   Java API By Example, From Geeks To Geeks.

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


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 single object (typically a sub-expression of an expression)
8  */

9 public class MonoIterator implements Iterator JavaDoc {
10
11     private Object JavaDoc thing; // the single object in the collection
12
private boolean gone; // true if the single object has already been returned
13

14     public MonoIterator(Object JavaDoc thing) {
15         this.gone = false;
16         this.thing = thing;
17     }
18
19     /**
20      * Returns <tt>true</tt> if the iteration has more elements. (In other
21      * words, returns <tt>true</tt> if <tt>next</tt> would return an element
22      * rather than throwing an exception.)
23      *
24      * @return <tt>true</tt> if the iterator has more elements.
25      */

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

37
38     public Object JavaDoc next() {
39         if (gone) {
40             throw new NoSuchElementException JavaDoc();
41         } else {
42             gone = true;
43             return thing;
44         }
45     }
46
47     /**
48      *
49      * Removes from the underlying collection the last element returned by the
50      * iterator (optional operation). This method can be called only once per
51      * call to <tt>next</tt>. The behavior of an iterator is unspecified if
52      * the underlying collection is modified while the iteration is in
53      * progress in any way other than by calling this method.
54      *
55      * @exception UnsupportedOperationException if the <tt>remove</tt>
56      * operation is not supported by this Iterator (which is the
57      * case for this iterator).
58      */

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