Class TreeNodeValidator

java.lang.Object
cloud.opencode.base.tree.validation.TreeNodeValidator

public final class TreeNodeValidator extends Object
Tree Node Validator 树节点验证器

Validates tree nodes and structure.

验证树节点和结构。

Features | 主要功能:

  • Node ID validation (null, duplicate) - 节点ID验证(null、重复)
  • Tree structure validation - 树结构验证
  • Max depth validation - 最大深度验证

Usage Examples | 使用示例:

ValidationResult result = TreeNodeValidator.validate(nodes);
if (!result.valid()) {
    System.out.println(result.getErrorMessage());
}
TreeNodeValidator.validateOrThrow(nodes); // throws TreeException

Security | 安全性:

  • Thread-safe: No - 否
  • Null-safe: No (nodes must not be null) - 否(节点不能为null)
Since:
JDK 25, opencode-base-tree V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • validate

      public static <T extends Treeable<T,ID>, ID> TreeNodeValidator.ValidationResult validate(List<T> nodes)
      Validate tree nodes 验证树节点
      Type Parameters:
      T - the node type | 节点类型
      ID - the ID type | ID类型
      Parameters:
      nodes - the nodes to validate | 要验证的节点
      Returns:
      the validation result | 验证结果
    • validateStructure

      public static <T extends Treeable<T,ID>, ID> TreeNodeValidator.ValidationResult validateStructure(List<T> roots)
      Validate tree structure 验证树结构
      Type Parameters:
      T - the node type | 节点类型
      ID - the ID type | ID类型
      Parameters:
      roots - the root nodes | 根节点
      Returns:
      the validation result | 验证结果
    • validateOrThrow

      public static <T extends Treeable<T,ID>, ID> void validateOrThrow(List<T> nodes)
      Validate and throw if invalid 验证并在无效时抛出异常
      Type Parameters:
      T - the node type | 节点类型
      ID - the ID type | ID类型
      Parameters:
      nodes - the nodes to validate | 要验证的节点
      Throws:
      TreeException - if validation fails | 如果验证失败抛出异常