All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cocaine.ServiceApi Maven / Gradle / Ivy

There is a newer version: 0.11.1.0
Show newest version
package cocaine;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;

/**
 * @author Anton Bobukh 
 */
public class ServiceApi {

    private final String name;
    private final ImmutableMap api;

    public ServiceApi(String name, ImmutableMap api) {
        this.name = name;
        this.api = api;
    }

    public static ServiceApi of(String name, String method, int id) {
        return new ServiceApi(name, ImmutableMap.of(method, id));
    }

    public static ServiceApi of(String name, ImmutableMap methods) {
        return new ServiceApi(name, methods);
    }

    public int getMethod(String method) {
        Integer number = api.get(method);
        if (number == null) {
            throw new UnknownMethodException(name, method);
        }
        return number;
    }

    @Override
    public String toString() {
        return "Service: " + name + "; Service API: { "
                + Joiner.on(", ").withKeyValueSeparator(": ").join(api) + " }";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy