java.lang.Object
java.lang.Record
info.jab.util.result.Success<T>
- Type Parameters:
T
- the type of the value returned in a successful computation- Record Components:
value
- the value resulting from a successful computation
- All Implemented Interfaces:
Result<T>
Record representing a successful Result in the Result.
This record encapsulates the successful state of a computation within the Result, holding the value resulting from a successful computation.
-
Nested Class Summary
Nested classes/interfaces inherited from interface info.jab.util.result.Result
Result.CheckedSupplier<T>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.<U> Result
<U> Applies the given function to the value if the Result is successful and returns a new Result.<U> U
Reduces the Result to a single value by applying a function to the successful value or a default value if the result is a failure.Returns the exception if present, otherwise returns an empty Optional.Returns the value if the Result is successful, otherwise returns the result of the specified Supplier.getValue()
Returns the value if present, otherwise returns an empty Optional.final int
hashCode()
Returns a hash code value for this object.void
Performs the given action if the Result is a failure.void
Performs the given action if the Result is successful.boolean
Checks if the Result is a failure.boolean
Checks if the Result is successful.<U> Result
<U> Applies the given function to the value if the Result is successful and returns a new Result.Applies the given function to the exception if the Result is a failure and returns a new Result with the mapped value.recoverCatching
(Function<? super Throwable, Result<T>> mapper) Applies the given function to the exception if the Result is a failure and returns a new Result.final String
toString()
Returns a string representation of this record class.value()
Returns the value of thevalue
record component.
-
Constructor Details
-
Success
-
-
Method Details
-
isSuccess
-
isFailure
-
ifSuccess
-
ifFailure
-
getValue
-
getException
-
getOrElse
Description copied from interface:Result
Returns the value if the Result is successful, otherwise returns the result of the specified Supplier. -
map
Description copied from interface:Result
Applies the given function to the value if the Result is successful and returns a new Result. -
flatMap
Description copied from interface:Result
Applies the given function to the value if the Result is successful and returns a new Result. The function should return a new Result. -
recover
Description copied from interface:Result
Applies the given function to the exception if the Result is a failure and returns a new Result with the mapped value. -
recoverCatching
Description copied from interface:Result
Applies the given function to the exception if the Result is a failure and returns a new Result. The function should return a new Result.- Specified by:
recoverCatching
in interfaceResult<T>
- Parameters:
mapper
- the function to apply to the exception- Returns:
- the Result returned by the mapper if failure, otherwise the original success
-
fold
Description copied from interface:Result
Reduces the Result to a single value by applying a function to the successful value or a default value if the result is a failure. -
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)
. -
value
-