1 package net.sf.saxon.tree; 2 import net.sf.saxon.om.AxisIterator; 3 import net.sf.saxon.om.Item; 4 import net.sf.saxon.om.LookaheadIterator; 5 import net.sf.saxon.pattern.NodeTest; 6 7 abstract class TreeEnumeration implements AxisIterator, LookaheadIterator { 8 9 protected NodeImpl start; 10 protected NodeImpl next; 11 protected NodeTest nodeTest; 12 protected NodeImpl current = null; 13 protected int position = 0; 14 16 23 24 public TreeEnumeration(NodeImpl origin, NodeTest nodeTest) { 25 next = origin; 26 start = origin; 27 this.nodeTest = nodeTest; 28 } 29 30 35 36 protected boolean conforms(NodeImpl node) { 37 if (node==null || nodeTest==null) { 38 return true; 39 } 40 return nodeTest.matches(node); 41 } 42 43 46 47 protected final void advance() { 48 do { 49 step(); 50 } while (!conforms(next)); 51 } 52 53 57 58 protected abstract void step(); 59 60 68 69 public boolean hasNext() { 70 return next != null; 71 } 72 73 76 77 public final Item next() { 78 if (next==null) { 79 current = null; 80 position = -1; 81 return null; 82 } else { 83 current = next; 84 position++; 85 advance(); 86 return current; 87 } 88 } 89 90 93 94 public final Item current() { 95 return current; 96 } 97 98 101 102 public final int position() { 103 return position; 104 } 105 106 115 116 public int getProperties() { 117 return LOOKAHEAD; 118 } 119 120 129 130 } 132 133 134 | Popular Tags |