Class UrlParserUtils

java.lang.Object
dev.sympho.modular_commands.utils.parse.UrlParserUtils

public final class UrlParserUtils extends Object
Convenience tools for implementing URL parsers.
Since:
1.0
Version:
1.0
  • Field Details

    • PROTOCOL_HTTP

      public static final String PROTOCOL_HTTP
      The HTTP protocol.
      See Also:
    • PROTOCOL_HTTPS

      public static final String PROTOCOL_HTTPS
      The HTTPS protocol.
      See Also:
    • PROTOCOL_HTTP_COMPATIBLE

      public static final List<String> PROTOCOL_HTTP_COMPATIBLE
      HTTP-based protocols.
  • Method Details

    • isHttp

      @Pure public static boolean isHttp(URL url)
      Checks if the given URL has a HTTP-based protocol (HTTP or HTTPS).
      Parameters:
      url - The URL to check.
      Returns:
      If the URL has a compatible protocol.
      API Note:
      This method allows HTTPS as well given that it is generally intercompatible with HTTP and is generally recommended for better security.
    • isHttps

      @Pure public static boolean isHttps(URL url)
      Checks if the given URL has HTTPS as the protocol.
      Parameters:
      url - The URL to check.
      Returns:
      If the URL has a compatible protocol.
    • isHost

      @Pure public static boolean isHost(URL url, String host)
      Checks if the given URL has the given host.
      Parameters:
      url - The URL to check.
      host - The host.
      Returns:
      If the URL has the given host.
    • isHost

      @Pure public static boolean isHost(URL url, Collection<String> aliases)
      Checks if the given URL has a certain host, which may be specified by any of the given aliases.
      Parameters:
      url - The URL to check.
      aliases - The host aliases.
      Returns:
      If the URL has the given host.
    • toMapper

      @SideEffectFree public static <T extends @NonNull Object, P extends UrlParser<T>> Function<URL,@Nullable P> toMapper(Collection<? extends P> parsers)
      Creates a delegate parser mapper where 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.
      P - The delegate parser type.
      Parameters:
      parsers - The delegate parsers.
      Returns:
      The mapper.
    • toHostMapper

      @Pure public static <T extends @NonNull Object, P extends UrlParser<T>> Function<URL,@Nullable P> toHostMapper(Map<String,? extends P> parsers)
      Creates a delegate parser mapper where the parser choice depends on the host of the URL, using the given host-parser mappings.
      Type Parameters:
      T - The parsed argument type.
      P - The delegate parser type.
      Parameters:
      parsers - The host-parser mappings.
      Returns:
      The mapper.