Class CsvValidator.Builder

java.lang.Object
cloud.opencode.base.csv.validator.CsvValidator.Builder
Enclosing class:
CsvValidator

public static final class CsvValidator.Builder extends Object
Builder for CsvValidator CsvValidator构建器

Provides a fluent API for adding validation rules.

提供用于添加验证规则的流式API。

Since:
JDK 25, opencode-base-csv V1.0.3
Author:
Leon Soo
  • Method Details

    • notBlank

      public CsvValidator.Builder notBlank(String column)
      Adds a not-blank rule: value must not be null, empty, or whitespace-only 添加非空规则:值不能为null、空或仅包含空白字符
      Parameters:
      column - the column name | 列名
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if column is null | 如果column为null
    • range

      public CsvValidator.Builder range(String column, double min, double max)
      Adds a numeric range rule: value must be a valid double within [min, max] 添加数字范围规则:值必须是在[min, max]范围内的有效双精度数
      Parameters:
      column - the column name | 列名
      min - the minimum value (inclusive) | 最小值(包含)
      max - the maximum value (inclusive) | 最大值(包含)
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if column is null | 如果column为null
      IllegalArgumentException - if min > max | 如果min大于max
    • pattern

      public CsvValidator.Builder pattern(String column, String regex)
      Adds a regex pattern rule: value must match the given pattern 添加正则模式规则:值必须匹配给定的模式

      The regex is compiled once at build time for efficiency.

      正则在构建时编译一次以提高效率。

      Parameters:
      column - the column name | 列名
      regex - the regular expression | 正则表达式
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if column or regex is null | 如果column或regex为null
    • minLength

      public CsvValidator.Builder minLength(String column, int min)
      Adds a minimum length rule: value must have at least min characters 添加最小长度规则:值必须至少有min个字符
      Parameters:
      column - the column name | 列名
      min - the minimum length (inclusive) | 最小长度(包含)
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if column is null | 如果column为null
      IllegalArgumentException - if min invalid input: '<' 0 | 如果min小于0
    • maxLength

      public CsvValidator.Builder maxLength(String column, int max)
      Adds a maximum length rule: value must have at most max characters 添加最大长度规则:值最多有max个字符
      Parameters:
      column - the column name | 列名
      max - the maximum length (inclusive) | 最大长度(包含)
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if column is null | 如果column为null
      IllegalArgumentException - if max invalid input: '<' 0 | 如果max小于0
    • oneOf

      public CsvValidator.Builder oneOf(String column, String... allowedValues)
      Adds an allowed-values rule: value must be one of the specified values (case-sensitive) 添加允许值规则:值必须是指定值之一(区分大小写)
      Parameters:
      column - the column name | 列名
      allowedValues - the allowed values | 允许的值
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if column or allowedValues is null | 如果column或allowedValues为null
      IllegalArgumentException - if allowedValues is empty | 如果allowedValues为空
    • custom

      public CsvValidator.Builder custom(String column, Predicate<String> rule, String errorMessage)
      Adds a custom validation rule with a predicate and error message 添加带有谓词和错误消息的自定义验证规则
      Parameters:
      column - the column name | 列名
      rule - the validation predicate (value may be null) | 验证谓词(值可能为null)
      errorMessage - the error message template (may contain {value}) | 错误消息模板(可包含{value})
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if any argument is null | 如果任何参数为null
    • build

      public CsvValidator build()
      Builds the CsvValidator 构建CsvValidator
      Returns:
      the CsvValidator instance | CsvValidator实例