KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.om;
2 import net.sf.saxon.expr.LastPositionFinder;
3 import net.sf.saxon.value.SequenceExtent;
4 import net.sf.saxon.value.Value;
5
6 import java.util.List JavaDoc;
7
8 /**
9 * Class ListIterator, iterates over a sequence of items held in a Java ArrayList,
10 * or indeed in any other kind of List
11 */

12
13 public final class ListIterator
14         implements AxisIterator, LastPositionFinder, LookaheadIterator, GroundedIterator {
15
16     int index=0;
17     int length;
18     Item current = null;
19     List JavaDoc list = null;
20
21     /**
22      * Create a ListIterator over a given List
23      * @param list the list: all objects in the list must be instances of {@link Item}
24      */

25
26     public ListIterator(List JavaDoc list) {
27         index = 0;
28         this.list = list;
29         this.length = list.size();
30     }
31
32     public boolean hasNext() {
33         return index<length;
34     }
35
36     public Item next() {
37         if (index >= length) {
38             current = null;
39             index = -1;
40             length = -1;
41             return null;
42         }
43         current = (Item)list.get(index++);
44         return current;
45     }
46
47     public Item current() {
48         return current;
49     }
50
51     public int position() {
52         return index;
53     }
54
55     public int getLastPosition() {
56         return length;
57     }
58
59     public SequenceIterator getAnother() {
60         return new ListIterator(list);
61     }
62
63     /**
64      * Get properties of this iterator, as a bit-significant integer.
65      *
66      * @return the properties of this iterator. This will be some combination of
67      * properties such as {@link GROUNDED}, {@link LAST_POSITION_FINDER},
68      * and {@link LOOKAHEAD}. It is always
69      * acceptable to return the value zero, indicating that there are no known special properties.
70      * It is acceptable for the properties of the iterator to change depending on its state.
71      */

72
73     public int getProperties() {
74         return GROUNDED | LAST_POSITION_FINDER | LOOKAHEAD;
75     }
76
77     /**
78      * Return a SequenceValue containing all the items in the sequence returned by this
79      * SequenceIterator
80      *
81      * @return the corresponding SequenceValue
82      */

83
84     public Value materialize() {
85         return new SequenceExtent(list);
86     }
87
88 }
89
90 //
91
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
92
// you may not use this file except in compliance with the License. You may obtain a copy of the
93
// License at http://www.mozilla.org/MPL/
94
//
95
// Software distributed under the License is distributed on an "AS IS" basis,
96
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
97
// See the License for the specific language governing rights and limitations under the License.
98
//
99
// The Original Code is: all this file.
100
//
101
// The Initial Developer of the Original Code is Michael H. Kay.
102
//
103
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
104
//
105
// Contributor(s): none.
106
//
107

108
Popular Tags