| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.tree.tiny; |
| 9 |
|
| 10 |
import net.sf.saxon.om.NodeInfo; |
| 11 |
import net.sf.saxon.pattern.NodeTest; |
| 12 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 13 |
|
| 14 |
import java.util.function.IntPredicate; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
final class PrecedingSiblingIterator implements AxisIterator { |
| 23 |
|
| 24 |
private TinyTree document; |
| 25 |
private TinyNodeImpl startNode; |
| 26 |
private int nextNodeNr; |
| 27 |
private NodeTest test; |
| 28 |
private TinyNodeImpl parentNode; |
| 29 |
private final IntPredicate matcher; |
| 30 |
|
| 31 |
PrecedingSiblingIterator(TinyTree doc, TinyNodeImpl node, NodeTest nodeTest) { |
| 32 |
document = doc; |
| 33 |
document.ensurePriorIndex(); |
| 34 |
test = nodeTest; |
| 35 |
startNode = node; |
| 36 |
nextNodeNr = node.nodeNr; |
| 37 |
parentNode = node.parent; |
| 38 |
this.matcher = nodeTest.getMatcher(doc); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
public NodeInfo next() { |
| 43 |
if (nextNodeNr < 0) { |
| 44 |
|
| 45 |
return null; |
| 46 |
} |
| 47 |
while (true) { |
| 48 |
nextNodeNr = document.prior[nextNodeNr]; |
| 49 |
if (nextNodeNr < 0) { |
| 50 |
return null; |
| 51 |
} |
| 52 |
if (matcher.test(nextNodeNr)) { |
| 53 |
TinyNodeImpl next = document.getNode(nextNodeNr); |
| 54 |
next.setParentNode(parentNode); |
| 55 |
return next; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
} |
| 61 |
|