Class ValidationResult

java.lang.Object
cloud.opencode.base.xml.validate.ValidationResult

public final class ValidationResult extends Object
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:
  • Constructor Details

    • ValidationResult

      public ValidationResult()
  • Method Details

    • valid

      public static ValidationResult valid()
      Creates a successful validation result. 创建成功的验证结果。
      Returns:
      a valid result | 有效结果
    • invalid

      public static ValidationResult invalid(ValidationResult.ValidationError error)
      Creates an invalid result with a single error. 创建带有单个错误的无效结果。
      Parameters:
      error - the error | 错误
      Returns:
      an invalid result | 无效结果
    • invalid

      public static ValidationResult invalid(String message)
      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

      public List<ValidationResult.ValidationError> getWarnings()
      Gets all warnings. 获取所有警告。
      Returns:
      list of warnings | 警告列表
    • getAllIssues

      public List<ValidationResult.ValidationError> 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

      public String getFirstErrorMessage()
      Gets the first error message, or null if no errors. 获取第一个错误消息,如果没有错误则返回 null。
      Returns:
      the first error message | 第一个错误消息
    • addError

      public void addError(ValidationResult.ValidationError error)
      Adds an error. 添加错误。
      Parameters:
      error - the error | 错误
    • addError

      public void addError(String message, int line, int column)
      Adds an error with message and location. 添加带消息和位置的错误。
      Parameters:
      message - the message | 消息
      line - the line number | 行号
      column - the column number | 列号
    • addWarning

      public void addWarning(ValidationResult.ValidationError warning)
      Adds a warning. 添加警告。
      Parameters:
      warning - the warning | 警告
    • addWarning

      public void addWarning(String message, int line, int column)
      Adds a warning with message and location. 添加带消息和位置的警告。
      Parameters:
      message - the message | 消息
      line - the line number | 行号
      column - the column number | 列号
    • merge

      public ValidationResult merge(ValidationResult other)
      Merges another result into this one. 将另一个结果合并到此结果中。
      Parameters:
      other - the other result | 另一个结果
      Returns:
      this result for chaining | 此结果以便链式调用
    • getErrorSummary

      public String getErrorSummary()
      Gets a summary of all errors. 获取所有错误的摘要。
      Returns:
      the error summary | 错误摘要
    • getErrorMessages

      public List<String> getErrorMessages()
      Gets error messages as strings. 获取错误消息字符串列表。
      Returns:
      list of error messages | 错误消息列表
    • toString

      public String toString()
      Overrides:
      toString in class Object