Class UrlParserUtils
java.lang.Object
dev.sympho.modular_commands.utils.parse.UrlParserUtils
Convenience tools for implementing URL parsers.
- Since:
- 1.0
- Version:
- 1.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if the given URL has the given host.static booleanisHost(URL url, Collection<String> aliases) Checks if the given URL has a certain host, which may be specified by any of the given aliases.static booleanChecks if the given URL has a HTTP-based protocol (HTTP or HTTPS).static booleanChecks if the given URL has HTTPS as the protocol.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.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 whichUrlParser.supports(URL)returnstruefor the URL being parsed.
-
Field Details
-
PROTOCOL_HTTP
The HTTP protocol.- See Also:
-
PROTOCOL_HTTPS
The HTTPS protocol.- See Also:
-
PROTOCOL_HTTP_COMPATIBLE
HTTP-based protocols.
-
-
Method Details
-
isHttp
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
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
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
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 whichUrlParser.supports(URL)returnstruefor 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.
-