- Type Parameters:
T- The parsed type.
- All Superinterfaces:
BiFunction<CommandContext,,String, Mono<T>> ParserFunction<String,T>
- All Known Subinterfaces:
FunctorUrlParser<T>
- All Known Implementing Classes:
ChannelRefUrlParser,ChannelUrlParser,EntityRefUrlParser,EntityUrlParser,FunctorUrlParser.Choice,FunctorUrlParser.ChoiceBase,FunctorUrlParser.PostParser,MessageRefUrlParser,MessageUrlParser,UrlParser.Choice,UrlParser.ChoiceBase,UrlParser.PostParser
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classUrlParser.Choice<T extends @NonNull Object>Parser that supports multiple URL types by delegating to one of a list of parsers.static classBase for a parser that supports multiple URL types by delegating to one of a list of parsers.static classUrlParser.PostParser<I extends @NonNull Object,T extends @NonNull Object, P1 extends @NonNull UrlParser<I>, P2 extends @NonNull ParserFunction<I, T>> A composed parser that first applies this parser to one parser, and then applies the results to a second parser. -
Method Summary
Modifier and TypeMethodDescriptionCreates a parser that delegates to the given parsers.choice(Collection<? extends UrlParser<T>> parsers) Creates a parser that delegates to the given parsers.Creates a parser that delegates to other parsers, chosen by the given mapping function based on the URL to parse.choiceHost(Map<String, ? extends UrlParser<T>> parsers) Creates a parser that delegates to a parser depending on the host of the URL, using the given host-parser mappings.static URLParses the given string into a URL.parse(CommandContext context, String raw) Parses the given raw argument from the user into the corresponding value.parse(CommandContext context, URL url) Parses the given URL.booleanChecks if the given URL is supported by this parser.then(ParserFunction<T, V> after) Returns a composed parser that first applies this parser to its input, and then applies the after parser to the result.Methods inherited from interface java.util.function.BiFunction
andThenMethods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply
-
Method Details
-
choice
static <T extends @NonNull Object> UrlParser<T> choice(Function<URL, @Nullable UrlParser<T>> parserMapper) Creates a parser that delegates to other parsers, chosen by the given mapping function based on the URL to parse.- Type Parameters:
T- The parsed argument type.- Parameters:
parserMapper- The function to use to determine which parser to delegate to for a given URL.- Returns:
- The parser.
-
choice
Creates a parser that delegates to the given parsers.The parser choice is defined as the first parser in the iteration order of the given collection for which
supports(URL)returnstruefor the URL being parsed. This implies that the iteration order matters if, and only if, there are URLs that may be supported by more than one of the parsers in the collection.- Type Parameters:
T- The parsed argument type.- Parameters:
parsers- The parsers to delegate to.- Returns:
- The parser.
-
choice
Creates a parser that delegates to the given parsers.The parser choice is defined as the first parser in the given order for which
supports(URL)returnstruefor the URL being parsed. This implies that the iteration order matters if, and only if, there are URLs that may be supported by more than one of the parsers in the collection.- Type Parameters:
T- The parsed argument type.- Parameters:
parsers- The parsers to delegate to.- Returns:
- The parser.
-
choiceHost
static <T extends @NonNull Object> UrlParser<T> choiceHost(Map<String, ? extends UrlParser<T>> parsers) Creates a parser that delegates to a parser depending on the host of the URL, using the given host-parser mappings.- Type Parameters:
T- The parsed argument type.- Parameters:
parsers- The host-parser mappings to delegate to.- Returns:
- The parser.
-
getUrl
Parses the given string into a URL.- Parameters:
raw- The string to parse.- Returns:
- The URL.
- Throws:
InvalidArgumentException- if the given string is not a valid URL.- API Note:
- Mainly a wrapper to convert the URL exception into the invalid argument type.
-
supports
Checks if the given URL is supported by this parser. If this returnsfalse, callingparse(CommandContext, URL)with the same URL will result in an error.Note that the opposite isn't necessarily true; it is possible for this method to return
truefor a given URL whileparse(CommandContext, URL)results in an error. That just means that the basic structure of the URL was detected as being compatible with this parser (for example, having a particular host and/or protocol), but was malformed or a variant that the parser doesn't support.- Parameters:
url- The URL to check.- Returns:
- Whether the URL is compatible with this parser.
-
parse
Parses the given URL.- Parameters:
context- The execution context.url- The URL to parse.- Returns:
- The parsed value. May result in a
InvalidArgumentExceptionif the URL is invalid. - Throws:
InvalidArgumentException- if the URL is invalid.
-
parse
Description copied from interface:ParserFunctionParses the given raw argument from the user into the corresponding value.- Specified by:
parsein interfaceParserFunction<String,T extends @NonNull Object> - Parameters:
context- The execution context.raw- The raw argument received from the user.- Returns:
- A Mono that issues the parsed argument. If the raw value is invalid, it may
fail with a
InvalidArgumentException. May be empty, in which case the value defers to thedefault(functionally the same as if the argument was missing, but without causing an error if the parameter isrequired). - Throws:
InvalidArgumentException- if the given argument is not a valid value.
-
then
Returns a composed parser that first applies this parser to its input, and then applies the after parser to the result. If parsing with either parser throws an exception, it is relayed to the caller of the composed parser.
-