001: package net.sf.saxon.om;
002:
003: import net.sf.saxon.expr.LastPositionFinder;
004: import net.sf.saxon.expr.ReversibleIterator;
005: import net.sf.saxon.value.EmptySequence;
006: import net.sf.saxon.value.Value;
007:
008: /**
009: * EmptyIterator: an iterator over an empty sequence. Since such an iterator has no state,
010: * only one instance is required; therefore a singleton instance is available via the static
011: * getInstance() method.
012: */
013:
014: public class EmptyIterator implements AxisIterator, ReversibleIterator,
015: LastPositionFinder, GroundedIterator, LookaheadIterator {
016:
017: private static EmptyIterator theInstance = new EmptyIterator();
018:
019: /**
020: * Get an EmptyIterator, an iterator over an empty sequence.
021: * @return an EmptyIterator (in practice, this always returns the same
022: * one)
023: */
024: public static EmptyIterator getInstance() {
025: return theInstance;
026: }
027:
028: /**
029: * Get the next item. This method should not be called unless hasNext() returns true.
030: * @return the next item. For the EmptyIterator this is always null.
031: */
032: public Item next() {
033: return null;
034: }
035:
036: /**
037: * Get the current item, that is, the item returned by the most recent call of next().
038: * @return the current item. For the EmptyIterator this is always null.
039: */
040: public Item current() {
041: return null;
042: }
043:
044: /**
045: * Get the position of the current item.
046: * @return the position of the current item. For the EmptyIterator this is always zero
047: * (whether or not the next() method has been called).
048: */
049: public int position() {
050: return 0;
051: }
052:
053: /**
054: * Get the position of the last item in the sequence.
055: * @return the position of the last item in the sequence, always zero in
056: * this implementation
057: */
058: public int getLastPosition() {
059: return 0;
060: }
061:
062: /**
063: * Get another iterator over the same items, positioned at the start.
064: * @return another iterator over an empty sequence (in practice, it
065: * returns the same iterator each time)
066: */
067: public SequenceIterator getAnother() {
068: return theInstance;
069: }
070:
071: /**
072: * Indicate that any nodes returned in the sequence will be atomized. This
073: * means that if it wishes to do so, the implementation can return the typed
074: * values of the nodes rather than the nodes themselves. The implementation
075: * is free to ignore this hint.
076: * @param atomizing true if the caller of this iterator will atomize any
077: * nodes that are returned, and is therefore willing to accept the typed
078: * value of the nodes instead of the nodes themselves.
079: */
080:
081: //public void setIsAtomizing(boolean atomizing) {}
082: /**
083: * Get another iterator over the same items, in reverse order.
084: * @return a reverse iterator over an empty sequence (in practice, it
085: * returns the same iterator each time)
086: */
087: public SequenceIterator getReverseIterator() {
088: return theInstance;
089: }
090:
091: /**
092: * Get properties of this iterator, as a bit-significant integer.
093: *
094: * @return the properties of this iterator. This will be some combination of
095: * properties such as {@link GROUNDED}, {@link LAST_POSITION_FINDER},
096: * and {@link LOOKAHEAD}. It is always
097: * acceptable to return the value zero, indicating that there are no known special properties.
098: * It is acceptable for the properties of the iterator to change depending on its state.
099: */
100:
101: public int getProperties() {
102: return GROUNDED | LAST_POSITION_FINDER | LOOKAHEAD;
103: }
104:
105: /**
106: * Return a Value containing all the items in the sequence returned by this
107: * SequenceIterator. This should be an "in-memory" value, not a Closure.
108: *
109: * @return the corresponding Value
110: */
111:
112: public Value materialize() {
113: return EmptySequence.getInstance();
114: }
115:
116: /**
117: * Determine whether there are more items to come. Note that this operation
118: * is stateless and it is not necessary (or usual) to call it before calling
119: * next(). It is used only when there is an explicit need to tell if we
120: * are at the last element.
121: *
122: * @return true if there are more nodes
123: */
124:
125: public boolean hasNext() {
126: return false;
127: }
128:
129: }
130:
131: //
132: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
133: // you may not use this file except in compliance with the License. You may obtain a copy of the
134: // License at http://www.mozilla.org/MPL/
135: //
136: // Software distributed under the License is distributed on an "AS IS" basis,
137: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
138: // See the License for the specific language governing rights and limitations under the License.
139: //
140: // The Original Code is: all this file.
141: //
142: // The Initial Developer of the Original Code is Michael H. Kay.
143: //
144: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
145: //
146: // Contributor(s): none.
147: //
|