Allow mappers to throw RuntimeExceptions and make ArgumentPair/Turple extensible

This commit is contained in:
broccolai 2020-09-28 16:46:05 +00:00 committed by Alexander Söderberg
parent d85684c22a
commit 8e2ac13ad5
3 changed files with 11 additions and 4 deletions

View file

@ -41,7 +41,7 @@ import java.util.function.Function;
* @param <V> Second argument type
* @param <O> Output type
*/
public final class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O> {
public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O> {
/**
* Create a new argument pair.

View file

@ -42,7 +42,7 @@ import java.util.function.Function;
* @param <W> Third argument type
* @param <O> Output type
*/
public final class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U, V, W>, C, O> {
public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U, V, W>, C, O> {
/**
* Create a new argument triplet.

View file

@ -128,8 +128,15 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
/* Store the parsed value */
output[i] = result.getParsedValue().orElse(null);
}
/* We now know that we have complete output, as none of the parsers returned a failure */
/*
* We now know that we have complete output, as none of the parsers returned a failure.
* Now check if the mapper threw any exceptions
*/
try {
return ArgumentParseResult.success(this.mapper.apply(this.tupleFactory.apply(output)));
} catch (final Exception e) {
return ArgumentParseResult.failure(e);
}
}
@Nonnull