java.lang.Object
dev.sympho.modular_commands.utils.parse.UrlParser.ChoiceBase<T,P>
- Type Parameters:
T
- The parsed argument type.P
- The delegate parser type.
- All Implemented Interfaces:
ParserFunction<String,
,T> UrlParser<T>
,BiFunction<CommandContext,
String, Mono<T>>
- Direct Known Subclasses:
FunctorUrlParser.ChoiceBase
,UrlParser.Choice
public abstract static class UrlParser.ChoiceBase<T extends @NonNull Object,P extends UrlParser<T>>
extends Object
implements UrlParser<T>
Base for a parser that supports multiple URL types by delegating to one of a list of
parsers. Note that this includes
compatibility checks
.- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.sympho.modular_commands.utils.parse.UrlParser
UrlParser.Choice<T extends @NonNull Object>, UrlParser.ChoiceBase<T extends @NonNull Object,
P extends UrlParser<T>>, UrlParser.PostParser<I extends @NonNull Object, T extends @NonNull Object, P1 extends @NonNull UrlParser<I>, P2 extends @NonNull ParserFunction<I, T>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ChoiceBase
(Function<URL, @Nullable P> parserMapper) Creates a new instance. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.function.BiFunction
andThen
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply
-
Constructor Details
-
ChoiceBase
Creates a new instance.- Parameters:
parserMapper
- The function to use to determine which parser to delegate to for a given URL.
-
-
Method Details
-
supports
Description copied from interface:UrlParser
Checks if the given URL is supported by this parser. If this returnsfalse
, callingUrlParser.parse(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
true
for a given URL whileUrlParser.parse(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. -
getParser
Retrives the parser to use for the given URL.- Parameters:
url
- The URL being parsed.- Returns:
- The parser to use.
- Throws:
InvalidArgumentException
- if none of the parsers support the given URL.
-
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.
-