Class DefaultTreeNode<ID>
java.lang.Object
cloud.opencode.base.tree.DefaultTreeNode<ID>
- Type Parameters:
ID- the ID type | ID类型
- All Implemented Interfaces:
Treeable<DefaultTreeNode<ID>, ID>
Default Tree Node
默认树节点
Default implementation of Treeable interface.
Treeable接口的默认实现。
Features | 主要功能:
- ID-based parent-child relationships - 基于ID的父子关系
- Extra attributes via Map - 通过Map存储额外属性
- Sortable with sort field - 可通过sort字段排序
- Root/leaf detection - 根节点/叶子节点检测
Usage Examples | 使用示例:
// Create node - 创建节点
DefaultTreeNode<Long> node = new DefaultTreeNode<>(1L, 0L, "Root");
node.put("key", "value");
// Add child - 添加子节点
node.addChild(new DefaultTreeNode<>(2L, 1L, "Child"));
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Partial (setExtra and setChildren handle null) - 空值安全: 部分(setExtra和setChildren处理null)
- Since:
- JDK 25, opencode-base-tree V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate empty node 创建空节点DefaultTreeNode(ID id) Create node with ID 使用ID创建节点DefaultTreeNode(ID id, ID parentId, String name) Create node with ID, parentId and name 使用ID、父ID和名称创建节点 -
Method Summary
Modifier and TypeMethodDescriptionaddChild(DefaultTreeNode<ID> child) Add child node 添加子节点<V> VGet extra attribute 获取额外属性<V> VGet extra attribute with default 获取额外属性(带默认值)Get the children list 获取子节点列表getExtra()getId()Get the node ID 获取节点IDgetName()Get the parent node ID 获取父节点IDintgetSort()booleanisLeaf()Check if node is leaf 检查是否为叶子节点booleanisRoot()Check if node is root 检查是否为根节点Put extra attribute 设置额外属性voidsetChildren(List<DefaultTreeNode<ID>> children) Set the children list 设置子节点列表voidvoidvoidvoidsetParentId(ID parentId) voidsetSort(int sort) toString()
-
Constructor Details
-
DefaultTreeNode
public DefaultTreeNode()Create empty node 创建空节点 -
DefaultTreeNode
-
DefaultTreeNode
-
-
Method Details
-
getId
-
setId
-
getParentId
Description copied from interface:TreeableGet the parent node ID 获取父节点ID- Specified by:
getParentIdin interfaceTreeable<DefaultTreeNode<ID>, ID>- Returns:
- the parent ID | 父节点ID
-
setParentId
-
getName
-
setName
-
getSort
public int getSort() -
setSort
public void setSort(int sort) -
getExtra
-
setExtra
-
getChildren
Description copied from interface:TreeableGet the children list 获取子节点列表- Specified by:
getChildrenin interfaceTreeable<DefaultTreeNode<ID>, ID>- Returns:
- the children | 子节点列表
-
setChildren
Description copied from interface:TreeableSet the children list 设置子节点列表- Specified by:
setChildrenin interfaceTreeable<DefaultTreeNode<ID>, ID>- Parameters:
children- the children | 子节点列表
-
put
Put extra attribute 设置额外属性- Parameters:
key- the key | 键value- the value | 值- Returns:
- this node | 此节点
-
get
Get extra attribute 获取额外属性- Type Parameters:
V- the value type | 值类型- Parameters:
key- the key | 键- Returns:
- the value | 值
-
get
Get extra attribute with default 获取额外属性(带默认值)- Type Parameters:
V- the value type | 值类型- Parameters:
key- the key | 键defaultValue- the default value | 默认值- Returns:
- the value or default | 值或默认值
-
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
-
addChild
Add child node 添加子节点- Parameters:
child- the child node | 子节点- Returns:
- this node | 此节点
-
toString
-