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 15 16 final class PrecedingEnumeration extends AxisIteratorImpl { 17 18 private TinyTree tree; 19 private TinyNodeImpl startNode; 20 private NodeTest test; 21 private int nextAncestorDepth; 22 private boolean includeAncestors; 23 24 public PrecedingEnumeration(TinyTree doc, TinyNodeImpl node, 25 NodeTest nodeTest, boolean includeAncestors) { 26 27 this.includeAncestors = includeAncestors; 28 test = nodeTest; 29 tree = doc; 30 startNode = node; 31 current = startNode; 32 nextAncestorDepth = doc.depth[node.nodeNr] - 1; 33 } 34 35 public Item next() { 36 int nextNodeNr = ((TinyNodeImpl)current).nodeNr; 37 while (true) { 38 nextNodeNr--; 39 if (!includeAncestors) { 40 while (nextAncestorDepth >= 0 && tree.depth[nextNodeNr] == nextAncestorDepth) { 42 if (nextAncestorDepth-- <= 0) { current = null; 44 position = -1; 45 return null; 46 }; 47 nextNodeNr--; 48 } 49 } else if (tree.depth[nextNodeNr] == 0) { 50 current = null; 51 position = -1; 52 return null; 53 } 54 if (test.matches(tree, nextNodeNr)) { 55 position++; 56 current = tree.getNode(nextNodeNr); 57 return current; 58 } 59 if (tree.depth[nextNodeNr] == 0) { 60 current = null; 61 position = -1; 62 return null; 63 } 64 } 65 } 66 67 70 71 public SequenceIterator getAnother() { 72 return new PrecedingEnumeration(tree, startNode, test, includeAncestors); 73 } 74 } 75 76 77 78 79 | Popular Tags |