Allow mappers to throw RuntimeExceptions and make ArgumentPair/Turple extensible
This commit is contained in:
parent
d85684c22a
commit
8e2ac13ad5
3 changed files with 11 additions and 4 deletions
|
|
@ -41,7 +41,7 @@ import java.util.function.Function;
|
||||||
* @param <V> Second argument type
|
* @param <V> Second argument type
|
||||||
* @param <O> Output 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.
|
* Create a new argument pair.
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import java.util.function.Function;
|
||||||
* @param <W> Third argument type
|
* @param <W> Third argument type
|
||||||
* @param <O> Output 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.
|
* Create a new argument triplet.
|
||||||
|
|
|
||||||
|
|
@ -128,8 +128,15 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
/* Store the parsed value */
|
/* Store the parsed value */
|
||||||
output[i] = result.getParsedValue().orElse(null);
|
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)));
|
return ArgumentParseResult.success(this.mapper.apply(this.tupleFactory.apply(output)));
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return ArgumentParseResult.failure(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue