Class DepthLimitedTraversal
java.lang.Object
cloud.opencode.base.tree.traversal.DepthLimitedTraversal
- All Implemented Interfaces:
TreeTraversal
Depth-Limited Traversal
深度限制遍历
Traversal with maximum depth limit.
带最大深度限制的遍历。
Features | 主要功能:
- Pre-order traversal with depth limit - 带深度限制的先序遍历
- Configurable maximum depth - 可配置最大深度
- Early termination via visitor - 通过访问者提前终止
Usage Examples | 使用示例:
DepthLimitedTraversal traversal = DepthLimitedTraversal.of(3);
traversal.traverse(roots, (node, depth) -> {
System.out.println(" ".repeat(depth) + node);
return true;
});
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 是(构造后不可变)
- Null-safe: No (roots must not be null) - 否(根节点不能为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 TypeMethodDescriptionintstatic DepthLimitedTraversalof(int maxDepth) <T extends Treeable<T,ID>, ID>
voidtraverse(List<T> roots, TreeVisitor<T> visitor) Traverse tree nodes 遍历树节点Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TreeTraversal
collect, traverse
-
Constructor Details
-
DepthLimitedTraversal
public DepthLimitedTraversal(int maxDepth)
-
-
Method Details
-
of
-
traverse
Description copied from interface:TreeTraversalTraverse tree nodes 遍历树节点- Specified by:
traversein interfaceTreeTraversal- Type Parameters:
T- the node type | 节点类型ID- the ID type | ID类型- Parameters:
roots- the root nodes | 根节点列表visitor- the visitor | 访问者
-
getMaxDepth
public int getMaxDepth()
-