class URLBuilder {

    public URL build() {
        port = port < 0 ? 0 : port;
        // trim the leading "/"
        int firstNonSlash = 0;
        if (path != null) {
            while (firstNonSlash < path.length() && path.charAt(firstNonSlash) == '/') {
                firstNonSlash++;
            }
            if (firstNonSlash >= path.length()) {
                path = "";
            } else if (firstNonSlash > 0) {
                path = path.substring(firstNonSlash);
            }
        }
        if (CollectionUtils.isEmptyMap(methodParameters)) {
            return new URL(protocol, username, password, host, port, path, parameters);
        } else {
            return new URL(protocol, username, password, host, port, path, parameters, methodParameters);
        }
    }

    public  URLBuilder();
    public  URLBuilder(String protocol, String host, int port);
    public  URLBuilder(String protocol, String host, int port, String[] pairs);
    public  URLBuilder(String protocol, String host, int port, Map<String, String> parameters);
    public  URLBuilder(String protocol, String host, int port, String path);
    public  URLBuilder(String protocol, String host, int port, String path, String... pairs);
    public  URLBuilder(String protocol, String host, int port, String path, Map<String, String> parameters);
    public  URLBuilder(String protocol,
                      String username,
                      String password,
                      String host,
                      int port,
                      String path, Map<String, String> parameters);
    public  URLBuilder(String protocol,
                      String username,
                      String password,
                      String host,
                      int port,
                      String path, Map<String, String> parameters,
                      Map<String, Map<String, String>> methodParameters);

}