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

brooklyn.entity.basic.ConfigKeys Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.entity.basic;

import javax.annotation.Nonnull;

import brooklyn.config.ConfigKey;
import brooklyn.event.basic.BasicConfigKey;
import brooklyn.event.basic.BasicConfigKey.BasicConfigKeyOverwriting;

import com.google.common.base.CaseFormat;
import com.google.common.base.Preconditions;
import com.google.common.reflect.TypeToken;


/**
 * Dictionary of {@link ConfigKey} entries.
 */
public class ConfigKeys {

    public static  ConfigKey newConfigKey(Class type, String name) {
        return new BasicConfigKey(type, name);
    }

    public static  ConfigKey newConfigKey(Class type, String name, String description) {
        return new BasicConfigKey(type, name, description);
    }

    public static  ConfigKey newConfigKey(TypeToken type, String name) {
        return new BasicConfigKey(type, name);
    }

    public static  ConfigKey newConfigKey(TypeToken type, String name, String description) {
        return new BasicConfigKey(type, name, description);
    }

    public static  ConfigKey newConfigKey(Class type, String name, String description, T defaultValue) {
        return new BasicConfigKey(type, name, description, defaultValue);
    }

    public static  ConfigKey newConfigKey(TypeToken type, String name, String description, T defaultValue) {
        return new BasicConfigKey(type, name, description, defaultValue);
    }

    /** Infers the type from the default value */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  ConfigKey newConfigKey(String name, String description, @Nonnull T defaultValue) {
        return new BasicConfigKey((Class)Preconditions.checkNotNull(defaultValue, 
                "Type must be exlicit for ConfigKey if defaultValue is null").getClass(), 
                name, description, defaultValue);
    }

    public static  BasicConfigKey.Builder builder(Class type) {
        return BasicConfigKey.builder(type);
    }

    public static  BasicConfigKey.Builder builder(TypeToken type) {
        return BasicConfigKey.builder(type);
    }

    // ---- extensions to keys
    
    public static  ConfigKey newConfigKeyWithDefault(ConfigKey parent, T defaultValue) {
        return new BasicConfigKeyOverwriting(parent, defaultValue);
    }

    public static  ConfigKey newConfigKeyRenamed(String newName, ConfigKey key) {
        return new BasicConfigKey(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue());
    }

    public static  ConfigKey newConfigKeyWithPrefix(String prefix, ConfigKey key) {
        return newConfigKeyRenamed(prefix+key.getName(), key);
    }

    /** converts the name of the key from one case-strategy (e.g. lowerCamel) to andother (e.g. lower-hyphen) */
    public static  ConfigKey convert(ConfigKey key, CaseFormat inputCaseStrategy, CaseFormat outputCaseStrategy) {
        return newConfigKeyRenamed(inputCaseStrategy.to(outputCaseStrategy, key.getName()), key);
    }

    // ---- typed keys

    public static ConfigKey newStringConfigKey(String name) {
        return newConfigKey(String.class, name);
    }

    public static ConfigKey newStringConfigKey(String name, String description) {
        return newConfigKey(String.class, name, description);
    }
    
    public static ConfigKey newStringConfigKey(String name, String description, String defaultValue) {
        return newConfigKey(String.class, name, description, defaultValue);
    }
    
    public static ConfigKey newIntegerConfigKey(String name) {
        return newConfigKey(Integer.class, name);
    }

    public static ConfigKey newIntegerConfigKey(String name, String description) {
        return newConfigKey(Integer.class, name, description);
    }
    
    public static ConfigKey newIntegerConfigKey(String name, String description, Integer defaultValue) {
        return newConfigKey(Integer.class, name, description, defaultValue);
    }
    
    public static ConfigKey newLongConfigKey(String name) {
        return newConfigKey(Long.class, name);
    }

    public static ConfigKey newLongConfigKey(String name, String description) {
        return newConfigKey(Long.class, name, description);
    }
    
    public static ConfigKey newLongConfigKey(String name, String description, Long defaultValue) {
        return newConfigKey(Long.class, name, description, defaultValue);
    }
    
    public static ConfigKey newDoubleConfigKey(String name) {
        return newConfigKey(Double.class, name);
    }

    public static ConfigKey newDoubleConfigKey(String name, String description) {
        return newConfigKey(Double.class, name, description);
    }
    
    public static ConfigKey newDoubleConfigKey(String name, String description, Double defaultValue) {
        return newConfigKey(Double.class, name, description, defaultValue);
    }
    
    public static ConfigKey newBooleanConfigKey(String name) {
        return newConfigKey(Boolean.class, name);
    }

    public static ConfigKey newBooleanConfigKey(String name, String description) {
        return newConfigKey(Boolean.class, name, description);
    }
    
    public static ConfigKey newBooleanConfigKey(String name, String description, Boolean defaultValue) {
        return newConfigKey(Boolean.class, name, description, defaultValue);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy