Class Tree<T>
java.lang.Object
org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree<T>
- All Implemented Interfaces:
Serializable
A tree data structure with a tree-shaped public API.
Iteration order over the nodes at a given level is not promised. Because children are keyed by node value,
sibling branches that resolve to the same value are represented as a single node; callers that require every
path to be preserved should use Path instead.
- Author:
- Marko A. Rodriguez (http://markorodriguez.com)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRecursively mergesotherinto this tree.Returns the child subtree for the given key.booleanReturnstrueif the given value appears as a key anywhere in this tree (recursive).booleanStructural recursive equality.findSubtree(T key) Recursively searches the tree for the first subtree rooted atkeyand returns it.Returns all keys whose subtrees are leaves.Returns single-key trees representing each leaf key in this tree, preserving the original key-to-empty-subtree mapping.getNodesAtDepth(int depth) Returns the keys at the given depth.getOrCreateChild(T key) Returns the existing child forkey, or inserts and returns a new emptyTreeif absent.getTreesAtDepth(int depth) Returns the trees at the given depth.booleanReturnstrueif the given key is an immediate child of this tree.inthashCode()booleanisLeaf()Returnstrueif this tree has no children.intReturns the total number of nodes (keys) in the tree, counted recursively.Produces a formatted string representation of the tree structure using a|--ASCII style.Returns the set of keys at the root of this tree.Splits this tree into one tree per root key.toString()
-
Constructor Details
-
Tree
public Tree() -
Tree
Creates a tree with the given values as root keys, each mapping to an emptyTree.
-
-
Method Details
-
rootNodes
Returns the set of keys at the root of this tree. The returned set is unmodifiable. -
childAt
Returns the child subtree for the given key.- Throws:
IllegalArgumentException- if no child exists for the given key
-
hasChild
Returnstrueif the given key is an immediate child of this tree. -
contains
Returnstrueif the given value appears as a key anywhere in this tree (recursive). -
findSubtree
Recursively searches the tree for the first subtree rooted atkeyand returns it. The search visits direct children first and then recurses, but iteration order across siblings is unspecified. -
getOrCreateChild
Returns the existing child forkey, or inserts and returns a new emptyTreeif absent. -
isLeaf
public boolean isLeaf()Returnstrueif this tree has no children. An empty tree is considered a leaf. -
nodeCount
public int nodeCount()Returns the total number of nodes (keys) in the tree, counted recursively. -
getNodesAtDepth
Returns the keys at the given depth. Depth0returns the root keys. -
getTreesAtDepth
Returns the trees at the given depth. Depth0returns a singleton list containing this tree. Depths beyond the tree's height return an empty list. -
getLeafNodes
Returns all keys whose subtrees are leaves. -
getLeafTrees
Returns single-key trees representing each leaf key in this tree, preserving the original key-to-empty-subtree mapping. -
addTree
Recursively mergesotherinto this tree. For overlapping keys, child subtrees are merged in turn. For keys present only inother, the corresponding subtree reference is adopted directly. -
splitParents
Splits this tree into one tree per root key. If the tree has a single root, returns a singleton list containing this tree. -
prettyPrint
Produces a formatted string representation of the tree structure using a|--ASCII style. -
equals
Structural recursive equality. Order across siblings is irrelevant; two trees are equal if they have the same set of keys and each key's subtree is recursively equal. -
hashCode
public int hashCode() -
toString
-