1 package com.icl.saxon.tinytree; 2 import com.icl.saxon.pattern.NodeTest; 3 import com.icl.saxon.om.NodeInfo; 4 import com.icl.saxon.om.AxisEnumeration; 5 6 10 11 final class FollowingEnumeration implements AxisEnumeration { 12 13 private TinyDocumentImpl document; 14 private TinyNodeImpl startNode; 15 private int nextNodeNr; 16 private NodeTest test; 17 int last = -1; 18 boolean includeDescendants; 19 20 public FollowingEnumeration(TinyDocumentImpl doc, TinyNodeImpl node, 21 NodeTest nodeTest, boolean includeDescendants) { 22 document = doc; 23 test = nodeTest; 24 startNode = node; 25 nextNodeNr = node.nodeNr; 26 this.includeDescendants = includeDescendants; 27 int depth = doc.depth[nextNodeNr]; 28 29 if (includeDescendants) { 31 nextNodeNr++; 32 } else { 33 do { 34 nextNodeNr++; 35 if (nextNodeNr >= doc.numberOfNodes) { 36 nextNodeNr = -1; 37 return; 38 } 39 } while (doc.depth[nextNodeNr] > depth); 40 } 41 42 if (!test.matches(doc.nodeType[nextNodeNr], doc.nameCode[nextNodeNr])) { 43 advance(); 44 } 45 } 46 47 private void advance() { 48 do { 49 nextNodeNr++; 50 if (nextNodeNr >= document.numberOfNodes) { 51 nextNodeNr = -1; 52 return; 53 } 54 } while (!test.matches(document.nodeType[nextNodeNr], document.nameCode[nextNodeNr])); 55 } 56 57 public boolean hasMoreElements() { 58 return nextNodeNr >= 0; 59 } 60 61 public NodeInfo nextElement() { 62 TinyNodeImpl node = document.getNode(nextNodeNr); 63 advance(); 64 return node; 65 } 66 67 public boolean isSorted() { 68 return true; 69 } 70 71 public boolean isReverseSorted() { 72 return false; 73 } 74 75 public boolean isPeer() { 76 return false; 77 } 78 79 82 83 public int getLastPosition() { 84 if (last >= 0) return last; 85 FollowingEnumeration enum = 86 new FollowingEnumeration(document, startNode, test, includeDescendants); 87 last = 0; 88 while (enum.hasMoreElements()) { 89 enum.nextElement(); 90 last++; 91 } 92 return last; 93 } 94 95 } 96 97 98 | Popular Tags |