Class ValidationResult
java.lang.Object
cloud.opencode.base.xml.validate.ValidationResult
Validation Result - Contains XML validation results
验证结果 - 包含 XML 验证结果
This class holds the results of XML validation including errors and warnings.
此类保存 XML 验证的结果,包括错误和警告。
Features | 主要功能:
- Container for XML validation errors and warnings - XML 验证错误和警告的容器
- Separate tracking of errors vs warnings - 错误与警告的分别跟踪
- Validity check and error message formatting - 有效性检查和错误消息格式化
Usage Examples | 使用示例:
// Check validation result
ValidationResult result = SchemaValidator.validate(xml, schema);
if (result.isValid()) {
System.out.println("XML is valid");
} else {
result.getErrors().forEach(System.err::println);
}
Security | 安全性:
- Thread-safe: No (mutable error list) - 线程安全: 否(可变错误列表)
- Null-safe: Yes (empty lists by default) - 空值安全: 是(默认空列表)
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordValidation Error - Represents a single validation error or warning 验证错误 - 表示单个验证错误或警告 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an error.voidAdds an error with message and location.voidAdds a warning.voidaddWarning(String message, int line, int column) Adds a warning with message and location.Gets all issues (errors + warnings).intGets the error count.Gets error messages as strings.Gets all errors.Gets a summary of all errors.Gets the first error message, or null if no errors.intGets the warning count.Gets all warnings.booleanChecks if the validation has any errors.booleanChecks if the validation has any warnings.static ValidationResultCreates an invalid result with a single error.static ValidationResultCreates an invalid result with a single error message.booleanisValid()Checks if the validation passed with no errors.merge(ValidationResult other) Merges another result into this one.toString()static ValidationResultvalid()Creates a successful validation result.
-
Constructor Details
-
ValidationResult
public ValidationResult()
-
-
Method Details
-
valid
Creates a successful validation result. 创建成功的验证结果。- Returns:
- a valid result | 有效结果
-
invalid
Creates an invalid result with a single error. 创建带有单个错误的无效结果。- Parameters:
error- the error | 错误- Returns:
- an invalid result | 无效结果
-
invalid
Creates an invalid result with a single error message. 创建带有单个错误消息的无效结果。- Parameters:
message- the error message | 错误消息- Returns:
- an invalid result | 无效结果
-
isValid
public boolean isValid()Checks if the validation passed with no errors. 检查验证是否通过(无错误)。- Returns:
- true if valid | 如果有效则返回 true
-
hasErrors
public boolean hasErrors()Checks if the validation has any errors. 检查验证是否有任何错误。- Returns:
- true if has errors | 如果有错误则返回 true
-
hasWarnings
public boolean hasWarnings()Checks if the validation has any warnings. 检查验证是否有任何警告。- Returns:
- true if has warnings | 如果有警告则返回 true
-
getErrors
Gets all errors. 获取所有错误。- Returns:
- list of errors | 错误列表
-
getWarnings
Gets all warnings. 获取所有警告。- Returns:
- list of warnings | 警告列表
-
getAllIssues
Gets all issues (errors + warnings). 获取所有问题(错误 + 警告)。- Returns:
- list of all issues | 所有问题列表
-
getErrorCount
public int getErrorCount()Gets the error count. 获取错误数量。- Returns:
- the error count | 错误数量
-
getWarningCount
public int getWarningCount()Gets the warning count. 获取警告数量。- Returns:
- the warning count | 警告数量
-
getFirstErrorMessage
Gets the first error message, or null if no errors. 获取第一个错误消息,如果没有错误则返回 null。- Returns:
- the first error message | 第一个错误消息
-
addError
Adds an error. 添加错误。- Parameters:
error- the error | 错误
-
addError
Adds an error with message and location. 添加带消息和位置的错误。- Parameters:
message- the message | 消息line- the line number | 行号column- the column number | 列号
-
addWarning
Adds a warning. 添加警告。- Parameters:
warning- the warning | 警告
-
addWarning
Adds a warning with message and location. 添加带消息和位置的警告。- Parameters:
message- the message | 消息line- the line number | 行号column- the column number | 列号
-
merge
Merges another result into this one. 将另一个结果合并到此结果中。- Parameters:
other- the other result | 另一个结果- Returns:
- this result for chaining | 此结果以便链式调用
-
getErrorSummary
Gets a summary of all errors. 获取所有错误的摘要。- Returns:
- the error summary | 错误摘要
-
getErrorMessages
-
toString
-