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 14 15 final class SiblingEnumeration implements AxisEnumeration { 16 17 TinyDocumentImpl document; 18 int nextNodeNr; 19 NodeTest test; 20 TinyNodeImpl startNode; 21 TinyNodeImpl parentNode; 22 boolean getChildren; 23 int last = -1; 24 25 protected SiblingEnumeration(TinyDocumentImpl doc, TinyNodeImpl node, 26 NodeTest nodeTest, boolean getChildren) { 27 document = doc; 28 test = nodeTest; 29 startNode = node; 30 this.getChildren = getChildren; 31 if (getChildren) { parentNode = node; 33 34 nextNodeNr = node.nodeNr + 1; 36 37 } else { parentNode = (TinyNodeImpl)node.getParent(); 39 40 nextNodeNr = doc.next[node.nodeNr]; 42 } 43 44 if (nextNodeNr >= 0) { 46 if (!nodeTest.matches(document.nodeType[nextNodeNr], 47 document.nameCode[nextNodeNr])) { 48 advance(); 49 } 50 } 51 } 52 53 public boolean hasMoreElements() { 54 return nextNodeNr >= 0; 55 } 56 57 public NodeInfo nextElement() { 58 TinyNodeImpl node = document.getNode(nextNodeNr); 59 node.setParentNode(parentNode); 60 advance(); 61 return node; 62 } 63 64 private void advance() { 65 do { 66 nextNodeNr = document.next[nextNodeNr]; 67 } while ( nextNodeNr >= 0 && 68 !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 true; 82 } 83 84 87 88 public int getLastPosition() { 89 if (last >= 0) return last; 90 SiblingEnumeration enum = 91 new SiblingEnumeration(document, startNode, test, getChildren); 92 last = 0; 93 while (enum.hasMoreElements()) { 94 enum.nextElement(); 95 last++; 96 } 97 return last; 98 } 99 100 } 101 102 103 | Popular Tags |