Package aQute.bnd.service.result
Class Err<V,E>
java.lang.Object
aQute.bnd.service.result.Err<V,E>
- Type Parameters:
V- The value typeE- The error type
- All Implemented Interfaces:
Result<V,E>
This class represents the Err side of @{link Result}.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ConsumerWithException<? super V> ok, ConsumerWithException<? super E> err) Terminal function that processes the result or the errorasError()error()Returns the error of this instance as anOptional.flatMap(FunctionWithException<? super V, ? extends Result<? extends U, ? extends E>> mapper) FlatMap the contained value if this is anOkvalue.booleanisErr()booleanisOk()map(FunctionWithException<? super V, ? extends U> mapper) Map the contained value if this is anOkvalue.mapErr(FunctionWithException<? super E, ? extends F> mapper) Map the contained error if this is anErrvalue.Returns the contained value if this is anOkvalue.Returns the contained value if this is anOkvalue.orElseThrow(FunctionWithException<? super E, ? extends R> throwableSupplier) Returns the contained value if this is anOkvalue.recover(FunctionWithException<? super E, ? extends V> recover) Recover the contained error if this is anErrvalue.toString()unwrap()Returns the contained value if this is anOkvalue.Express the expectation that this object is anOkvalue.value()Returns the value of this instance as anOptional.
-
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. -
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 E, ? 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,E> - 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- If this is anErrinstance.
-
map
Map the contained value if this is anOkvalue. Otherwise return this.- Specified by:
mapin interfaceResult<V,E> - Type Parameters:
U- The new value type.- Parameters:
mapper- The function to map the contained value into a new value. Must not benull. The function must return a non-nullvalue.- Returns:
- A result containing the mapped value if this is an
Okvalue. Otherwise this.
-
mapErr
Map the contained error if this is anErrvalue. Otherwise return this.- Specified by:
mapErrin interfaceResult<V,E> - Type Parameters:
F- The new error type.- Parameters:
mapper- The function to map the contained error into a new error. Must not benull. The function must return a non-nullerror.- Returns:
- A result containing the mapped error if this is an
Errvalue. Otherwise this.
-
flatMap
public <U> Result<U,E> flatMap(FunctionWithException<? super V, ? extends Result<? extends U, ? extends E>> mapper) FlatMap the contained value if this is anOkvalue. Otherwise return this.- Specified by:
flatMapin interfaceResult<V,E> - 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. -
accept
Description copied from interface:ResultTerminal function that processes the result or the error -
toString
-
asError
-
unwrap
-