Class CsvValidator.Builder
java.lang.Object
cloud.opencode.base.csv.validator.CsvValidator.Builder
- Enclosing class:
CsvValidator
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 Summary
Modifier and TypeMethodDescriptionbuild()Builds the CsvValidator 构建CsvValidatorAdds a custom validation rule with a predicate and error message 添加带有谓词和错误消息的自定义验证规则Adds a maximum length rule: value must have at most max characters 添加最大长度规则:值最多有max个字符Adds a minimum length rule: value must have at least min characters 添加最小长度规则:值必须至少有min个字符Adds a not-blank rule: value must not be null, empty, or whitespace-only 添加非空规则:值不能为null、空或仅包含空白字符Adds an allowed-values rule: value must be one of the specified values (case-sensitive) 添加允许值规则:值必须是指定值之一(区分大小写)Adds a regex pattern rule: value must match the given pattern 添加正则模式规则:值必须匹配给定的模式Adds a numeric range rule: value must be a valid double within [min, max] 添加数字范围规则:值必须是在[min, max]范围内的有效双精度数
-
Method Details
-
notBlank
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
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为nullIllegalArgumentException- if min > max | 如果min大于max
-
pattern
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
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为nullIllegalArgumentException- if min invalid input: '<' 0 | 如果min小于0
-
maxLength
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为nullIllegalArgumentException- if max invalid input: '<' 0 | 如果max小于0
-
oneOf
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为nullIllegalArgumentException- if allowedValues is empty | 如果allowedValues为空
-
custom
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
Builds the CsvValidator 构建CsvValidator- Returns:
- the CsvValidator instance | CsvValidator实例
-