Record Class LightTreeNode<ID>
java.lang.Object
java.lang.Record
cloud.opencode.base.tree.LightTreeNode<ID>
- Type Parameters:
ID- the ID type | ID类型- Record Components:
id- the node ID | 节点IDparentId- the parent ID | 父节点IDname- the node name | 节点名称children- the children list | 子节点列表
public record LightTreeNode<ID>(ID id, ID parentId, String name, List<LightTreeNode<ID>> children)
extends Record
Light Tree Node
轻量级树节点
A lightweight tree node implementation using record.
使用record实现的轻量级树节点。
Features | 主要功能:
- Immutable record-based tree node - 基于record的不可变树节点
- Minimal memory footprint - 最小内存占用
- Factory methods for root and child nodes - 根节点和子节点的工厂方法
- Functional child addition via withChild - 通过withChild函数式添加子节点
Usage Examples | 使用示例:
// Create root - 创建根节点
LightTreeNode<Long> root = LightTreeNode.root(1L, "Root");
// Create child - 创建子节点
LightTreeNode<Long> child = LightTreeNode.of(2L, 1L, "Child");
// Add child (returns new node) - 添加子节点(返回新节点)
LightTreeNode<Long> updated = root.withChild(child);
Security | 安全性:
- Thread-safe: Yes (immutable record, withChild returns new instance) - 线程安全: 是(不可变record,withChild返回新实例)
- Null-safe: Partial (children list defaults to empty if null) - 空值安全: 部分(子节点列表null时默认为空)
- Since:
- JDK 25, opencode-base-tree V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLightTreeNode(ID id, ID parentId, String name, List<LightTreeNode<ID>> children) Compact constructor 紧凑构造函数 -
Method Summary
Modifier and TypeMethodDescriptionchildren()Returns the value of thechildrenrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.booleanisLeaf()Check if node is leaf 检查是否为叶子节点booleanisRoot()Check if node is root 检查是否为根节点name()Returns the value of thenamerecord component.static <ID> LightTreeNode<ID> Create node 创建节点parentId()Returns the value of theparentIdrecord component.static <ID> LightTreeNode<ID> Create root node 创建根节点final StringtoString()Returns a string representation of this record class.withChild(LightTreeNode<ID> child) Add child and return new node 添加子节点并返回新节点
-
Constructor Details
-
LightTreeNode
-
-
Method Details
-
of
Create node 创建节点- Type Parameters:
ID- the ID type | ID类型- Parameters:
id- the ID | IDparentId- the parent ID | 父节点IDname- the name | 名称- Returns:
- the node | 节点
-
root
Create root node 创建根节点- Type Parameters:
ID- the ID type | ID类型- Parameters:
id- the ID | IDname- the name | 名称- Returns:
- the node | 节点
-
isRoot
public boolean isRoot()Check if node is root 检查是否为根节点- Returns:
- true if root | 如果是根节点返回true
-
isLeaf
public boolean isLeaf()Check if node is leaf 检查是否为叶子节点- Returns:
- true if leaf | 如果是叶子节点返回true
-
withChild
Add child and return new node 添加子节点并返回新节点- Parameters:
child- the child to add | 要添加的子节点- Returns:
- new node with child | 带子节点的新节点
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
id
-
parentId
-
name
-
children
-