Interface FunctorUrlParser<T extends @NonNull Object>

Type Parameters:
T - The parsed type.
All Superinterfaces:
BiFunction<CommandContext,String,Mono<T>>, ParserFunction<String,T>, UrlParser<T>
All Known Implementing Classes:
FunctorUrlParser.Choice, FunctorUrlParser.ChoiceBase, FunctorUrlParser.PostParser

public interface FunctorUrlParser<T extends @NonNull Object> extends UrlParser<T>
A parser for URL-based arguments that are independent from the invocation context.
Since:
1.0
Version:
1.0
  • Method Details

    • choice

      static <T extends @NonNull Object> FunctorUrlParser<T> choice(Function<URL,@Nullable FunctorUrlParser<T>> parserMapper)
      Creates a parser that delegates to other parsers, chosen by the given mapping function based on the URL to parse.
      Type Parameters:
      T - The parsed argument type.
      Parameters:
      parserMapper - The function to use to determine which parser to delegate to for a given URL.
      Returns:
      The parser.
    • choice

      static <T extends @NonNull Object> FunctorUrlParser<T> choice(Collection<? extends FunctorUrlParser<T>> parsers)
      Creates a parser that delegates to the given parsers.

      The parser choice is defined as the first parser in the iteration order of the given collection for which UrlParser.supports(URL) returns true for the URL being parsed. This implies that the iteration order matters if, and only if, there are URLs that may be supported by more than one of the parsers in the collection.

      Type Parameters:
      T - The parsed argument type.
      Parameters:
      parsers - The parsers to delegate to.
      Returns:
      The parser.
    • choice

      @SafeVarargs static <T extends @NonNull Object> FunctorUrlParser<T> choice(FunctorUrlParser<T>... parsers)
      Creates a parser that delegates to the given parsers.

      The parser choice is defined as the first parser in the given order for which UrlParser.supports(URL) returns true for the URL being parsed. This implies that the iteration order matters if, and only if, there are URLs that may be supported by more than one of the parsers in the collection.

      Type Parameters:
      T - The parsed argument type.
      Parameters:
      parsers - The parsers to delegate to.
      Returns:
      The parser.
    • choiceHost

      static <T extends @NonNull Object> FunctorUrlParser<T> choiceHost(Map<String,? extends FunctorUrlParser<T>> parsers)
      Creates a parser that delegates to a parser depending on the host of the URL, using the given host-parser mappings.
      Type Parameters:
      T - The parsed argument type.
      Parameters:
      parsers - The host-parser mappings to delegate to.
      Returns:
      The parser.
    • parse

      Parses the given URL.
      Parameters:
      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.
    • parse

      default 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.
    • then

      @SideEffectFree default <V extends @NonNull Object> UrlParser<V> then(Parsers.Functor<T,V> after)
      Returns a composed parser that first applies this parser to its input, and then applies the after parser to the result. If parsing with either parser throws an exception, it is relayed to the caller of the composed parser.
      Type Parameters:
      V - The type of output of the after parser, and of the composed parser.
      Parameters:
      after - The parser to apply after this parser is applied.
      Returns:
      The composed parser.