Record Class Result.Failure<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.core.result.Result.Failure<T>
- Type Parameters:
T- value type - 值类型- Record Components:
cause- the failure cause (must not be null) - 失败原因(不能为 null)
- All Implemented Interfaces:
Result<T>
Failure - Represents a failed computation result
Failure - 表示失败的计算结果
- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
-
Nested Class Summary
Nested classes/interfaces inherited from interface Result
Result.Failure<T>, Result.Success<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncause()Returns the value of thecauserecord component.final booleanIndicates whether some other object is "equal to" this one.<U> Result<U> Transform the success value to another Result.Get the success value, or return default if Failure 获取成功值,如果是 Failure 返回默认值getOrElseGet(Supplier<? extends T> supplier) Get the success value, or compute default from Supplier if Failure 获取成功值,如果是 Failure 从 Supplier 计算默认值getOrElseThrow(Function<? super Throwable, ? extends X> exceptionMapper) Get the success value, or throw an exception mapped from the cause 获取成功值,或抛出从原因映射的异常final inthashCode()Returns a hash code value for this object.booleanCheck if this is a Failure 检查是否为失败booleanCheck if this is a Success 检查是否为成功<U> Result<U> Transform the success value.Execute action on Success value 对成功值执行操作peekFailure(Consumer<? super Throwable> action) Execute action on Failure cause 对失败原因执行操作Recover from a Failure by applying a function to the cause 通过对原因应用函数来从 Failure 恢复recoverWith(Function<? super Throwable, Result<T>> recoverer) Recover from a Failure by applying a function that returns a Result 通过应用返回 Result 的函数来从 Failure 恢复stream()Convert to Stream.Convert to Optional.toString()Returns string representation showing only class name and message (no stack trace for security).
-
Constructor Details
-
Failure
Compact constructor enforcing non-null cause 紧凑构造器强制 cause 不为 null
-
-
Method Details
-
isSuccess
-
isFailure
-
map
Description copied from interface:ResultTransform the success value. If the mapper throws, returns Failure with the caught exception. 转换成功值。如果映射函数抛出异常,返回包含捕获异常的 Failure。 -
flatMap
Description copied from interface:ResultTransform the success value to another Result. If the mapper throws, returns Failure. 将成功值转换为另一个 Result。如果映射函数抛出异常,返回 Failure。 -
recover
Description copied from interface:ResultRecover from a Failure by applying a function to the cause 通过对原因应用函数来从 Failure 恢复 -
recoverWith
Description copied from interface:ResultRecover from a Failure by applying a function that returns a Result 通过应用返回 Result 的函数来从 Failure 恢复- Specified by:
recoverWithin interfaceResult<T>- Parameters:
recoverer- recovery function that takes the cause and returns a Result - 接受原因并返回 Result 的恢复函数- Returns:
- recovered Result, or original Success
-
peek
-
peekFailure
Description copied from interface:ResultExecute action on Failure cause 对失败原因执行操作- Specified by:
peekFailurein interfaceResult<T>- Parameters:
action- action to execute on failure cause - 对失败原因执行的操作- Returns:
- this Result for chaining
-
getOrElse
-
getOrElseGet
Description copied from interface:ResultGet the success value, or compute default from Supplier if Failure 获取成功值,如果是 Failure 从 Supplier 计算默认值- Specified by:
getOrElseGetin interfaceResult<T>- Parameters:
supplier- default value supplier - 默认值供应商- Returns:
- success value or computed default
-
getOrElseThrow
public <X extends Throwable> T getOrElseThrow(Function<? super Throwable, ? extends X> exceptionMapper) throws X Description copied from interface:ResultGet the success value, or throw an exception mapped from the cause 获取成功值,或抛出从原因映射的异常- Specified by:
getOrElseThrowin interfaceResult<T>- Type Parameters:
X- exception type - 异常类型- Parameters:
exceptionMapper- function to map cause to throwable - 将原因映射为异常的函数- Returns:
- success value
- Throws:
X- if this is a Failure
-
toOptional
Description copied from interface:ResultConvert to Optional. Success becomes Optional.of(value), Failure becomes Optional.empty(). 转换为 Optional。Success 变为 Optional.of(value),Failure 变为 Optional.empty()。- Specified by:
toOptionalin interfaceResult<T>- Returns:
- Optional containing the success value, or empty if Failure
-
stream
Description copied from interface:ResultConvert to Stream. Success becomes a single-element Stream, Failure becomes an empty Stream. 转换为 Stream。Success 变为单元素 Stream,Failure 变为空 Stream。 -
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. All components in this record class are compared withObjects::equals(Object,Object). -
cause
-