java.lang.Object
dev.sympho.modular_commands.utils.parse.entity.EntityRefUrlParser<R>
- Type Parameters:
R- The reference type.
- All Implemented Interfaces:
ParserFunction<String,,R> UrlParser<R>,BiFunction<CommandContext,String, Mono<R>>
- Direct Known Subclasses:
ChannelRefUrlParser,MessageRefUrlParser
public abstract class EntityRefUrlParser<R extends EntityRef<? extends @NonNull Entity>>
extends Object
implements UrlParser<R>
A parser for URLs of Discord entities to references.
- 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.final RParses the given string as a reference URL.final RParses the given URL into the corresponding reference.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
-
EntityRefUrlParser
public EntityRefUrlParser()
-
-
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
Parses the URL path.- Parameters:
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
Parses the given URL into the corresponding reference.- Parameters:
url- The URL to parse.- Returns:
- The parsed reference. May fail with a
InvalidArgumentExceptionif not a valid reference URL. - Throws:
InvalidArgumentException- if not a valid reference URL.
-
parse
Parses the given string as a reference URL.- Parameters:
raw- The string to parse.- Returns:
- The parsed reference.
- Throws:
InvalidArgumentException- if the given string is not a valid reference URL.
-
parse
Description copied from interface:UrlParserParses the given URL.- Specified by:
parsein interfaceUrlParser<R extends EntityRef<? 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.
-