Class UrlBuilder


  • public final class UrlBuilder
    extends java.lang.Object
    A builder class that is used to create URLs.
    • Constructor Summary

      Constructors 
      Constructor Description
      UrlBuilder()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getHost()
      Get the host that has been assigned to this UrlBuilder.
      java.lang.String getPath()
      Get the path that has been assigned to this UrlBuilder.
      java.lang.Integer getPort()
      Get the port that has been assigned to this UrlBuilder.
      java.util.Map<java.lang.String,​java.lang.String> getQuery()
      Get the query that has been assigned to this UrlBuilder.
      java.lang.String getQueryString()
      Returns the query string currently configured in this UrlBuilder instance.
      java.lang.String getScheme()
      Get the scheme/protocol that has been assigned to this UrlBuilder.
      static UrlBuilder parse​(java.lang.String url)
      Parses the passed url string into a UrlBuilder.
      static UrlBuilder parse​(java.net.URL url)
      Parse a UrlBuilder from the provided URL object.
      UrlBuilder setHost​(java.lang.String host)
      Set the host that will be used to build the final URL.
      UrlBuilder setPath​(java.lang.String path)
      Set the path that will be used to build the final URL.
      UrlBuilder setPort​(int port)
      Set the port that will be used to build the final URL.
      UrlBuilder setPort​(java.lang.String port)
      Set the port that will be used to build the final URL.
      UrlBuilder setQuery​(java.lang.String query)
      Set the query that will be used to build the final URL.
      UrlBuilder setQueryParameter​(java.lang.String queryParameterName, java.lang.String queryParameterEncodedValue)
      Set the provided query parameter name and encoded value to query string for the final URL.
      UrlBuilder setScheme​(java.lang.String scheme)
      Set the scheme/protocol that will be used to build the final URL.
      java.lang.String toString()
      Get the string representation of the URL that is being built.
      java.net.URL toUrl()
      Get the URL that is being built.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • UrlBuilder

        public UrlBuilder()
    • Method Detail

      • setScheme

        public UrlBuilder setScheme​(java.lang.String scheme)
        Set the scheme/protocol that will be used to build the final URL.
        Parameters:
        scheme - The scheme/protocol that will be used to build the final URL.
        Returns:
        This UrlBuilder so that multiple setters can be chained together.
      • getScheme

        public java.lang.String getScheme()
        Get the scheme/protocol that has been assigned to this UrlBuilder.
        Returns:
        the scheme/protocol that has been assigned to this UrlBuilder.
      • setHost

        public UrlBuilder setHost​(java.lang.String host)
        Set the host that will be used to build the final URL.
        Parameters:
        host - The host that will be used to build the final URL.
        Returns:
        This UrlBuilder so that multiple setters can be chained together.
      • getHost

        public java.lang.String getHost()
        Get the host that has been assigned to this UrlBuilder.
        Returns:
        the host that has been assigned to this UrlBuilder.
      • setPort

        public UrlBuilder setPort​(java.lang.String port)
        Set the port that will be used to build the final URL.
        Parameters:
        port - The port that will be used to build the final URL.
        Returns:
        This UrlBuilder so that multiple setters can be chained together.
      • setPort

        public UrlBuilder setPort​(int port)
        Set the port that will be used to build the final URL.
        Parameters:
        port - The port that will be used to build the final URL.
        Returns:
        This UrlBuilder so that multiple setters can be chained together.
      • getPort

        public java.lang.Integer getPort()
        Get the port that has been assigned to this UrlBuilder.
        Returns:
        the port that has been assigned to this UrlBuilder.
      • setPath

        public UrlBuilder setPath​(java.lang.String path)
        Set the path that will be used to build the final URL.
        Parameters:
        path - The path that will be used to build the final URL.
        Returns:
        This UrlBuilder so that multiple setters can be chained together.
      • getPath

        public java.lang.String getPath()
        Get the path that has been assigned to this UrlBuilder.
        Returns:
        the path that has been assigned to this UrlBuilder.
      • setQueryParameter

        public UrlBuilder setQueryParameter​(java.lang.String queryParameterName,
                                            java.lang.String queryParameterEncodedValue)
        Set the provided query parameter name and encoded value to query string for the final URL.
        Parameters:
        queryParameterName - The name of the query parameter.
        queryParameterEncodedValue - The encoded value of the query parameter.
        Returns:
        The provided query parameter name and encoded value to query string for the final URL.
      • setQuery

        public UrlBuilder setQuery​(java.lang.String query)
        Set the query that will be used to build the final URL.
        Parameters:
        query - The query that will be used to build the final URL.
        Returns:
        This UrlBuilder so that multiple setters can be chained together.
      • getQuery

        public java.util.Map<java.lang.String,​java.lang.String> getQuery()
        Get the query that has been assigned to this UrlBuilder.
        Returns:
        the query that has been assigned to this UrlBuilder.
      • getQueryString

        public java.lang.String getQueryString()
        Returns the query string currently configured in this UrlBuilder instance.
        Returns:
        A String containing the currently configured query string.
      • toUrl

        public java.net.URL toUrl()
                           throws java.net.MalformedURLException
        Get the URL that is being built.
        Returns:
        The URL that is being built.
        Throws:
        java.net.MalformedURLException - if the URL is not fully formed.
      • toString

        public java.lang.String toString()
        Get the string representation of the URL that is being built.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation of the URL that is being built.
      • parse

        public static UrlBuilder parse​(java.lang.String url)
        Parses the passed url string into a UrlBuilder.
        Parameters:
        url - The URL string to parse.
        Returns:
        The UrlBuilder that was created from parsing the passed URL string.
      • parse

        public static UrlBuilder parse​(java.net.URL url)
        Parse a UrlBuilder from the provided URL object.
        Parameters:
        url - The URL object to parse.
        Returns:
        The UrlBuilder that was parsed from the URL object.