Class URLWrapper


  • public class URLWrapper
    extends java.lang.Object
    • Constructor Detail

      • URLWrapper

        public URLWrapper()
      • URLWrapper

        @Deprecated
        @ScheduledForRemoval
        public URLWrapper​(java.lang.String url)
                   throws java.net.MalformedURLException
        Deprecated.
        Deprecated, use ofURL(String) or ofURI(String) instead.
        The original behavior was ofURL(String).
        Throws:
        java.net.MalformedURLException
      • URLWrapper

        public URLWrapper​(java.net.URL url)
      • URLWrapper

        public URLWrapper​(java.net.URI uri)
    • Method Detail

      • empty

        public static URLWrapper empty()
        Create a new empty URLWrapper.
        Returns:
        The URLWrapper
      • of

        @Deprecated
        @ScheduledForRemoval
        public static URLWrapper of​(java.lang.String url)
                             throws java.net.MalformedURLException
        Deprecated.
        Deprecated, use ofURL(String) or ofURI(String) instead.
        The original behavior was ofURL(String).
        Throws:
        java.net.MalformedURLException
      • ofURL

        public static URLWrapper ofURL​(java.lang.String url)
                                throws java.net.MalformedURLException
        Create a new URLWrapper from a URL string.
        Parameters:
        url - The URL to wrap
        Returns:
        The URLWrapper
        Throws:
        java.net.MalformedURLException - If the URL is invalid
      • ofURI

        public static URLWrapper ofURI​(java.lang.String uri)
                                throws java.lang.IllegalArgumentException
        Create a new URLWrapper from a URI string.
        Parameters:
        uri - The URI to wrap
        Returns:
        The URLWrapper
        Throws:
        java.lang.IllegalArgumentException - If the URI is invalid
      • of

        public static URLWrapper of​(java.net.URL url)
        Create a new URLWrapper from an URL.
        Parameters:
        url - The URL to wrap
        Returns:
        The URLWrapper
      • of

        public static URLWrapper of​(java.net.URI uri)
        Create a new URLWrapper from an URI.
        Parameters:
        uri - The URI to wrap
        Returns:
        The URLWrapper
      • hasProtocol

        public boolean hasProtocol()
        Returns:
        If the protocol is set
      • getProtocol

        public java.lang.String getProtocol()
        Returns:
        The protocol of the URL (e.g. https)
      • getProtocolOr

        public java.lang.String getProtocolOr​(java.lang.String defaultProtocol)
        Parameters:
        defaultProtocol - The default protocol to return if none is set
        Returns:
        The protocol of the URL (e.g. https)
      • setProtocol

        public URLWrapper setProtocol​(java.lang.String protocol)
        Set the protocol of the URL (e.g. https).
        Parameters:
        protocol - The new protocol
        Returns:
        The URLWrapper
      • hasHost

        public boolean hasHost()
        Returns:
        If the host is set
      • getHost

        public java.lang.String getHost()
        Returns:
        The host of the URL (e.g. www.example.com)
      • getHostOr

        public java.lang.String getHostOr​(java.lang.String defaultHost)
        Parameters:
        defaultHost - The default host to return if none is set
        Returns:
        The host of the URL (e.g. www.example.com)
      • setHost

        public URLWrapper setHost​(java.lang.String host)
        Set the host of the URL (e.g. www.example.com).
        Parameters:
        host - The new host
        Returns:
        The URLWrapper
      • hasPort

        public boolean hasPort()
        Returns:
        If the port is set
      • getPort

        public int getPort()
        Returns:
        The port of the URL (e.g. 443)
      • getPortOr

        public int getPortOr​(int defaultPort)
        Parameters:
        defaultPort - The default port to return if none is set
        Returns:
        The port of the URL (e.g. 443)
      • setPort

        public URLWrapper setPort​(int port)
        Set the port of the URL (e.g. 443).
        Parameters:
        port - The new port
        Returns:
        The URLWrapper
      • hasPath

        public boolean hasPath()
        Returns:
        If the path is set
      • getPath

        public java.lang.String getPath()
        Returns:
        The path of the URL (e.g. /search)
      • getPathOr

        public java.lang.String getPathOr​(java.lang.String defaultPath)
        Parameters:
        defaultPath - The default path to return if none is set
        Returns:
        The path of the URL (e.g. /search)
      • setPath

        public URLWrapper setPath​(java.lang.String path)
        Set the path of the URL (e.g. /search).
        Parameters:
        path - The new path
        Returns:
        The URLWrapper
      • hasQuery

        public boolean hasQuery()
        Returns:
        If the query is set
      • getQuery

        public java.lang.String getQuery()
        Returns:
        The query of the URL (e.g. q=hello)
      • getQueryOr

        public java.lang.String getQueryOr​(java.lang.String defaultQuery)
        Parameters:
        defaultQuery - The default query to return if none is set
        Returns:
        The query of the URL (e.g. q=hello)
      • setQuery

        public URLWrapper setQuery​(java.lang.String query)
        Set the query of the URL (e.g. q=hello).
        Parameters:
        query - The new query
        Returns:
        The URLWrapper
      • wrapQuery

        @Deprecated
        @ScheduledForRemoval
        public URLWrapper.QueryWrapper wrapQuery()
        Deprecated.
        Get a wrapper for the query parameters.
        Returns:
        The query wrapper
      • hasUserInfo

        public boolean hasUserInfo()
        Returns:
        If the user info is set
      • getUserInfo

        public java.lang.String getUserInfo()
        Returns:
        The user info of the URL (e.g. user:password)
      • getUserInfoOr

        public java.lang.String getUserInfoOr​(java.lang.String defaultUserInfo)
        Parameters:
        defaultUserInfo - The default user info to return if none is set
        Returns:
        The user info of the URL (e.g. user:password)
      • setUserInfo

        public URLWrapper setUserInfo​(java.lang.String userInfo)
        Set the user info of the URL (e.g. user:password).
        Parameters:
        userInfo - The new user info
        Returns:
        The URLWrapper
      • hasFragment

        public boolean hasFragment()
        Returns:
        If the fragment is set
      • getFragment

        public java.lang.String getFragment()
        Returns:
        The fragment of the URL (e.g. fragment)
      • getFragmentOr

        public java.lang.String getFragmentOr​(java.lang.String defaultFragment)
        Parameters:
        defaultFragment - The default fragment to return if none is set
        Returns:
        The fragment of the URL (e.g. fragment)
      • setFragment

        public URLWrapper setFragment​(java.lang.String fragment)
        Set the fragment of the URL (e.g. fragment).
        Parameters:
        fragment - The new fragment
        Returns:
        The URLWrapper
      • getReference

        @Deprecated
        @ScheduledForRemoval
        public java.lang.String getReference()
        Deprecated.
        Deprecated, use getFragment() instead.
      • setReference

        @Deprecated
        @ScheduledForRemoval
        public URLWrapper setReference​(java.lang.String reference)
        Deprecated.
        Deprecated, use setFragment(String) instead.
      • toURL

        public java.net.URL toURL()
                           throws java.net.MalformedURLException
        Returns:
        The wrapped URL
        Throws:
        java.net.MalformedURLException - If the URL is invalid
      • toURI

        public java.net.URI toURI()
        Returns:
        The wrapped URI
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object