KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > tinytree > PrecedingSiblingEnumeration


1 package net.sf.saxon.tinytree;
2 import net.sf.saxon.om.AxisIteratorImpl;
3 import net.sf.saxon.om.Item;
4 import net.sf.saxon.om.SequenceIterator;
5 import net.sf.saxon.pattern.NodeTest;
6
7 /**
8 * This class supports the preceding-sibling axis.
9 * The starting node must be an element, text node, comment, or processing instruction:
10 * to ensure this, construct the enumeration using NodeInfo#getEnumeration()
11 */

12
13 final class PrecedingSiblingEnumeration extends AxisIteratorImpl {
14
15     private TinyTree document;
16     private TinyNodeImpl startNode;
17     private int nextNodeNr;
18     private NodeTest test;
19     private TinyNodeImpl parentNode;
20
21     PrecedingSiblingEnumeration(TinyTree doc, TinyNodeImpl node, NodeTest nodeTest) {
22         document = doc;
23         document.ensurePriorIndex();
24         test = nodeTest;
25         startNode = node;
26         nextNodeNr = node.nodeNr;
27         parentNode = node.parent; // doesn't matter if this is null (unknown)
28
}
29
30     public Item next() {
31 // if (nextNodeNr < 0) {
32
// return null;
33
// }
34
while (true) {
35             nextNodeNr = document.prior[nextNodeNr];
36             if (nextNodeNr < 0) {
37                 current = null;
38                 position = -1;
39                 return null;
40             }
41             if (test.matches(document, nextNodeNr)) {
42                 position++;
43                 current = document.getNode(nextNodeNr);
44                 ((TinyNodeImpl)current).setParentNode(parentNode);
45                 return current;
46             };
47         }
48     }
49
50     /**
51     * Get another enumeration of the same nodes
52     */

53
54     public SequenceIterator getAnother() {
55         return new PrecedingSiblingEnumeration(document, startNode, test);
56     }
57
58 }
59
60
61 //
62
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
63
// you may not use this file except in compliance with the License. You may obtain a copy of the
64
// License at http://www.mozilla.org/MPL/
65
//
66
// Software distributed under the License is distributed on an "AS IS" basis,
67
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
68
// See the License for the specific language governing rights and limitations under the License.
69
//
70
// The Original Code is: all this file.
71
//
72
// The Initial Developer of the Original Code is Michael H. Kay.
73
//
74
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
75
//
76
// Contributor(s): none.
77
//
78
Popular Tags