in src/main/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java [83:174]
public boolean nextNode() {
if (!setStarted) {
setStarted = true;
if (stack == null) {
stack = new Stack();
}
else {
stack.clear();
}
currentRootLocation = parentContext.getCurrentNodePointer();
final NodePointer parent = currentRootLocation.getParent();
if (parent != null) {
// TBD: check type
stack.push(
parent.childIterator(null, reverse, currentRootLocation));
}
}
while (true) {
if (stack.isEmpty()) {
currentRootLocation = currentRootLocation.getParent();
if (currentRootLocation == null
|| currentRootLocation.isRoot()) {
break;
}
final NodePointer parent = currentRootLocation.getParent();
if (parent != null) {
stack.push(
parent.childIterator(
null,
reverse,
currentRootLocation));
}
}
while (!stack.isEmpty()) {
if (!reverse) {
final NodeIterator it = (NodeIterator) stack.peek();
if (it.setPosition(it.getPosition() + 1)) {
currentNodePointer = it.getNodePointer();
if (!currentNodePointer.isLeaf()) {
stack.push(
currentNodePointer.childIterator(
null,
reverse,
null));
}
if (currentNodePointer.testNode(nodeTest)) {
super.setPosition(getCurrentPosition() + 1);
return true;
}
}
else {
// We get here only if the name test failed
// and the iterator ended
stack.pop();
}
}
else {
NodeIterator it = (NodeIterator) stack.peek();
if (it.setPosition(it.getPosition() + 1)) {
currentNodePointer = it.getNodePointer();
if (!currentNodePointer.isLeaf()) {
stack.push(
currentNodePointer.childIterator(
null,
reverse,
null));
}
else if (currentNodePointer.testNode(nodeTest)) {
super.setPosition(getCurrentPosition() + 1);
return true;
}
}
else {
stack.pop();
if (!stack.isEmpty()) {
it = (NodeIterator) stack.peek();
currentNodePointer = it.getNodePointer();
if (currentNodePointer.testNode(nodeTest)) {
super.setPosition(getCurrentPosition() + 1);
return true;
}
}
}
}
}
}
return false;
}