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 11 12 final class FollowingEnumeration extends AxisIteratorImpl { 13 14 private TinyTree tree; 15 private TinyNodeImpl startNode; 16 private NodeTest test; 17 private boolean includeDescendants; 18 19 29 30 public FollowingEnumeration(TinyTree doc, TinyNodeImpl node, 31 NodeTest nodeTest, boolean includeDescendants) { 32 tree = doc; 33 test = nodeTest; 34 startNode = node; 35 this.includeDescendants = includeDescendants; 36 } 37 38 public Item next() { 39 int nodeNr; 40 if (position == 0) { 41 nodeNr = startNode.nodeNr; 43 int depth = tree.depth[nodeNr]; 44 45 if (includeDescendants) { 47 nodeNr++; 48 } else { 49 do { 50 nodeNr++; 51 if (tree.depth[nodeNr] == 0) { 52 current = null; 53 position = -1; 54 return null; 55 } 56 } while (tree.depth[nodeNr] > depth); 57 } 58 } else { 59 nodeNr = ((TinyNodeImpl)current).nodeNr + 1; 60 } 61 62 while (true) { 63 if (tree.depth[nodeNr] == 0) { 64 current = null; 65 position = -1; 66 return null; 67 } 68 if (test.matches(tree, nodeNr)) { 69 position++; 70 current = tree.getNode(nodeNr); 71 return current; 72 } 73 nodeNr++; 74 } 75 } 76 77 80 81 public SequenceIterator getAnother() { 82 return new FollowingEnumeration(tree, startNode, test, includeDescendants); 83 } 84 } 85 86 87 | Popular Tags |