/** * Sets the specified Node as the root Node. * Resets the current position in the tree. * @param rootNode The Node to set as the root of the tree. * @throws NullPointerException if rootNode is null. */ public void setRootNode(Node rootNode) throws NullPointerException { initRootNode(rootNode); }
/** * Sets the current Node as the root Node. * Resets the current position in the tree. * @throws NullPointerException if the current Node is null (i.e. if the tree traversal has not yet begun). */ public void setCurrentNodeAsRootNode() throws NullPointerException { if (this.mCurrentNode == null) throw new NullPointerException("Current Node is null, cannot set as root Node."); initRootNode(this.mCurrentNode); }
/** * Creates a new instance of NodeTreeWalker using the specified type of tree traversal and maximum depth from the root Node to traverse. * @param rootNode The Node to set as the root of the tree. * @param depthFirst Whether to use depth-first (true) or breadth-first (false) tree traversal. * @param maxDepth The maximum depth from the root Node that this NodeTreeWalker may traverse. This must be > 0 or equal to -1. * @throws NullPointerException if rootNode is null. * @throws IllegalArgumentException maxDepth is not > 0 or equal to -1. */ public NodeTreeWalker(Node rootNode, boolean depthFirst, int maxDepth) { //check maxDepth is valid if ( ! ((maxDepth >= 1) || (maxDepth == -1)))//if not one of these valid possibilities throw new IllegalArgumentException("Paramater maxDepth must be > 0 or equal to -1."); initRootNode(rootNode);//this method also checks if rootNode is valid this.mDepthFirst = depthFirst; this.mMaxDepth = maxDepth; }