Record Class ValidationResult

java.lang.Object
java.lang.Record
cloud.opencode.base.captcha.ValidationResult
Record Components:
success - true if validation succeeded | 如果验证成功则为 true
message - the result message | 结果消息
code - the result code | 结果代码

public record ValidationResult(boolean success, String message, ValidationResult.ResultCode code) extends Record
Validation Result - Result of CAPTCHA validation 验证结果 - 验证码验证结果

This record holds the result of a CAPTCHA validation attempt.

此记录保存验证码验证尝试的结果。

Features | 主要功能:

  • Immutable validation result record - 不可变验证结果记录
  • Predefined result codes for common scenarios - 常见场景的预定义结果代码
  • Static factory methods for standard results - 标准结果的静态工厂方法

Usage Examples | 使用示例:

ValidationResult result = OpenCaptcha.validate(id, answer);
if (result.success()) {
    // Proceed with action
} else {
    String error = result.message();
}

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No (message may be null) - 空值安全: 否(消息可能为空)
Since:
JDK 25, opencode-base-captcha V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ValidationResult

      public ValidationResult(boolean success, String message, ValidationResult.ResultCode code)
      Creates an instance of a ValidationResult record class.
      Parameters:
      success - the value for the success record component
      message - the value for the message record component
      code - the value for the code record component
  • Method Details

    • ok

      public static ValidationResult ok()
      Creates a successful result. 创建成功结果。
      Returns:
      a success result | 成功结果
    • notFound

      public static ValidationResult notFound()
      Creates a failed result for not found. 创建未找到的失败结果。
      Returns:
      a not found result | 未找到结果
    • expired

      public static ValidationResult expired()
      Creates a failed result for expired. 创建已过期的失败结果。
      Returns:
      an expired result | 过期结果
    • mismatch

      public static ValidationResult mismatch()
      Creates a failed result for mismatch. 创建不匹配的失败结果。
      Returns:
      a mismatch result | 不匹配结果
    • rateLimited

      public static ValidationResult rateLimited()
      Creates a failed result for rate limiting. 创建速率限制的失败结果。
      Returns:
      a rate limited result | 速率限制结果
    • invalidInput

      public static ValidationResult invalidInput()
      Creates a failed result for invalid input. 创建无效输入的失败结果。
      Returns:
      an invalid input result | 无效输入结果
    • suspiciousBehavior

      public static ValidationResult suspiciousBehavior()
      Creates a failed result for suspicious behavior. 创建可疑行为的失败结果。
      Returns:
      a suspicious behavior result | 可疑行为结果
    • isFailed

      public boolean isFailed()
      Checks if validation failed. 检查验证是否失败。
      Returns:
      true if failed | 如果失败则返回 true
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • success

      public boolean success()
      Returns the value of the success record component.
      Returns:
      the value of the success record component
    • message

      public String message()
      Returns the value of the message record component.
      Returns:
      the value of the message record component
    • code

      Returns the value of the code record component.
      Returns:
      the value of the code record component