Record Class TreePath<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.tree.path.TreePath<T>
- Type Parameters:
T- the node type | 节点类型- Record Components:
nodes- the path nodes from root to target | 从根到目标的路径节点
Tree Path
树路径
Represents a path from root to a node.
表示从根到节点的路径。
Features | 主要功能:
- Immutable path representation - 不可变路径表示
- Root, target, and parent access - 根、目标和父节点访问
- Sub-path and append operations - 子路径和追加操作
- String representation with separator - 带分隔符的字符串表示
Usage Examples | 使用示例:
TreePath<MyNode> path = PathFinder.findPathById(roots, id).get();
MyNode root = path.getRoot();
MyNode target = path.getTarget();
int depth = path.length();
String display = path.toString(" / ");
Security | 安全性:
- Thread-safe: Yes (immutable record) - 是(不可变记录)
- Null-safe: Yes (null nodes default to empty) - 是(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 TypeMethodDescriptionAppend node to path 向路径追加节点booleanCheck if path contains node 检查路径是否包含节点static <T> TreePath<T> empty()Create empty path 创建空路径final booleanIndicates whether some other object is "equal to" this one.get(int index) Get node at index 获取指定索引的节点Get parent of target 获取目标的父节点getRoot()Get root node 获取根节点Get target node (last node) 获取目标节点(最后一个节点)final inthashCode()Returns a hash code value for this object.booleanisEmpty()Check if path is empty 检查路径是否为空intlength()Get path length 获取路径长度nodes()Returns the value of thenodesrecord component.static <T> TreePath<T> Create path from list 从列表创建路径static <T> TreePath<T> of(T... nodes) Create path from nodes 从节点创建路径reverse()Get reversed path 获取反转的路径subPath(int start, int end) Get sub-path from start to end index 获取从开始到结束索引的子路径toString()Returns a string representation of this record class.Convert to string representation 转换为字符串表示
-
Constructor Details
-
TreePath
-
-
Method Details
-
empty
Create empty path 创建空路径- Type Parameters:
T- the node type | 节点类型- Returns:
- the empty path | 空路径
-
of
Create path from nodes 从节点创建路径- Type Parameters:
T- the node type | 节点类型- Parameters:
nodes- the nodes | 节点- Returns:
- the path | 路径
-
of
-
isEmpty
public boolean isEmpty()Check if path is empty 检查路径是否为空- Returns:
- true if empty | 如果为空返回true
-
length
public int length()Get path length 获取路径长度- Returns:
- the length | 长度
-
getRoot
-
getTarget
Get target node (last node) 获取目标节点(最后一个节点)- Returns:
- the target or null | 目标节点或null
-
get
Get node at index 获取指定索引的节点- Parameters:
index- the index | 索引- Returns:
- the node | 节点
-
getParent
-
subPath
-
append
-
reverse
-
contains
Check if path contains node 检查路径是否包含节点- Parameters:
node- the node to check | 要检查的节点- Returns:
- true if contains | 如果包含返回true
-
toString
-
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). -
nodes
-