package io.sidecar.client;

import static com.google.common.base.Throwables.propagate;

import java.net.MalformedURLException;
import java.net.URL;

public final class ClientConfig {

    final private URL restApiBasePath;

    public ClientConfig() {
        this(new Builder());
    }

    private ClientConfig(Builder bd) {
        restApiBasePath = getOrDefault(bd.restApiBasePath, "http://localhost:8080/rest-api");
    }

    private URL getOrDefault(URL builderUrl, String defaultUrl) {
        try {
            return (builderUrl != null) ? builderUrl : new URL(defaultUrl);
        } catch (MalformedURLException e) {
            throw propagate(e);
        }
    }

    public URL getRestApiBasePath() {
        return restApiBasePath;
    }

    public static final class Builder {

        private URL restApiBasePath;

        public ClientConfig build() {
            return new ClientConfig(this);
        }

        public Builder withRestApiBasePath(URL basePath) {
            this.restApiBasePath = basePath;
            return this;
        }
    }
}

package io.sidecar.client;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.propagate;

import java.net.URL;

public final class ClientConfig {

    final private URL restApiBasePath;

    public ClientConfig() {
        this(urlFromString("http://localhost:8080/rest-api"));
    }

    public ClientConfig(URL baseUrl) {
        this.restApiBasePath = checkNotNull(baseUrl);
    }

    public URL getRestApiBasePath() {
        return restApiBasePath;
    }

    private static URL urlFromString(String s) {
        try {
            return new URL(s);
        } catch (Exception e) {
            throw propagate(e);
        }
    }
}

remove unnecessary builder from ClientConfig