java.lang.Object
dev.sympho.modular_commands.utils.parse.EntityUrlParser<E>
- Type Parameters:
E- The entity type.
- All Implemented Interfaces:
ParserFunction<String,,E> UrlParser<E>,BiFunction<CommandContext,String, Mono<E>>
- Direct Known Subclasses:
ChannelUrlParser,MessageUrlParser
public abstract class EntityUrlParser<E extends @NonNull Entity>
extends Object
implements UrlParser<E>
A parser for URLs of Discord entities.
- Since:
- 1.0
- Version:
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionparse(CommandContext context, URL url) Parses the given URL.parsePath(GatewayDiscordClient client, String path) Parses the URL path.booleanChecks if the given URL is supported by this parser.protected abstract StringtypeName()Gets the display name for this type.protected abstract booleanChecks if the given path (endpoint) is valid for the entity type of this parser.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThenMethods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply
-
Constructor Details
-
EntityUrlParser
public EntityUrlParser()
-
-
Method Details
-
validPath
Checks if the given path (endpoint) is valid for the entity type of this parser.- Parameters:
path- The path.- Returns:
- If the path is valid for this parser.
-
parsePath
@SideEffectFree protected abstract @Nullable Mono<E> parsePath(GatewayDiscordClient client, String path) Parses the URL path.- Parameters:
client- The Discord client.path- The path.- Returns:
- The parsed entity, or
nullif the path is not valid.
-
typeName
Gets the display name for this type.- Returns:
- The name.
- API Note:
- For use in error messages.
-
supports
Description copied from interface:UrlParserChecks 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
truefor 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. -
parse
Description copied from interface:UrlParserParses the given URL.- Specified by:
parsein interfaceUrlParser<E extends @NonNull Entity>- 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.
-