Home

# Class goog.structs.TreeNode

Generic tree node data structure with arbitrary number of child nodes. It is possible to create a dynamic tree structure by overriding {@link #getParent} and {@link #getChildren} in a subclass. All other getters will automatically work.

extends goog.structs.Node

Instance Method Summary
| `addChild(!goog.structs.TreeNode child)` Appends a child node to this node.
| `addChildAt(!goog.structs.TreeNode child, number index)` Inserts a child node at the given index.
| `clone() ⇒ !goog.structs.TreeNode`
| `contains(!goog.structs.TreeNode node) ⇒ boolean` Tells whether this node is the ancestor of the given node.
| `deepClone() ⇒ !goog.structs.TreeNode`
| `forEachChild(function (goog.structs.TreeNode, number, Array): ? f, ?Object= opt_this)` Traverses all child nodes.
| `forEachDescendant(function (goog.structs.TreeNode): ? f, ?Object= opt_this)` Traverses all child nodes recursively in preorder.
| `getAncestors() ⇒ !Array`
| `getChildAt(number index) ⇒ ?goog.structs.TreeNode` Gets the child node of this node at the given index.
| `getChildCount() ⇒ number`
| `getChildren() ⇒ !Array`
| `getDepth() ⇒ number`
| `getParent() ⇒ ?goog.structs.TreeNode`
| `getRoot() ⇒ !goog.structs.TreeNode`
| `getSubtreeKeys() ⇒ !Array` Builds a nested array structure from the node keys in this node's subtree to facilitate testing tree operations that change the hierarchy.

`isLastChild() ⇒ boolean`

Tells if the node is the last child of its parent. This method helps how to connect the tree nodes with lines: L shapes should be used before the last children and |- shapes before the rest. Schematic tree visualization:

    Node1
    |-Node2
    | L-Node3
    |   |-Node4
    |   L-Node5
    L-Node6

| `isLeaf() ⇒ boolean`
| `removeChild(?goog.structs.TreeNode child) ⇒ ?goog.structs.TreeNode` Removes the given child node of this node.
| `removeChildAt(number index) ⇒ ?goog.structs.TreeNode` Removes the child node at the given index.
| `removeChildren()` Removes all child nodes of this node.
| `replaceChild(!goog.structs.TreeNode newChild, !goog.structs.TreeNode oldChild) ⇒ !goog.structs.TreeNode` Replaces the given child node.
| `replaceChildAt(!goog.structs.TreeNode newChild, number index) ⇒ !goog.structs.TreeNode` Replaces a child node at the given index.
| `setParent(?goog.structs.TreeNode parent)` Sets the parent node of this node. The callers must ensure that the parent node and only that has this node among its children.
| `traverse(function (goog.structs.TreeNode): (boolean|undefined) f, ?Object= opt_this)` Traverses the subtree with the possibility to skip branches. Starts with this node, and visits the descendant nodes depth-first, in preorder.

Static Method Summary
| `findCommonAncestor((goog.structs.TreeNode|undefined) var_args) ⇒ ?goog.structs.TreeNode` Finds the deepest common ancestor of the given nodes. The concept of ancestor is not strict in this case, it includes the node itself.