Record Class ValidationResult
java.lang.Object
java.lang.Record
cloud.opencode.base.yml.schema.ValidationResult
ValidationResult - Result of YAML schema validation
ValidationResult - YAML 模式验证的结果
An immutable record representing the outcome of validating YAML data against a schema. Contains a validity flag and an immutable list of errors (empty when valid).
一个不可变记录,表示根据模式验证 YAML 数据的结果。 包含有效性标志和不可变的错误列表(有效时为空)。
Features | 主要功能:
- Factory methods for success and failure - 成功和失败的工厂方法
- Immutable error list - 不可变的错误列表
- Convenience isValid() check - 便捷的 isValid() 检查
Usage Examples | 使用示例:
// Success
ValidationResult ok = ValidationResult.success();
assert ok.isValid();
// Failure
ValidationResult fail = ValidationResult.failure(List.of(
new ValidationError("port", "Required key missing", ErrorType.MISSING_REQUIRED)
));
assert !fail.isValid();
assert fail.getErrors().size() == 1;
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Since:
- JDK 25, opencode-base-yml V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionValidationResult(boolean valid, List<ValidationError> errors) Canonical constructor that ensures the error list is immutable. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.errors()Returns the value of theerrorsrecord component.static ValidationResultfailure(List<ValidationError> errors) Creates a failure validation result with the given errors.Returns the list of validation errors.final inthashCode()Returns a hash code value for this object.booleanisValid()Returns whether the validation passed.static ValidationResultsuccess()Creates a successful validation result with no errors.toString()Returns a string representation of this record class.booleanvalid()Returns the value of thevalidrecord component.
-
Constructor Details
-
ValidationResult
Canonical constructor that ensures the error list is immutable. 规范构造函数,确保错误列表不可变。- Parameters:
valid- whether validation passed | 验证是否通过errors- the list of validation errors | 验证错误列表
-
-
Method Details
-
success
Creates a successful validation result with no errors. 创建没有错误的成功验证结果。- Returns:
- a successful result | 成功结果
-
failure
Creates a failure validation result with the given errors. 创建带有给定错误的失败验证结果。- Parameters:
errors- the validation errors | 验证错误- Returns:
- a failure result | 失败结果
-
isValid
public boolean isValid()Returns whether the validation passed. 返回验证是否通过。- Returns:
- true if valid | 如果有效则返回 true
-
getErrors
Returns the list of validation errors. 返回验证错误列表。- Returns:
- immutable list of errors | 不可变的错误列表
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
valid
public boolean valid()Returns the value of thevalidrecord component.- Returns:
- the value of the
validrecord component
-
errors
Returns the value of theerrorsrecord component.- Returns:
- the value of the
errorsrecord component
-