/** * <p>Returns the next <code>Node</code> on the stack and pushes all of its * children onto the stack, allowing us to walk the node tree without the * use of recursion. If there are no more nodes on the stack then null is * returned.</p> * * @return Node The next <code>Node</code> on the stack or null if there * isn't a next node. */ public Node nextNode() { // if no next node return null if (!hasNext()) { return null; } // pop the next node off of the stack and push all of its children onto // the stack currentNode = nodes.pop(); currentChildren = currentNode.getChildNodes(); int childLen = (currentChildren != null) ? currentChildren.getLength() : 0; // put the children node on the stack in first to last order for (int i = childLen - 1; i >= 0; i--) { nodes.add(currentChildren.item(i)); } return currentNode; }
/** * <p>Returns the next <code>Node</code> on the stack and pushes all of its * children onto the stack, allowing us to walk the node tree without the * use of recursion. If there are no more nodes on the stack then null is * returned.</p> * * @return Node The next <code>Node</code> on the stack or null if there * isn't a next node. */ public Node nextNode() { // if no next node return null if (!hasNext()) { return null; } // pop the next node off of the stack and push all of its children onto // the stack currentNode = nodes.pop(); currentChildren = currentNode.getChildNodes(); int childLen = (currentChildren != null) ? currentChildren.getLength() : 0; // put the children node on the stack in first to last order for (int i = childLen - 1; i >= 0; i--) { nodes.add(currentChildren.item(i)); } return currentNode; }