Class UrlParser.ChoiceBase<T extends @NonNull Object,P extends UrlParser<T>>

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
Enclosing interface:
UrlParser<T extends @NonNull Object>

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

    • ChoiceBase

      protected ChoiceBase(Function<URL,@Nullable P> parserMapper)
      Creates a new instance.
      Parameters:
      parserMapper - The function to use to determine which parser to delegate to for a given URL.
  • Method Details

    • 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<T extends @NonNull Object>
      Parameters:
      url - The URL to check.
      Returns:
      Whether the URL is compatible with this parser.
    • getParser

      @Pure protected P getParser(URL url) throws InvalidArgumentException
      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

      public Mono<T> parse(CommandContext context, URL url) throws InvalidArgumentException
      Description copied from interface: UrlParser
      Parses the given URL.
      Specified by:
      parse in interface UrlParser<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.