Interface AggregateParser<C,O>
- Type Parameters:
C- the command sender typeO- the output type
- All Superinterfaces:
ArgumentParser<C,,O> ArgumentParser.FutureArgumentParser<C,,O> ParserDescriptor<C,,O> SuggestionProviderHolder<C>
components() and transforms the aggregate results into
an output using the mapper().
You may either implement this interface to create a new parser type, or create an aggregate parser by using a
builder().
The parsers components() will be invoked in the order of the returned collection.
When parsing, each parser will be invoked and the result will be stored in a AggregateParsingContext.
After parsing, the mapper() will be invoked, turning the intermediate results into the output type which is then
returned by this parser.
When evaluating the suggestions for this parser, some component parsers will be invoked, which allows
the suggestion providers to rely on the results from the preceding components.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.incendo.cloud.parser.ArgumentParser
ArgumentParser.FutureArgumentParser<C,T> -
Method Summary
Modifier and TypeMethodDescriptionstatic <C> @NonNull AggregateParserBuilder<C> builder()Returns a new aggregate command parser builder.Returns the inner components of the parser.mapper()Returns the result mapper.static <C,U, V> @NonNull AggregateParserPairBuilder <C, U, V, Pair<U, V>> pairBuilder(@NonNull String firstName, @NonNull ParserDescriptor<C, U> firstParser, @NonNull String secondName, @NonNull ParserDescriptor<C, V> secondParser) Returns a new aggregate pair command parser builder.default @NonNull CompletableFuture<@NonNull ArgumentParseResult<O>> parseFuture(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput) Returns a future that completes with the result of parsing the givencommandInput.default @NonNull ArgumentParser<C, O> parser()Returns the parser.default @NonNull SuggestionProvider<C> Returns the suggestion provider.static <C,U, V, Z>
@NonNull AggregateParserTripletBuilder<C, U, V, Z, Triplet<U, V, Z>> tripletBuilder(@NonNull String firstName, @NonNull ParserDescriptor<C, U> firstParser, @NonNull String secondName, @NonNull ParserDescriptor<C, V> secondParser, @NonNull String thirdName, @NonNull ParserDescriptor<C, Z> thirdParser) Returns a new aggregate triplet command parser builder.Methods inherited from interface org.incendo.cloud.parser.ArgumentParser
flatMap, flatMapSuccess, mapSuccessMethods inherited from interface org.incendo.cloud.parser.ArgumentParser.FutureArgumentParser
parseMethods inherited from interface org.incendo.cloud.parser.ParserDescriptor
flatMap, flatMap, flatMapSuccess, flatMapSuccess, mapSuccess, mapSuccess, valueType
-
Method Details
-
builder
Returns a new aggregate command parser builder. The builder is immutable, and each method returns a new builder instance.- Type Parameters:
C- the command sender type- Returns:
- the builder
-
pairBuilder
static <C,U, @NonNull AggregateParserPairBuilder<C,V> U, pairBuilderV, Pair<U, V>> (@NonNull String firstName, @NonNull ParserDescriptor<C, U> firstParser, @NonNull String secondName, @NonNull ParserDescriptor<C, V> secondParser) Returns a new aggregate pair command parser builder. The builder is immutable, and each method returns a new builder instance.- Type Parameters:
C- the command sender typeU- the type of the first componentV- the type of the second component- Parameters:
firstName- the name of the first componentfirstParser- the parser for the first componentsecondName- the name of the second componentsecondParser- the parser for the second component- Returns:
- the builder
-
tripletBuilder
static <C,U, @NonNull AggregateParserTripletBuilder<C,V, Z> U, tripletBuilderV, Z, Triplet<U, V, Z>> (@NonNull String firstName, @NonNull ParserDescriptor<C, U> firstParser, @NonNull String secondName, @NonNull ParserDescriptor<C, V> secondParser, @NonNull String thirdName, @NonNull ParserDescriptor<C, Z> thirdParser) Returns a new aggregate triplet command parser builder. The builder is immutable, and each method returns a new builder instance.- Type Parameters:
C- the command sender typeU- the type of the first componentV- the type of the second componentZ- the type of the third component- Parameters:
firstName- the name of the first componentfirstParser- the parser for the first componentsecondName- the name of the second componentsecondParser- the parser for the second componentthirdName- the name of the third componentthirdParser- the parser for the third component- Returns:
- the builder
-
components
@NonNull List<@NonNull CommandComponent<C>> components()Returns the inner components of the parser.- Returns:
- an unmodifiable view of the inner components in the order they were defined in
-
mapper
@NonNull AggregateResultMapper<C,O> mapper()Returns the result mapper. It will be invoked after parsing to map the intermediate results into the output type.- Returns:
- the result mapper
-
parseFuture
default @NonNull CompletableFuture<@NonNull ArgumentParseResult<O>> parseFuture(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput) Description copied from interface:ArgumentParserReturns a future that completes with the result of parsing the givencommandInput.This method may be called when a command chain is being parsed for execution (using
CommandExecutor.executeCommand(Object, String)) or when a command is being parsed to provide context for suggestions (usingSuggestionFactory.suggest(Object, String)). It is possible to useCommandContext.isSuggestions()} to see what the purpose of the parsing is. Particular care should be taken when parsing for suggestions, as the parsing method is then likely to be called once for every character written by the command sender.This method should never throw any exceptions under normal circumstances. Instead, if the parsing for some reason cannot be done successfully
ArgumentParseResult.failure(Throwable)orArgumentParseResult.failureFuture(Throwable)should be returned. This then wraps any exception that should be forwarded to the command sender.The parser is assumed to be completely stateless and should not store any information about the command sender or the command context. Instead, information should be stored in the
CommandContext.- Specified by:
parseFuturein interfaceArgumentParser<C,O> - Specified by:
parseFuturein interfaceArgumentParser.FutureArgumentParser<C,O> - Parameters:
commandContext- Command contextcommandInput- Command Input- Returns:
- future that completes with the result.
-
suggestionProvider
Description copied from interface:ArgumentParserReturns the suggestion provider.By default, this will return the parser, if the parser is also a
SuggestionProvider. Otherwise,SuggestionProvider.noSuggestions()will be returned.- Specified by:
suggestionProviderin interfaceArgumentParser<C,O> - Specified by:
suggestionProviderin interfaceSuggestionProviderHolder<C>- Returns:
- the suggestion provider
-
parser
Description copied from interface:ParserDescriptorReturns the parser.- Specified by:
parserin interfaceParserDescriptor<C,O> - Returns:
- the parser
-