Class EntityRefUrlParser<R extends EntityRef<? extends @NonNull Entity>>

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
  • Constructor Details

    • EntityRefUrlParser

      public EntityRefUrlParser()
  • Method Details

    • validPath

      @Pure protected abstract boolean validPath(String path)
      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 R parsePath(String path)
      Parses the URL path.
      Parameters:
      path - The path.
      Returns:
      The parsed entity, or null if the path is not valid.
    • typeName

      @Pure protected abstract String typeName()
      Gets the display name for this type.
      Returns:
      The name.
      API Note:
      For use in error messages.
    • supports

      public boolean supports(URL url)
      Description copied from interface: UrlParser
      Checks if the given URL is supported by this parser. If this returns false, calling UrlParser.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 while UrlParser.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.

      Specified by:
      supports in interface UrlParser<R extends EntityRef<? extends @NonNull Entity>>
      Parameters:
      url - The URL to check.
      Returns:
      Whether the URL is compatible with this parser.
    • parse

      @SideEffectFree public final R parse(URL url) throws InvalidArgumentException
      Parses the given URL into the corresponding reference.
      Parameters:
      url - The URL to parse.
      Returns:
      The parsed reference. May fail with a InvalidArgumentException if not a valid reference URL.
      Throws:
      InvalidArgumentException - if not a valid reference URL.
    • parse

      @SideEffectFree public final R parse(String raw) throws InvalidArgumentException
      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

      public final Mono<R> parse(CommandContext context, URL url) throws InvalidArgumentException
      Description copied from interface: UrlParser
      Parses the given URL.
      Specified by:
      parse in interface UrlParser<R extends EntityRef<? extends @NonNull Entity>>
      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.