Class DepthLimitedTraversal

java.lang.Object
cloud.opencode.base.tree.traversal.DepthLimitedTraversal
All Implemented Interfaces:
TreeTraversal

public class DepthLimitedTraversal extends Object implements 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 Details

    • DepthLimitedTraversal

      public DepthLimitedTraversal(int maxDepth)
  • Method Details

    • of

      public static DepthLimitedTraversal of(int maxDepth)
    • traverse

      public <T extends Treeable<T,ID>, ID> void traverse(List<T> roots, TreeVisitor<T> visitor)
      Description copied from interface: TreeTraversal
      Traverse tree nodes 遍历树节点
      Specified by:
      traverse in interface TreeTraversal
      Type Parameters:
      T - the node type | 节点类型
      ID - the ID type | ID类型
      Parameters:
      roots - the root nodes | 根节点列表
      visitor - the visitor | 访问者
    • getMaxDepth

      public int getMaxDepth()