KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.om;
2 import net.sf.saxon.trans.XPathException;
3
4 /**
5  * A SequenceIterator is used to iterate over any XPath 2 sequence (of values or nodes).
6  * To get the next item in a sequence, call next(); if this returns null, you've
7  * reached the end of the sequence.
8  * <p>
9  * A SequenceIterator keeps track of the current Item and the current position.
10  * The objects returned by the SequenceIterator will always be either nodes
11  * (class NodeInfo) or singleton values (class AtomicValue): these are represented
12  * collectively by the interface Item.
13  * <p>
14  * This interface forms part of the public Saxon API. The JavaDoc "since" flag is used from
15  * release 8.4 onwards to indicate methods that are considered to be a stable part
16  * of the API. Methods without a "since" flag should not be regarded as a stable part
17  * of the API.
18  * <p>
19  * Note that the stability of this interface applies to classes that use the interface,
20  * not to classes that implement it. The interface may be extended in future to add new methods.
21  *
22  * @author Michael H. Kay
23  * @since 8.4
24  */

25
26 public interface SequenceIterator {
27
28     /**
29      * Get the next item in the sequence. This method changes the state of the
30      * iterator, in particular it affects the result of subsequent calls of
31      * position() and current().
32      * @throws XPathException if an error occurs retrieving the next item
33      * @return the next item, or null if there are no more items. Once a call
34      * on next() has returned null, no further calls should be made. The preferred
35      * action for an iterator if subsequent calls on next() are made is to return
36      * null again, and all implementations within Saxon follow this rule.
37      * @since 8.4
38      */

39
40     public Item next() throws XPathException;
41
42     /**
43      * Get the current value in the sequence (the one returned by the
44      * most recent call on next()). This will be null before the first
45      * call of next(). This method does not change the state of the iterator.
46      *
47      * @return the current item, the one most recently returned by a call on
48      * next(). Returns null if next() has not been called, or if the end
49      * of the sequence has been reached.
50      * @since 8.4
51      */

52
53     public Item current();
54
55     /**
56      * Get the current position. This will usually be zero before the first call
57      * on next(), otherwise it will be the number of times that next() has
58      * been called. Once next() has returned null, the preferred action is
59      * for subsequent calls on position() to return -1, but not all existing
60      * implementations follow this practice. (In particular, the EmptyIterator
61      * is stateless, and always returns 0 as the value of position(), whether
62      * or not next() has been called.)
63      * <p>
64      * This method does not change the state of the iterator.
65      *
66      * @return the current position, the position of the item returned by the
67      * most recent call of next(). This is 1 after next() has been successfully
68      * called once, 2 after it has been called twice, and so on. If next() has
69      * never been called, the method returns zero. If the end of the sequence
70      * has been reached, the value returned will always be <= 0; the preferred
71      * value is -1.
72      *
73      * @since 8.4
74      */

75
76     public int position();
77
78     /**
79      * Get another SequenceIterator that iterates over the same items as the original,
80      * but which is repositioned at the start of the sequence.
81      * <p>
82      * This method allows access to all the items in the sequence without disturbing the
83      * current position of the iterator. Internally, its main use is in evaluating the last()
84      * function.
85      * <p>
86      * This method does not change the state of the iterator.
87      *
88      * @exception XPathException if any error occurs
89      * @return a SequenceIterator that iterates over the same items,
90      * positioned before the first item
91      * @since 8.4
92      */

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

104
105     public int getProperties();
106
107     /**
108      * Property value: the iterator is "grounded". This means that (a) the
109      * iterator must be an instance of {@link GroundedIterator}, and (b) the
110      * implementation of the materialize() method must be efficient (in particular,
111      * it should not involve the creation of new objects)
112      */

113
114     public static final int GROUNDED = 1<<0;
115
116     /**
117      * Property value: the iterator knows the number of items that it will deliver.
118      * This means that (a) the iterator must be an instance of {@link net.sf.saxon.expr.LastPositionFinder},
119      * and (b) the implementation of the getLastPosition() method must be efficient (in particular,
120      * it should take constant time, rather than time proportional to the length of the sequence)
121      */

122
123     public static final int LAST_POSITION_FINDER = 1<<1;
124
125     /**
126      * Property value: the iterator knows whether there are more items still to come. This means
127      * that (a) the iterator must be an instance of {@link LookaheadIterator}, and (b) the
128      * implementation of the hasNext() method must be efficient (more efficient than the client doing
129      * it)
130      */

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