Record Class ValidationResult
java.lang.Object
java.lang.Record
cloud.opencode.base.captcha.ValidationResult
- Record Components:
success- true if validation succeeded | 如果验证成功则为 truemessage- 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumResult codes for validation. -
Constructor Summary
ConstructorsConstructorDescriptionValidationResult(boolean success, String message, ValidationResult.ResultCode code) Creates an instance of aValidationResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncode()Returns the value of thecoderecord component.final booleanIndicates whether some other object is "equal to" this one.static ValidationResultexpired()Creates a failed result for expired.final inthashCode()Returns a hash code value for this object.static ValidationResultCreates a failed result for invalid input.booleanisFailed()Checks if validation failed.message()Returns the value of themessagerecord component.static ValidationResultmismatch()Creates a failed result for mismatch.static ValidationResultnotFound()Creates a failed result for not found.static ValidationResultok()Creates a successful result.static ValidationResultCreates a failed result for rate limiting.booleansuccess()Returns the value of thesuccessrecord component.static ValidationResultCreates a failed result for suspicious behavior.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
ok
Creates a successful result. 创建成功结果。- Returns:
- a success result | 成功结果
-
notFound
Creates a failed result for not found. 创建未找到的失败结果。- Returns:
- a not found result | 未找到结果
-
expired
Creates a failed result for expired. 创建已过期的失败结果。- Returns:
- an expired result | 过期结果
-
mismatch
Creates a failed result for mismatch. 创建不匹配的失败结果。- Returns:
- a mismatch result | 不匹配结果
-
rateLimited
Creates a failed result for rate limiting. 创建速率限制的失败结果。- Returns:
- a rate limited result | 速率限制结果
-
invalidInput
Creates a failed result for invalid input. 创建无效输入的失败结果。- Returns:
- an invalid input result | 无效输入结果
-
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
-
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. -
success
-
message
-
code
-