Class TreeNode<T>
java.lang.Object
cloud.opencode.base.tree.TreeNode<T>
- Type Parameters:
T- the data type | 数据类型
Tree Node
树节点
A generic tree node implementation.
通用树节点实现。
Features | 主要功能:
- Parent-child relationships with back-references - 带反向引用的父子关系
- Pre-order, post-order, breadth-first traversal - 前序、后序、广度优先遍历
- Search, filter, and map operations - 搜索、过滤和映射操作
- Ancestor, descendant, and sibling queries - 祖先、后代和兄弟查询
- Depth, height, and size calculations - 深度、高度和大小计算
Usage Examples | 使用示例:
// Create tree - 创建树
TreeNode<String> root = new TreeNode<>("root");
TreeNode<String> child = root.addChild("child");
// Search - 搜索
Optional<TreeNode<String>> found = root.find(s -> s.equals("child"));
// Traverse - 遍历
root.forEachPreOrder(node -> System.out.println(node.getData()));
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: No (null data is allowed but not checked) - 空值安全: 否(允许null数据但不做检查)
- Since:
- JDK 25, opencode-base-tree V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidforEachBreadthFirst(Consumer<TreeNode<T>> action) voidforEachPostOrder(Consumer<TreeNode<T>> action) voidforEachPreOrder(Consumer<TreeNode<T>> action) intgetData()intgetDepth()intgetRoot()booleanbooleanisLeaf()booleanisRoot()<R> TreeNode<R> booleanremoveChild(TreeNode<T> child) voidintsize()toString()
-
Constructor Details
-
TreeNode
-
-
Method Details
-
getData
-
setData
-
getParent
-
getChildren
-
addChild
-
addChild
-
removeChild
-
clearChildren
public void clearChildren() -
isRoot
public boolean isRoot() -
isLeaf
public boolean isLeaf() -
getChildCount
public int getChildCount() -
hasChildren
public boolean hasChildren() -
getDepth
public int getDepth() -
getHeight
public int getHeight() -
getRoot
-
getSiblings
-
getAncestors
-
getDescendants
-
getLeaves
-
find
-
findAll
-
forEachPreOrder
-
forEachPostOrder
-
forEachBreadthFirst
-
map
-
filter
-
size
public int size() -
toString
-