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 11 12 final class PrecedingSiblingEnumeration implements AxisEnumeration { 13 14 TinyDocumentImpl document; 15 TinyNodeImpl startNode; 16 int nextNodeNr; 17 int depth; 18 NodeTest test; 19 TinyNodeImpl parentNode; 20 int last = -1; 21 22 protected PrecedingSiblingEnumeration(TinyDocumentImpl doc, TinyNodeImpl node, 23 NodeTest nodeTest) { 24 document = doc; 25 document.ensurePriorIndex(); 26 test = nodeTest; 27 startNode = node; 28 nextNodeNr = node.nodeNr; 29 depth = doc.depth[nextNodeNr]; 30 parentNode = node.parent; advance(); 32 } 33 34 public boolean hasMoreElements() { 35 return nextNodeNr >= 0; 36 } 37 38 public NodeInfo nextElement() { 39 TinyNodeImpl node = document.getNode(nextNodeNr); 40 node.setParentNode(parentNode); 41 advance(); 42 return node; 43 } 44 45 private void advance() { 46 do { 47 nextNodeNr = document.prior[nextNodeNr]; 48 } while ( nextNodeNr >= 0 && 49 !test.matches(document.nodeType[nextNodeNr], 50 document.nameCode[nextNodeNr])); 51 67 } 68 69 public boolean isSorted() { 70 return false; 71 } 72 73 public boolean isReverseSorted() { 74 return true; 75 } 76 77 public boolean isPeer() { 78 return true; 79 } 80 81 84 85 public int getLastPosition() { 86 if (last >= 0) return last; 87 PrecedingSiblingEnumeration enum = 88 new PrecedingSiblingEnumeration(document, startNode, test); 89 last = 0; 90 while (enum.hasMoreElements()) { 91 enum.nextElement(); 92 last++; 93 } 94 return last; 95 } 96 } 97 98 99 | Popular Tags |