Class YmlSchema.Builder

java.lang.Object
cloud.opencode.base.yml.schema.YmlSchema.Builder
Enclosing class:
YmlSchema

public static final class YmlSchema.Builder extends Object
Builder for constructing YmlSchema instances. 用于构建 YmlSchema 实例的构建器。
Since:
JDK 25, opencode-base-yml V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • required

      public YmlSchema.Builder required(String... keys)
      Adds required keys at the root level. 在根级别添加必需键。
      Parameters:
      keys - the required key names | 必需的键名
      Returns:
      this builder | 此构建器
    • type

      public YmlSchema.Builder type(String path, Class<?> expectedType)
      Adds a type constraint: the value at the given path must be assignable to the expected type. 添加类型约束:给定路径处的值必须可赋值给预期类型。
      Parameters:
      path - the dot-notation path | 点号路径
      expectedType - the expected type | 预期类型
      Returns:
      this builder | 此构建器
    • range

      public YmlSchema.Builder range(String path, Comparable<?> min, Comparable<?> max)
      Adds a range constraint for Comparable values at the given path. 为给定路径的 Comparable 值添加范围约束。
      Parameters:
      path - the dot-notation path | 点号路径
      min - the minimum value (inclusive), or null for no lower bound | 最小值(含),null 表示无下界
      max - the maximum value (inclusive), or null for no upper bound | 最大值(含),null 表示无上界
      Returns:
      this builder | 此构建器
    • pattern

      public YmlSchema.Builder pattern(String path, String regex)
      Adds a regex pattern constraint for string values at the given path. 为给定路径的字符串值添加正则模式约束。
      Parameters:
      path - the dot-notation path | 点号路径
      regex - the regex pattern | 正则模式
      Returns:
      this builder | 此构建器
      Throws:
      PatternSyntaxException - if the regex is invalid | 如果正则无效
    • nested

      public YmlSchema.Builder nested(String path, YmlSchema schema)
      Adds a nested schema for validating a sub-document at the given path. 添加嵌套模式以验证给定路径处的子文档。
      Parameters:
      path - the dot-notation path | 点号路径
      schema - the nested schema | 嵌套模式
      Returns:
      this builder | 此构建器
    • rule

      public YmlSchema.Builder rule(String path, Predicate<Object> predicate, String message)
      Adds a custom validation rule at the given path. 在给定路径添加自定义验证规则。
      Parameters:
      path - the dot-notation path | 点号路径
      predicate - the validation predicate | 验证谓词
      message - the error message if the predicate returns false | 谓词返回 false 时的错误消息
      Returns:
      this builder | 此构建器
    • build

      public YmlSchema build()
      Builds the immutable YmlSchema. 构建不可变的 YmlSchema。
      Returns:
      the schema | 模式