KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > om > EmptyIterator


1 package net.sf.saxon.om;
2
3 import net.sf.saxon.expr.LastPositionFinder;
4 import net.sf.saxon.expr.ReversibleIterator;
5 import net.sf.saxon.value.EmptySequence;
6 import net.sf.saxon.value.Value;
7
8 /**
9  * EmptyIterator: an iterator over an empty sequence. Since such an iterator has no state,
10  * only one instance is required; therefore a singleton instance is available via the static
11  * getInstance() method.
12  */

13
14 public class EmptyIterator implements AxisIterator,
15         ReversibleIterator, LastPositionFinder, GroundedIterator, LookaheadIterator {
16
17     private static EmptyIterator theInstance = new EmptyIterator();
18
19     /**
20      * Get an EmptyIterator, an iterator over an empty sequence.
21      * @return an EmptyIterator (in practice, this always returns the same
22      * one)
23      */

24     public static EmptyIterator getInstance() {
25         return theInstance;
26     }
27
28     /**
29      * Get the next item. This method should not be called unless hasNext() returns true.
30      * @return the next item. For the EmptyIterator this is always null.
31      */

32     public Item next() {
33         return null;
34     }
35
36     /**
37      * Get the current item, that is, the item returned by the most recent call of next().
38      * @return the current item. For the EmptyIterator this is always null.
39      */

40     public Item current() {
41         return null;
42     }
43
44     /**
45      * Get the position of the current item.
46      * @return the position of the current item. For the EmptyIterator this is always zero
47      * (whether or not the next() method has been called).
48      */

49     public int position() {
50         return 0;
51     }
52
53     /**
54      * Get the position of the last item in the sequence.
55      * @return the position of the last item in the sequence, always zero in
56      * this implementation
57      */

58     public int getLastPosition() {
59         return 0;
60     }
61
62     /**
63      * Get another iterator over the same items, positioned at the start.
64      * @return another iterator over an empty sequence (in practice, it
65      * returns the same iterator each time)
66      */

67     public SequenceIterator getAnother() {
68         return theInstance;
69     }
70
71     /**
72      * Indicate that any nodes returned in the sequence will be atomized. This
73      * means that if it wishes to do so, the implementation can return the typed
74      * values of the nodes rather than the nodes themselves. The implementation
75      * is free to ignore this hint.
76      * @param atomizing true if the caller of this iterator will atomize any
77      * nodes that are returned, and is therefore willing to accept the typed
78      * value of the nodes instead of the nodes themselves.
79      */

80
81     //public void setIsAtomizing(boolean atomizing) {}
82

83     /**
84      * Get another iterator over the same items, in reverse order.
85      * @return a reverse iterator over an empty sequence (in practice, it
86      * returns the same iterator each time)
87      */

88     public SequenceIterator getReverseIterator() {
89         return theInstance;
90     }
91
92     /**
93      * Get properties of this iterator, as a bit-significant integer.
94      *
95      * @return the properties of this iterator. This will be some combination of
96      * properties such as {@link GROUNDED}, {@link LAST_POSITION_FINDER},
97      * and {@link LOOKAHEAD}. It is always
98      * acceptable to return the value zero, indicating that there are no known special properties.
99      * It is acceptable for the properties of the iterator to change depending on its state.
100      */

101
102     public int getProperties() {
103         return GROUNDED | LAST_POSITION_FINDER | LOOKAHEAD;
104     }
105
106     /**
107      * Return a Value containing all the items in the sequence returned by this
108      * SequenceIterator. This should be an "in-memory" value, not a Closure.
109      *
110      * @return the corresponding Value
111      */

112
113     public Value materialize() {
114         return EmptySequence.getInstance();
115     }
116
117     /**
118      * Determine whether there are more items to come. Note that this operation
119      * is stateless and it is not necessary (or usual) to call it before calling
120      * next(). It is used only when there is an explicit need to tell if we
121      * are at the last element.
122      *
123      * @return true if there are more nodes
124      */

125
126     public boolean hasNext() {
127         return false;
128     }
129
130 }
131
132 //
133
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
134
// you may not use this file except in compliance with the License. You may obtain a copy of the
135
// License at http://www.mozilla.org/MPL/
136
//
137
// Software distributed under the License is distributed on an "AS IS" basis,
138
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
139
// See the License for the specific language governing rights and limitations under the License.
140
//
141
// The Original Code is: all this file.
142
//
143
// The Initial Developer of the Original Code is Michael H. Kay.
144
//
145
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
146
//
147
// Contributor(s): none.
148
//
149
Popular Tags