T - type of result valuepublic interface Result<T>
| Modifier and Type | Interface and Description |
|---|---|
static class |
Result.Error<V> |
static class |
Result.Fail<V> |
static class |
Result.Success<V> |
static class |
Result.Unexpected<V> |
| Modifier and Type | Method and Description |
|---|---|
static <T,U> Function<Result<T>,CompletableFuture<Result<U>>> |
compose(Function<T,CompletableFuture<Result<U>>> mapper)
Create functor to compose the successful result to next completable future with another result.
|
static <T> Function<Result<T>,CompletableFuture<Status>> |
composeStatus(Function<T,CompletableFuture<Status>> mapper)
Create functor to compose the successful result to next completable future with status.
|
static <T,U> Function<Result<T>,CompletableFuture<Result<U>>> |
composeValue(U value)
Create functor to compose the successful result to completed future with specified value.
|
static <V> Result<V> |
error(String message,
Throwable throwable) |
static <V> Result<V> |
fail(Status status) |
static <V> Result<V> |
fail(UnexpectedResultException unexpected) |
Status |
getStatus() |
T |
getValue() |
default boolean |
isSuccess() |
<U> Result<U> |
map(Function<T,U> mapper) |
<U> CompletableFuture<Result<U>> |
mapResultFuture(Function<T,CompletableFuture<Result<U>>> mapper) |
CompletableFuture<Status> |
mapStatusFuture(Function<T,CompletableFuture<Status>> mapper) |
static <V> Result<V> |
success(V value) |
static <V> Result<V> |
success(V value,
Status status) |
@Nonnull T getValue() throws UnexpectedResultException
UnexpectedResultException@Nonnull <U> CompletableFuture<Result<U>> mapResultFuture(Function<T,CompletableFuture<Result<U>>> mapper)
@Nonnull CompletableFuture<Status> mapStatusFuture(Function<T,CompletableFuture<Status>> mapper)
default boolean isSuccess()
static <V> Result<V> fail(UnexpectedResultException unexpected)
static <T,U> Function<Result<T>,CompletableFuture<Result<U>>> compose(Function<T,CompletableFuture<Result<U>>> mapper)
This helper is designed to be used as CompletableFuture.thenCompose(java.util.function.Function)
argument
Example of usage:
// Execute one query, with opening new transaction
session.executeDataQuery(...)
// Execute second query if first was successful
.thenCompose(Result.compose(fisrt -> session.executeDataQuery(...)))
// Commit transaction after two successful query executions
.thenCompose(Result.composeStatus(second -> session.commitTransaction(...)));
T - type of value in ResultU - type of resulting value in returning futuremapper - mapper from successful value to completable future with another resultstatic <T> Function<Result<T>,CompletableFuture<Status>> composeStatus(Function<T,CompletableFuture<Status>> mapper)
This helper is designed to be used as CompletableFuture.thenCompose(java.util.function.Function)
argument
Example of usage:
// Execute one query, with opening new transaction
session.executeDataQuery(...)
// Execute second query if first was successful
.thenCompose(Result.compose(fisrt -> session.executeDataQuery(...)))
// Commit transaction after two successful query executions
.thenCompose(Result.composeStatus(second -> session.commitTransaction(...)));
T - type of value in Resultmapper - mapper from successful value to completable future with statusstatic <T,U> Function<Result<T>,CompletableFuture<Result<U>>> composeValue(U value)
This helper is designed to be used as CompletableFuture.thenCompose(java.util.function.Function)
argument
Example of usage:
// Execute one query
session.executeDataQuery(...)
// Execute second query if first was successful
.thenCompose(Result.compose(fisrt -> session
.executeDataQuery(...)
// But use first request result as the result of
.thenCompose(Result.composeValue(first))
)
)
T - type of value in ResultU - type of composed valuevalue - value to create completed futureCopyright © 2024. All rights reserved.