Package aQute.bnd.result
Class Ok<V>
java.lang.Object
aQute.bnd.result.Ok<V>
- Type Parameters:
V- The value type
- All Implemented Interfaces:
Result<V>
This class represents the Ok side of @{link Result}.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ConsumerWithException<? super V> ok, ConsumerWithException<? super String> err) Processes the result.<U> Result<U> asError()If anErr, return this coerced to the desired generic type.error()Returns the error of this instance as anOptional.<U> Result<U> flatMap(FunctionWithException<? super V, ? extends Result<? extends U>> mapper) FlatMap the contained value if this is anOkvalue.booleanisErr()booleanisOk()<U> Result<U> map(FunctionWithException<? super V, ? extends U> mapper) Map the contained value if this is anOkvalue.mapErr(FunctionWithException<? super String, ? extends CharSequence> mapper) Map the contained error if this is anErrvalue.Returns the contained value if this is anOkvalue.orElseGet(SupplierWithException<? extends V> orElseSupplier) Returns the contained value if this is anOkvalue.orElseThrow(FunctionWithException<? super String, ? extends R> throwableSupplier) Returns the contained value if this is anOkvalue.recover(FunctionWithException<? super String, ? extends V> recover) Recover the contained error if this is anErrvalue.recoverWith(FunctionWithException<? super String, ? extends Result<? extends V>> recover) Recover the contained error if this is anErrvalue.toString()unwrap()Returns the contained value if this is anOkvalue.unwrap(CharSequence message) Express the expectation that this object is anOkvalue.value()Returns the value of this instance as anOptional.
-
Field Details
-
value
-
-
Constructor Details
-
Ok
Ok(V value) Constructor.- Parameters:
value- the value
-
-
Method Details
-
isOk
public boolean isOk() -
isErr
public boolean isErr() -
value
-
error
-
unwrap
Returns the contained value if this is anOkvalue. Otherwise throws aResultException. -
unwrap
Express the expectation that this object is anOkvalue. Otherwise throws aResultExceptionwith the specified message.- Specified by:
unwrapin interfaceResult<V>- Parameters:
message- The message to pass to a potential ResultException. Must not benull.- Throws:
ResultException- If this is anErrinstance.
-
orElse
Returns the contained value if this is anOkvalue. Otherwise returns the specified alternate value. -
orElseGet
Returns the contained value if this is anOkvalue. Otherwise returns the alternate value supplied by the specified supplier. -
orElseThrow
public <R extends Throwable> V orElseThrow(FunctionWithException<? super String, ? extends R> throwableSupplier) throws RReturns the contained value if this is anOkvalue. Otherwise throws the exception supplied by the specified function.- Specified by:
orElseThrowin interfaceResult<V>- Type Parameters:
R- The exception type.- Parameters:
throwableSupplier- The supplier to supply an exception if this is anErrinstance. Must not benull. The supplier must return a non-nullresult.- Returns:
- The contained value.
- Throws:
R- The exception returned by the throwableSupplier if this is anErrinstance.
-
map
Map the contained value if this is anOkvalue. Otherwise return this. -
mapErr
Map the contained error if this is anErrvalue. Otherwise return this. -
flatMap
FlatMap the contained value if this is anOkvalue. Otherwise return this.- Specified by:
flatMapin interfaceResult<V>- Type Parameters:
U- The new value type.- Parameters:
mapper- The function to flatmap the contained value into a new result. Must not benull. The function must return a non-nullresult.- Returns:
- The flatmapped result if this is an
Okvalue. Otherwise this.
-
recover
Recover the contained error if this is anErrvalue. Otherwise return this.To recover with a recovery value of
null, theResult.recoverWith(FunctionWithException)method must be used. The specified function forResult.recoverWith(FunctionWithException)can returnResult.ok(null)to supply the desirednullvalue.- Specified by:
recoverin interfaceResult<V>- Parameters:
recover- The function to recover the contained error into a new value. Must not benull.- Returns:
- A result containing the new non-
nullvalue if this is anErrvalue. Otherwise this if this is anOkvalue or the recover function returnednull.
-
recoverWith
public Result<V> recoverWith(FunctionWithException<? super String, ? extends Result<? extends V>> recover) Recover the contained error if this is anErrvalue. Otherwise return this.- Specified by:
recoverWithin interfaceResult<V>- Parameters:
recover- The function to recover the contained error into a new result. Must not benull. The function must return a non-nullvalue.- Returns:
- A result if this is an
Errvalue. Otherwise this.
-
accept
Processes the result. -
asError
If anErr, return this coerced to the desired generic type. -
toString
-