T - the value type of the tree nodepublic final class TreeNode<T> extends Object implements Tree<T,TreeNode<T>>, Iterable<TreeNode<T>>, Copyable<TreeNode<T>>, Serializable
TreeNode is a
 mutable implementation of the Tree interface.| Modifier and Type | Method and Description | 
|---|---|
| TreeNode<T> | attach(T... children)Attaches the given  childrentothisnode. | 
| TreeNode<T> | attach(T child)Attaches the given  childtothisnode. | 
| TreeNode<T> | attach(TreeNode<T> child)Remove the given  childfrom its parent and makes it a child of
 this node by adding it to the end of this node's child array. | 
| int | childCount()Return the number of children this tree node consists of. | 
| TreeNode<T> | copy() | 
| TreeNode<T> | detach()Detaches the subtree rooted at  thisnode from the tree, givingthisnode anullparent. | 
| boolean | equals(Object obj) | 
| TreeNode<T> | getChild(int index)Returns the child at the specified index in this node's child array. | 
| Optional<TreeNode<T>> | getParent()Returns this node's parent if available. | 
| T | getValue()Return the node value | 
| int | hashCode() | 
| TreeNode<T> | insert(int index,
      TreeNode<T> child)Removes the  childfrom its present parent (if it has one), sets
 the child's parent to this node, and then adds the child to this node's
 child array at indexindex. | 
| Iterator<TreeNode<T>> | iterator()Return an iterator that traverses the subtree rooted at  thisnode
 in pre-order. | 
| <B> TreeNode<B> | map(Function<? super T,? extends B> mapper)Returns a new  TreeNodeconsisting of all nodes ofthistree, but with a different value type, created by applying the given
 function to the node values ofthistree. | 
| static <T> TreeNode<T> | of()Return a new  TreeNodewith anulltree value. | 
| static <T> TreeNode<T> | of(T value)Return a new  TreeNodewith the given nodevalue. | 
| static <T> TreeNode<T> | ofTree(Tree<? extends T,?> tree)Return a new  TreeNodefrom the given sourcetree. | 
| static TreeNode<String> | parse(String tree)Parses a (parentheses) tree string, created with
  Tree.toParenthesesString(). | 
| static <B> TreeNode<B> | parse(String tree,
     Function<? super String,? extends B> mapper)Parses a (parentheses) tree string, created with
  Tree.toParenthesesString(). | 
| TreeNode<T> | remove(int index)Removes the child at the specified index from this node's children and
 sets that node's parent to  null. | 
| void | remove(Tree<?,?> child)Remove the  childfromthisnode's child array, giving it
 anullparent. | 
| void | removeAllChildren()Removes all children fo  thisnode and setting their parents tonull. | 
| void | setValue(T value)Sets the user object for this node. | 
| String | toString() | 
clone, finalize, getClass, notify, notifyAll, wait, wait, waitbreadthFirstIterator, breadthFirstStream, childAfter, childAtPath, childBefore, childIterator, childStream, depth, depthFirstIterator, depthFirstStream, equals, firstChild, firstLeaf, getIndex, getPath, getRoot, hashCode, identical, isAncestor, isChild, isDescendant, isLeaf, isRelated, isRoot, isSibling, lastChild, lastLeaf, leafCount, level, nextLeaf, nextNode, nextSibling, pathFromAncestorIterator, postorderIterator, postorderStream, preorderIterator, preorderStream, previousLeaf, previousNode, previousSibling, sharedAncestor, siblingCount, size, stream, toCompactString, toDottyString, toParenthesesString, toParenthesesString, toStringforEach, spliteratorpublic void setValue(T value)
value - the node valuepublic TreeNode<T> getChild(int index)
public int childCount()
TreechildCount in interface Tree<T,TreeNode<T>>public Iterator<TreeNode<T>> iterator()
this node
 in pre-order. The first node returned by the iterator is this
 node.
 Modifying the tree by inserting, removing, or moving a node invalidates any iterator created before the modification.
public TreeNode<T> insert(int index, TreeNode<T> child)
child from its present parent (if it has one), sets
 the child's parent to this node, and then adds the child to this node's
 child array at index index. The new child must not be
 null and must not be an ancestor of this node.index - the index in the child array where this node is to be
        insertedchild - the sub-node to be insertedthis tree-node, for method chainingArrayIndexOutOfBoundsException - if index is out of boundsIllegalArgumentException - if child is an ancestor of
         this nodeNullPointerException - if the given child is nullpublic TreeNode<T> remove(int index)
null. The child node to remove must be
 a MutableTreeNode.index - the index in this node's child array of the child to removethis tree-node, for method chainingArrayIndexOutOfBoundsException - if the index is out of
         boundspublic TreeNode<T> detach()
this node from the tree, giving
 this node a null parent. Does nothing if this
 node is the root of its tree.thispublic void remove(Tree<?,?> child)
child from this node's child array, giving it
 a null parent.child - the child of this node to removeNullPointerException - if the given child is nullIllegalArgumentException - if the given child is not a
         child of this nodepublic void removeAllChildren()
this node and setting their parents to
 null. If this node has no children, this method does
 nothing.public TreeNode<T> attach(TreeNode<T> child)
child from its parent and makes it a child of
 this node by adding it to the end of this node's child array.child - the new child added to this nodethis tree-node, for method chainingNullPointerException - if the given child is null@SafeVarargs public final TreeNode<T> attach(T... children)
children to this node.children - the children to attach to this nodethis tree-node, for method chainingNullPointerException - if the given children array is
         nullpublic TreeNode<T> attach(T child)
child to this node.child - the child to attach to this nodethis tree-node, for method chainingpublic <B> TreeNode<B> map(Function<? super T,? extends B> mapper)
TreeNode consisting of all nodes of this
 tree, but with a different value type, created by applying the given
 function to the node values of this tree.B - the new node typemapper - the node value mapperthis treeNullPointerException - if the given mapper function is
         nullpublic static <T> TreeNode<T> of()
TreeNode with a null tree value.T - the tree-node typepublic static <T> TreeNode<T> of(T value)
TreeNode with the given node value.T - the tree-node typevalue - the node valuepublic static <T> TreeNode<T> ofTree(Tree<? extends T,?> tree)
TreeNode from the given source tree. The
 whole tree is copied.T - the tree value typetree - the source tree the new tree-node is created fromTreeNode from the given source treeNullPointerException - if the source tree is nullpublic static TreeNode<String> parse(String tree)
Tree.toParenthesesString(). The tree string might look like this:
 mul(div(cos(1.0), cos(π)), sin(mul(1.0, z)))
tree - the parentheses tree stringNullPointerException - if the given tree string is
         nullIllegalArgumentException - if the given tree string could not be
         parsedTree.toParenthesesString(Function), 
Tree.toParenthesesString(), 
parse(String, Function)public static <B> TreeNode<B> parse(String tree, Function<? super String,? extends B> mapper)
Tree.toParenthesesString(). The tree string might look like this
 0(1(4,5),2(6),3(7(10,11),8,9))and can be parsed to an integer tree with the following code:
 final Tree<Integer, ?> tree = TreeNode.parse(
     "0(1(4,5),2(6),3(7(10,11),8,9))",
     Integer::parseInt
 );B - the tree node value typetree - the parentheses tree stringmapper - the mapper which converts the serialized string value to
        the desired typeNullPointerException - if one of the arguments is nullIllegalArgumentException - if the given parentheses tree string
         doesn't represent a valid treeTree.toParenthesesString(Function), 
Tree.toParenthesesString(), 
parse(String)© 2007-2018 Franz Wilhelmstötter (2018-10-28 17:23)