V - The result type.@ProviderType public abstract class Result<V> extends Object implements Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
Result.Builder<V,A>
Builds a result for a wrapped collector.
|
| Modifier and Type | Method and Description |
|---|---|
static <V> Result<V> |
failure(@NotNull Exception e) |
static <V> Result<V> |
failure(@NotNull RuntimeException e) |
static <V> Result<V> |
failure(String message) |
static <V> Result<V> |
failure(@NotNull String message,
@NotNull Exception e) |
<E extends Throwable> |
findCause(@NotNull Class<E> errorType)
Filters the exception stack as a stream, matching causes against the provided error type.
|
Optional<Throwable> |
findCause(@NotNull Predicate<? super Throwable> predicate)
Filters the exception stack as a stream using the provided Throwable predicate.
|
abstract <W> @NotNull Result<W> |
flatMap(@NotNull Function<? super V,Result<W>> f)
Flat-map it.
|
abstract void |
forEach(@NotNull Consumer<? super V> consumer)
Standard forEach method calling a consumer to accept the value.
|
abstract Optional<RuntimeException> |
getError()
All Failures will be created with a top-level RuntimeException.
|
abstract V |
getOrDefault(V defaultValue) |
abstract V |
getOrElse(@NotNull Supplier<? extends V> defaultValue) |
boolean |
isFailure() |
boolean |
isSuccess() |
static <V> Collector<Result<V>,Stream.Builder<Result<V>>,Stream<Result<V>>> |
logAndRestream() |
static <V> Collector<Result<V>,Stream.Builder<Result<V>>,Stream<Result<V>>> |
logAndRestream(@NotNull String message) |
abstract <W> @NotNull Result<W> |
map(@NotNull Function<? super V,W> f)
Map it.
|
abstract Result<V> |
orElse(@NotNull Supplier<Result<V>> defaultValue) |
abstract Stream<V> |
stream() |
static <V> Result<V> |
success(V value) |
abstract Result<V> |
teeLogError() |
<E extends Exception> |
throwCause(@NotNull Class<E> errorType)
Feeling down because of too much functional wrapping? This method has you covered.
|
Optional<V> |
toOptional() |
static <V,R,A> Collector<Result<V>,Result.Builder<V,A>,Result<R>> |
tryCollect(@NotNull Collector<V,A,R> collector)
Create a collector that accumulates a stream of Results into a single Result containing either:
1.
|
@NotNull public abstract <W> @NotNull Result<W> map(@NotNull @NotNull Function<? super V,W> f)
W - the result type.f - the mapping function@NotNull public abstract <W> @NotNull Result<W> flatMap(@NotNull @NotNull Function<? super V,Result<W>> f)
W - the result typef - the mapping functionpublic final boolean isSuccess()
public final boolean isFailure()
public abstract Optional<RuntimeException> getError()
public final Optional<Throwable> findCause(@NotNull @NotNull Predicate<? super Throwable> predicate)
predicate - the Throwable filterpublic final <E extends Throwable> Optional<E> findCause(@NotNull @NotNull Class<E> errorType)
E - the particular Throwable type parametererrorType - the class providing teh particular Exception type parameterpublic final <E extends Exception> void throwCause(@NotNull @NotNull Class<E> errorType) throws E extends Exception
E - the particular Exception type parametererrorType - the class providing the particular Exception type parameterE - if any cause in the chain is an instance of the provided errorType, that cause is rethrownE extends Exceptionpublic abstract void forEach(@NotNull
@NotNull Consumer<? super V> consumer)
consumer - the consumerpublic static <V> Result<V> failure(@NotNull @NotNull String message, @NotNull @NotNull Exception e)
public static <V> Result<V> failure(@NotNull @NotNull RuntimeException e)
public static <V> Result<V> success(V value)
public static <V,R,A> Collector<Result<V>,Result.Builder<V,A>,Result<R>> tryCollect(@NotNull @NotNull Collector<V,A,R> collector)
This method is indented to invert the relationship between the Result monoid and the Stream/Collector type,
such that this transformation becomes easier: List<Result<A>> -> Result<List<A>>
V - the incremental valueR - the intended container typeA - the collector's accumulator typecollector - the underlying collectorpublic static <V> Collector<Result<V>,Stream.Builder<Result<V>>,Stream<Result<V>>> logAndRestream()
Copyright © 2017–2020. All rights reserved.