/** * Returns whether or not there are more nodes available based on the current configuration of this NodeTreeWalker. * @return True if there are more Nodes available, based on the current configuration, or false otherwise. */ public boolean hasMoreNodes() { if (this.mNextNode == null)//if we've already generated mNextNode { if (this.mCurrentNode == null) this.mNextNode = this.mRootNode.getFirstChild(); else { if (this.mDepthFirst) this.mNextNode = getNextNodeDepthFirst(); else this.mNextNode = getNextNodeBreadthFirst(); } } return (this.mNextNode != null); }
/** * Traverses to the next Node from the current Node, using either depth-first or breadth-first tree traversal as appropriate. * @return The next Node from the current Node. */ public Node nextNode() { if (this.mNextNode != null)//check if we've already found the next Node by calling hasMoreNodes() { this.mCurrentNode = this.mNextNode; this.mNextNode = null;//reset mNextNode } else { //Check if we have started traversing yet. If not, start with first child (for either traversal method). if (this.mCurrentNode == null) this.mCurrentNode = this.mRootNode.getFirstChild(); else { if (this.mDepthFirst) this.mCurrentNode = getNextNodeDepthFirst(); else this.mCurrentNode = getNextNodeBreadthFirst(); } } return (this.mCurrentNode); }