Package aQute.bnd.result
Class Err<V>
- java.lang.Object
-
- aQute.bnd.result.Err<V>
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
error
-
Constructor Summary
Constructors Constructor Description Err(java.lang.CharSequence error)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(ConsumerWithException<? super V> ok, ConsumerWithException<? super java.lang.String> err)
Processes the result.<U> Result<U>
asError()
If anErr
, return this coerced to the desired generic type.java.util.Optional<java.lang.String>
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 anOk
value.boolean
isErr()
boolean
isOk()
<U> Result<U>
map(FunctionWithException<? super V,? extends U> mapper)
Map the contained value if this is anOk
value.Result<V>
mapErr(FunctionWithException<? super java.lang.String,? extends java.lang.CharSequence> 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(SupplierWithException<? extends V> orElseSupplier)
Returns the contained value if this is anOk
value.<R extends java.lang.Throwable>
VorElseThrow(FunctionWithException<? super java.lang.String,? extends R> throwableSupplier)
Returns the contained value if this is anOk
value.Result<V>
recover(FunctionWithException<? super java.lang.String,? extends V> recover)
Recover the contained error if this is anErr
value.Result<V>
recoverWith(FunctionWithException<? super java.lang.String,? extends Result<? 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.CharSequence message)
Express the expectation that this object is anOk
value.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<java.lang.String> 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.CharSequence message) throws ResultException
Express the expectation that this object is anOk
value. Otherwise throws aResultException
with the specified message.- Specified by:
unwrap
in interfaceResult<V>
- Parameters:
message
- The message to pass to a potential ResultException. Must not benull
.- Throws:
ResultException
- If this is anErr
instance.
-
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(SupplierWithException<? 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 java.lang.String,? 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>
- 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
- The exception returned by the throwableSupplier if this is anErr
instance.R extends java.lang.Throwable
-
map
public <U> Result<U> map(FunctionWithException<? super V,? extends U> mapper)
Map the contained value if this is anOk
value. Otherwise return this.
-
mapErr
public Result<V> mapErr(FunctionWithException<? super java.lang.String,? extends java.lang.CharSequence> mapper)
Map the contained error if this is anErr
value. Otherwise return this.
-
flatMap
public <U> Result<U> flatMap(FunctionWithException<? super V,? extends Result<? extends U>> mapper)
FlatMap the contained value if this is anOk
value. Otherwise return this.- Specified by:
flatMap
in 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-null
result.- Returns:
- The flatmapped result if this is an
Ok
value. Otherwise this.
-
recover
public Result<V> recover(FunctionWithException<? super java.lang.String,? extends V> recover)
Recover the contained error if this is anErr
value. 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 desirednull
value.- Specified by:
recover
in 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-
null
value if this is anErr
value. Otherwise this if this is anOk
value or the recover function returnednull
.
-
recoverWith
public Result<V> recoverWith(FunctionWithException<? super java.lang.String,? extends Result<? extends V>> recover)
Recover the contained error if this is anErr
value. Otherwise return this.- Specified by:
recoverWith
in interfaceResult<V>
- Parameters:
recover
- The function to recover the contained error into a new result. Must not benull
. The function must return a non-null
value.- Returns:
- A result if this is an
Err
value. Otherwise this.
-
accept
public void accept(ConsumerWithException<? super V> ok, ConsumerWithException<? super java.lang.String> err)
Processes the result.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-