com.maryanovsky.gwtutils.client.net
Class UrlBuilder

java.lang.Object
  extended by com.maryanovsky.gwtutils.client.net.UrlBuilder

public final class UrlBuilder
extends Object

Constructs a URL from a base URL and parameters.

Author:
Maryanovsky Alexander

Constructor Summary
UrlBuilder(String baseUrl)
          Creates a new UrlBuilder with the specified base URL.
UrlBuilder(UrlBuilder urlBuilder)
          Creates a copy of the specified UrlBuilder.
 
Method Summary
 UrlBuilder addParam(String name, double value)
          Adds the specified double parameter to the URL.
 UrlBuilder addParam(String name, int value)
          Adds the specified integer parameter to the URL.
 UrlBuilder addParam(String name, Object value)
          Adds the specified parameter to the URL.
 UrlBuilder addParams(Map<String,? extends Object> parameters)
          Adds all the specified parameters to the URL.
 String getUrl()
          Returns the built URL.
 String toString()
          Returns the URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UrlBuilder

public UrlBuilder(String baseUrl)
Creates a new UrlBuilder with the specified base URL.


UrlBuilder

public UrlBuilder(UrlBuilder urlBuilder)
Creates a copy of the specified UrlBuilder. This is useful if you will be creating many URLs which share some of the parameters.

Method Detail

addParam

public UrlBuilder addParam(String name,
                           Object value)
Adds the specified parameter to the URL.

Parameters:
name - The name of the URL parameter. May not be null or an empty string.
value - The value of the URL parameter. Converted to a String by invoking toString on it. May be null, in which case only the parameter name is appended (no "=" is appended).
Returns:
this

addParam

public UrlBuilder addParam(String name,
                           int value)
Adds the specified integer parameter to the URL.

Parameters:
name - The name of the URL parameter. May not be null or an empty string.
value - The value of the URL parameter. Converted to a String via String.valueOf(int).
Returns:
this

addParam

public UrlBuilder addParam(String name,
                           double value)
Adds the specified double parameter to the URL.

Parameters:
name - The name of the URL parameter. May not be null or an empty string.
value - The value of the URL parameter. Converted to a String via String.valueOf(double).
Returns:
this

addParams

public UrlBuilder addParams(Map<String,? extends Object> parameters)
Adds all the specified parameters to the URL.

Parameters:
parameters - A map from parameter names to parameter values.

getUrl

public String getUrl()
Returns the built URL.


toString

public String toString()
Returns the URL.

Overrides:
toString in class Object