}
}
while (!stack.isEmpty()){
if (!reverse){
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 = (PropertyIterator)stack.peek();
currentNodePointer = it.getNodePointer();
if (currentNodePointer.testNode(nodeTest)){
super.setPosition(getCurrentPosition() + 1);
return true;
}
}