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