From cd90665559ef18f6005b09be9162d8e630b05a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Sep 2020 23:45:56 +0200 Subject: [PATCH] :zap: Make it possible to extent the argument product types --- .../arguments/compound/ArgumentPair.java | 33 +++++++++----- .../arguments/compound/ArgumentTriplet.java | 43 ++++++++++++------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentPair.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentPair.java index cee39180..2017ac7d 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentPair.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentPair.java @@ -43,13 +43,24 @@ import java.util.function.Function; */ public final class ArgumentPair extends CompoundArgument, C, O> { - private ArgumentPair(final boolean required, - @Nonnull final String name, - @Nonnull final Pair names, - @Nonnull final Pair, Class> types, - @Nonnull final Pair, ArgumentParser> parserPair, - @Nonnull final Function, O> mapper, - @Nonnull final TypeToken valueType) { + /** + * Create a new argument pair. + * + * @param required Whether or not the argument is required + * @param name The argument name + * @param names Names of the sub-arguments (in order) + * @param types Types of the sub-arguments (in order) + * @param parserPair The sub arguments + * @param mapper Mapper that maps the sub-arguments to the output type + * @param valueType The output type + */ + protected ArgumentPair(final boolean required, + @Nonnull final String name, + @Nonnull final Pair names, + @Nonnull final Pair, Class> types, + @Nonnull final Pair, ArgumentParser> parserPair, + @Nonnull final Function, O> mapper, + @Nonnull final TypeToken valueType) { super(required, name, names, parserPair, types, mapper, o -> Pair.of((U) o[0], (V) o[1]), valueType); } @@ -75,12 +86,12 @@ public final class ArgumentPair extends CompoundArgument, final ParserRegistry parserRegistry = manager.getParserRegistry(); final ArgumentParser firstParser = parserRegistry.createParser(TypeToken.of(types.getFirst()), ParserParameters.empty()).orElseThrow(() -> - new IllegalArgumentException( - "Could not create parser for primary type")); + new IllegalArgumentException( + "Could not create parser for primary type")); final ArgumentParser secondaryParser = parserRegistry.createParser(TypeToken.of(types.getSecond()), ParserParameters.empty()).orElseThrow(() -> - new IllegalArgumentException( - "Could not create parser for secondary type")); + new IllegalArgumentException( + "Could not create parser for secondary type")); return new ArgumentPairIntermediaryBuilder<>(true, name, names, Pair.of(firstParser, secondaryParser), types); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentTriplet.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentTriplet.java index 248b2835..e5e0d4b5 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentTriplet.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/compound/ArgumentTriplet.java @@ -44,14 +44,25 @@ import java.util.function.Function; */ public final class ArgumentTriplet extends CompoundArgument, C, O> { - private ArgumentTriplet(final boolean required, - @Nonnull final String name, - @Nonnull final Triplet names, - @Nonnull final Triplet, Class, Class> types, - @Nonnull final Triplet, ArgumentParser, - ArgumentParser> parserTriplet, - @Nonnull final Function, O> mapper, - @Nonnull final TypeToken valueType) { + /** + * Create a new argument triplet. + * + * @param required Whether or not the argument is required + * @param name The argument name + * @param names Names of the sub-arguments (in order) + * @param types Types of the sub-arguments (in order) + * @param parserTriplet The sub arguments + * @param mapper Mapper that maps the sub-arguments to the output type + * @param valueType The output type + */ + protected ArgumentTriplet(final boolean required, + @Nonnull final String name, + @Nonnull final Triplet names, + @Nonnull final Triplet, Class, Class> types, + @Nonnull final Triplet, ArgumentParser, + ArgumentParser> parserTriplet, + @Nonnull final Function, O> mapper, + @Nonnull final TypeToken valueType) { super(required, name, names, parserTriplet, types, mapper, o -> Triplet.of((U) o[0], (V) o[1], (W) o[2]), valueType); } @@ -79,16 +90,16 @@ public final class ArgumentTriplet extends CompoundArgument parserRegistry = manager.getParserRegistry(); final ArgumentParser firstParser = parserRegistry.createParser(TypeToken.of(types.getFirst()), ParserParameters.empty()).orElseThrow(() -> - new IllegalArgumentException( - "Could not create parser for primary type")); + new IllegalArgumentException( + "Could not create parser for primary type")); final ArgumentParser secondaryParser = parserRegistry.createParser(TypeToken.of(types.getSecond()), ParserParameters.empty()).orElseThrow(() -> - new IllegalArgumentException( - "Could not create parser for secondary type")); + new IllegalArgumentException( + "Could not create parser for secondary type")); final ArgumentParser tertiaryParser = parserRegistry.createParser(TypeToken.of(types.getThird()), - ParserParameters.empty()).orElseThrow(() -> - new IllegalArgumentException( - "Could not create parser for tertiary type")); + ParserParameters.empty()).orElseThrow(() -> + new IllegalArgumentException( + "Could not create parser for tertiary type")); return new ArgumentTripletIntermediaryBuilder<>(true, name, names, Triplet.of(firstParser, secondaryParser, tertiaryParser), types); } @@ -106,7 +117,7 @@ public final class ArgumentTriplet extends CompoundArgument names, @Nonnull final Triplet, - ArgumentParser, ArgumentParser> parserTriplet, + ArgumentParser, ArgumentParser> parserTriplet, @Nonnull final Triplet, Class, Class> types) { this.required = required; this.name = name;