Package org.incendo.cloud.parser
Class ArgumentParseResult<T>
java.lang.Object
org.incendo.cloud.parser.ArgumentParseResult<T>
- Type Parameters:
T- Parser return type
Result of the parsing done by a
ArgumentParser-
Method Summary
Modifier and TypeMethodDescriptionasFuture()Maps the result to a completable future.failure()Get the failure reason, if it existsstatic <T> @NonNull ArgumentParseResult<T> Indicate that the parsing failedstatic <T> @NonNull CompletableFuture<@NonNull ArgumentParseResult<T>> failureFuture(@NonNull Throwable failure) Create afuturecompleted with a failed parse result.abstract <O> @NonNull ArgumentParseResult<O> flatMapSuccess(@NonNull Function<T, ArgumentParseResult<O>> mapper) Returns the result from applyingmapperto the parsed value, or the same failure as this result.abstract <O> @NonNull CompletableFuture<ArgumentParseResult<O>> Returns a future resulting from applyingmapperto the parsed value, or a completed future with the same failure as this result.abstract <O> @NonNull ArgumentParseResult<O> mapSuccess(@NonNull Function<T, O> mapper) Returns the result from applyingmapperto the parsed value and wrapping insuccess(Object), or the same failure as this result.abstract <O> @NonNull CompletableFuture<ArgumentParseResult<O>> mapSuccessFuture(@NonNull Function<T, CompletableFuture<O>> mapper) Returns a success future resulting from applyingmapperto the parsed value and wrapping insuccess(Object), or a completed future with the same failure as this result.Get the parsed value, if it existsstatic <T> @NonNull ArgumentParseResult<T> Indicate that the parsing succeededstatic <T> @NonNull CompletableFuture<@NonNull ArgumentParseResult<T>> successFuture(@NonNull T value) Create afuturecompleted with a successful parse result.
-
Method Details
-
failure
Indicate that the parsing failedIf the
failureis aCompletionExceptionthen it will be unwrapped.- Type Parameters:
T- Parser return type- Parameters:
failure- Failure reason- Returns:
- Failed parse result
-
failureFuture
@API(status=STABLE) public static <T> @NonNull CompletableFuture<@NonNull ArgumentParseResult<T>> failureFuture(@NonNull Throwable failure) Create afuturecompleted with a failed parse result.- Type Parameters:
T- parser value type- Parameters:
failure- failure reason- Returns:
- completed future with failed result
-
success
Indicate that the parsing succeeded- Type Parameters:
T- Parser return type- Parameters:
value- Value produced by the parser- Returns:
- Succeeded parse result
-
successFuture
@API(status=STABLE) public static <T> @NonNull CompletableFuture<@NonNull ArgumentParseResult<T>> successFuture(@NonNull T value) Create afuturecompleted with a successful parse result.- Type Parameters:
T- parser value type- Parameters:
value- parsed value- Returns:
- completed future with successful result
-
parsedValue
Get the parsed value, if it exists- Returns:
- Optional containing the parsed value
-
failure
Get the failure reason, if it exists- Returns:
- Optional containing the failure reason
-
asFuture
Maps the result to a completable future.- Returns:
- the future
-
flatMapSuccessFuture
public abstract <O> @NonNull CompletableFuture<ArgumentParseResult<O>> flatMapSuccessFuture(@NonNull Function<T, CompletableFuture<ArgumentParseResult<O>>> mapper) Returns a future resulting from applyingmapperto the parsed value, or a completed future with the same failure as this result.- Type Parameters:
O- new result value type- Parameters:
mapper- mapper- Returns:
- new result future
-
mapSuccessFuture
public abstract <O> @NonNull CompletableFuture<ArgumentParseResult<O>> mapSuccessFuture(@NonNull Function<T, CompletableFuture<O>> mapper) Returns a success future resulting from applyingmapperto the parsed value and wrapping insuccess(Object), or a completed future with the same failure as this result.- Type Parameters:
O- new result value type- Parameters:
mapper- mapper- Returns:
- new result future
-
flatMapSuccess
public abstract <O> @NonNull ArgumentParseResult<O> flatMapSuccess(@NonNull Function<T, ArgumentParseResult<O>> mapper) Returns the result from applyingmapperto the parsed value, or the same failure as this result.- Type Parameters:
O- new result value type- Parameters:
mapper- mapper- Returns:
- new result
-
mapSuccess
Returns the result from applyingmapperto the parsed value and wrapping insuccess(Object), or the same failure as this result.- Type Parameters:
O- new result value type- Parameters:
mapper- mapper- Returns:
- new result
-