Interface TreeVisitor<T>
- Type Parameters:
T- the node type | 节点类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Tree Visitor
树访问者
Visitor interface for tree traversal.
树遍历的访问者接口。
Features | 主要功能:
- Functional visitor interface for tree traversal - 树遍历的函数式访问者接口
- Depth-aware visiting - 深度感知的访问
- Early termination support - 支持提前终止
Usage Examples | 使用示例:
// Simple visitor
TreeVisitor<MyNode> visitor = TreeVisitor.of(node -> process(node));
// Visitor with depth
TreeVisitor<MyNode> visitor = TreeVisitor.withDepth((node, depth) ->
System.out.println(" ".repeat(depth) + node));
Security | 安全性:
- Thread-safe: Implementation-dependent - 取决于实现
- Null-safe: No (node must not be null) - 否(节点不能为null)
- Since:
- JDK 25, opencode-base-tree V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TreeVisitor<T> Create visitor that always continues 创建始终继续的访问者booleanVisit a node 访问节点static <T> TreeVisitor<T> withDepth(BiConsumer<T, Integer> action) Create visitor with depth 创建带深度的访问者
-
Method Details
-
visit
Visit a node 访问节点- Parameters:
node- the node to visit | 要访问的节点depth- the depth of the node | 节点深度- Returns:
- true to continue, false to stop | true继续,false停止
-
of
Create visitor that always continues 创建始终继续的访问者- Type Parameters:
T- the node type | 节点类型- Parameters:
action- the action to perform | 要执行的动作- Returns:
- the visitor | 访问者
-
withDepth
Create visitor with depth 创建带深度的访问者- Type Parameters:
T- the node type | 节点类型- Parameters:
action- the action to perform | 要执行的动作- Returns:
- the visitor | 访问者
-