- Type Parameters:
T
- The parsed type.
- All Superinterfaces:
BiFunction<CommandContext,
,String, Mono<T>> ParserFunction<String,
,T> UrlParser<T>
- All Known Implementing Classes:
FunctorUrlParser.Choice
,FunctorUrlParser.ChoiceBase
,FunctorUrlParser.PostParser
A parser for URL-based arguments that are independent from the invocation context.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
FunctorUrlParser.Choice<T extends @NonNull Object>
Parser that supports multiple URL types by delegating to one of a list of parsers.static class
FunctorUrlParser.ChoiceBase<T extends @NonNull Object,
P extends FunctorUrlParser<T>> Base for a parser that supports multiple URL types by delegating to one of a list of parsers.static class
FunctorUrlParser.PostParser<I extends @NonNull Object,
T extends @NonNull Object, P1 extends @NonNull FunctorUrlParser<I>, P2 extends @NonNull Parsers.Functor<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 TypeMethodDescriptionstatic <T extends @NonNull Object>
FunctorUrlParser<T>choice
(FunctorUrlParser<T>... parsers) Creates a parser that delegates to the given parsers.static <T extends @NonNull Object>
FunctorUrlParser<T>choice
(Collection<? extends FunctorUrlParser<T>> parsers) Creates a parser that delegates to the given parsers.static <T extends @NonNull Object>
FunctorUrlParser<T>choice
(Function<URL, @Nullable FunctorUrlParser<T>> parserMapper) Creates a parser that delegates to other parsers, chosen by the given mapping function based on the URL to parse.static <T extends @NonNull Object>
FunctorUrlParser<T>choiceHost
(Map<String, ? extends FunctorUrlParser<T>> parsers) Creates a parser that delegates to a parser depending on the host of the URL, using the given host-parser mappings.parse
(CommandContext context, URL url) Parses the given URL.Parses the given URL.then
(Parsers.Functor<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
andThen
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply
-
Method Details
-
choice
static <T extends @NonNull Object> FunctorUrlParser<T> choice(Function<URL, @Nullable FunctorUrlParser<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
static <T extends @NonNull Object> FunctorUrlParser<T> choice(Collection<? extends FunctorUrlParser<T>> parsers) 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
UrlParser.supports(URL)
returnstrue
for 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
@SafeVarargs static <T extends @NonNull Object> FunctorUrlParser<T> choice(FunctorUrlParser<T>... parsers) Creates a parser that delegates to the given parsers.The parser choice is defined as the first parser in the given order for which
UrlParser.supports(URL)
returnstrue
for 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> FunctorUrlParser<T> choiceHost(Map<String, ? extends FunctorUrlParser<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.
-
parse
Parses the given URL.- Parameters:
url
- The URL to parse.- Returns:
- The parsed value. May result in a
InvalidArgumentException
if the URL is invalid. - Throws:
InvalidArgumentException
- if the URL is invalid.
-
parse
Description copied from interface:UrlParser
Parses the given URL.- Specified by:
parse
in interfaceUrlParser<T extends @NonNull Object>
- Parameters:
context
- The execution context.url
- The URL to parse.- Returns:
- The parsed value. May result in a
InvalidArgumentException
if the URL is invalid. - Throws:
InvalidArgumentException
- if the URL is invalid.
-
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.- Type Parameters:
V
- The type of output of theafter
parser, and of the composed parser.- Parameters:
after
- The parser to apply after this parser is applied.- Returns:
- The composed parser.
-