Package aQute.bnd.service.result
Class Err<V,E>
- java.lang.Object
-
- aQute.bnd.service.result.Err<V,E>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(ConsumerWithException<? super V> ok, ConsumerWithException<? super E> err)
Terminal function that processes the result or the error<X> Result<X,E>
asError()
java.util.Optional<E>
error()
Returns the error of this instance as anOptional
.<U> Result<U,E>
flatMap(FunctionWithException<? super V,? extends Result<? extends U,? extends E>> mapper)
FlatMap the contained value if this is anOk
value.boolean
isErr()
boolean
isOk()
<U> Result<U,E>
map(FunctionWithException<? super V,? extends U> mapper)
Map the contained value if this is anOk
value.<F> Result<V,F>
mapErr(FunctionWithException<? super E,? extends F> mapper)
Map the contained error if this is anErr
value.V
orElse(V orElse)
Returns the contained value if this is anOk
value.V
orElseGet(java.util.function.Supplier<? extends V> orElseSupplier)
Returns the contained value if this is anOk
value.<R extends java.lang.Throwable>
VorElseThrow(FunctionWithException<? super E,? extends R> throwableSupplier)
Returns the contained value if this is anOk
value.Result<V,E>
recover(FunctionWithException<? super E,? extends V> recover)
Recover the contained error if this is anErr
value.java.lang.String
toString()
V
unwrap()
Returns the contained value if this is anOk
value.V
unwrap(java.lang.String message)
Express the expectation that this object is anOk
value.<X extends java.lang.Throwable>
Vunwrap(java.util.function.Function<E,X> constructor)
java.util.Optional<V>
value()
Returns the value of this instance as anOptional
.
-
-
-
Method Detail
-
isOk
public boolean isOk()
-
isErr
public boolean isErr()
-
value
public java.util.Optional<V> value()
Returns the value of this instance as anOptional
. ReturnsOptional.empty()
if this is anErr
instance.
-
error
public java.util.Optional<E> error()
Returns the error of this instance as anOptional
. ReturnsOptional.empty()
if this is anOk
instance.
-
unwrap
public V unwrap()
Returns the contained value if this is anOk
value. Otherwise throws aResultException
.
-
unwrap
public V unwrap(java.lang.String message) throws ResultException
Express the expectation that this object is anOk
value. Otherwise throws aResultException
with the specified message.
-
orElse
public V orElse(V orElse)
Returns the contained value if this is anOk
value. Otherwise returns the specified alternate value.
-
orElseGet
public V orElseGet(java.util.function.Supplier<? extends V> orElseSupplier)
Returns the contained value if this is anOk
value. Otherwise returns the alternate value supplied by the specified supplier.
-
orElseThrow
public <R extends java.lang.Throwable> V orElseThrow(FunctionWithException<? super E,? extends R> throwableSupplier) throws R extends java.lang.Throwable
Returns the contained value if this is anOk
value. Otherwise throws the exception supplied by the specified function.- Specified by:
orElseThrow
in interfaceResult<V,E>
- Type Parameters:
R
- The exception type.- Parameters:
throwableSupplier
- The supplier to supply an exception if this is anErr
instance. Must not benull
. The supplier must return a non-null
result.- Returns:
- The contained value.
- Throws:
R
- If this is anErr
instance.R extends java.lang.Throwable
-
map
public <U> Result<U,E> map(FunctionWithException<? super V,? extends U> mapper)
Map the contained value if this is anOk
value. Otherwise return this.- Specified by:
map
in 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-null
value.- Returns:
- A result containing the mapped value if this is an
Ok
value. Otherwise this.
-
mapErr
public <F> Result<V,F> mapErr(FunctionWithException<? super E,? extends F> mapper)
Map the contained error if this is anErr
value. Otherwise return this.- Specified by:
mapErr
in 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-null
error.- Returns:
- A result containing the mapped error if this is an
Err
value. 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 anOk
value. Otherwise return this.- Specified by:
flatMap
in 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-null
result.- Returns:
- The flatmapped result if this is an
Ok
value. Otherwise this.
-
recover
public Result<V,E> recover(FunctionWithException<? super E,? extends V> recover)
Recover the contained error if this is anErr
value. Otherwise return this.
-
accept
public void accept(ConsumerWithException<? super V> ok, ConsumerWithException<? super E> err)
Description copied from interface:Result
Terminal function that processes the result or the error
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-