goog.structs.TreeNode
Classgoog.structs.TreeNode
> goog.structs.Node
goog.structs.TreeNode(key, value)
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.
key
{*}
value
{*}
.addChild(child)
Appends a child node to this node.
child
{!goog.structs.TreeNode
}
.addChildAt(child, index)
Inserts a child node at the given index.
child
{!goog.structs.TreeNode
}
index
{number
}
.clone()
Clones a node and returns a new node.
goog.structs.TreeNode
}
.contains(node)
Tells whether this node is the ancestor of the given node.
node
{!goog.structs.TreeNode
}
boolean
}
.deepClone()
goog.structs.TreeNode
}
.findCommonAncestor(var_args)
Finds the deepest common ancestor of the given nodes. The concept of ancestor is not strict in this case, it includes the node itself.
var_args
{...!goog.structs.TreeNode
}
goog.structs.TreeNode
}
.forEachChild(f, opt_this)
Traverses all child nodes.
f
{function
(!goog.structs.TreeNode
, number
,
!Array
.<!goog.structs.TreeNode
>)}
opt_this
{Object
=}
.forEachDescendant(f, opt_this)
Traverses all child nodes recursively in preorder.
f
{function
(!goog.structs.TreeNode
)}
opt_this
{Object
=}
.getAncestors()
Array
.<!goog.structs.TreeNode
>}
.getChildAt(index)
Gets the child node of this node at the given index.
index
{number
}
goog.structs.TreeNode
}
.getChildCount()
number
}
.getChildren()
Array
.<!goog.structs.TreeNode
>}
.getDepth()
number
}
.getKey()
Inherited from goog.structs.Node
.
Gets the key.
.getParent()
goog.structs.TreeNode
}
.getRoot()
goog.structs.TreeNode
}
.getSubtreeKeys()
Builds a nested array structure from the node keys in this node's subtree to facilitate testing tree operations that change the hierarchy.
Array
}
this |- child1 | L- grandchild L- child2is represented as ['child1', ['grandchild'], 'child2'].
.getValue()
Inherited from goog.structs.Node
.
Gets the value.
.isLastChild()
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
boolean
}
.isLeaf()
boolean
}
.removeChild(child)
Removes the given child node of this node.
child
{goog.structs.TreeNode
}
goog.structs.TreeNode
}
.removeChildAt(index)
Removes the child node at the given index.
index
{number
}
goog.structs.TreeNode
}
.removeChildren()
Removes all child nodes of this node.
.replaceChild(newChild, oldChild)
Replaces the given child node.
newChild
{!goog.structs.TreeNode
}
oldChild
{!goog.structs.TreeNode
}
goog.structs.TreeNode
}
.replaceChildAt(newChild, index)
Replaces a child node at the given index.
newChild
{!goog.structs.TreeNode
}
index
{number
}
goog.structs.TreeNode
}
.setParent(parent)
[protected]Sets the parent node of this node. The callers must ensure that the parent node and only that has this node among its children.
parent
{goog.structs.TreeNode
}
.traverse(f, opt_this)
Traverses the subtree with the possibility to skip branches. Starts with this node, and visits the descendant nodes depth-first, in preorder.
f
{function
(!goog.structs.TreeNode
): (boolean
|undefined
)}
opt_this
{Object
=}