Search in sources :

Example 1 with ConfigList

use of com.typesafe.config.ConfigList in project config by typesafehub.

the class SerializedConfigValue method writeValueData.

private static void writeValueData(DataOutput out, ConfigValue value) throws IOException {
    SerializedValueType st = SerializedValueType.forValue(value);
    out.writeByte(st.ordinal());
    switch(st) {
        case BOOLEAN:
            out.writeBoolean(((ConfigBoolean) value).unwrapped());
            break;
        case NULL:
            break;
        case INT:
            // saving numbers as both string and binary is redundant but easy
            out.writeInt(((ConfigInt) value).unwrapped());
            out.writeUTF(((ConfigNumber) value).transformToString());
            break;
        case LONG:
            out.writeLong(((ConfigLong) value).unwrapped());
            out.writeUTF(((ConfigNumber) value).transformToString());
            break;
        case DOUBLE:
            out.writeDouble(((ConfigDouble) value).unwrapped());
            out.writeUTF(((ConfigNumber) value).transformToString());
            break;
        case STRING:
            out.writeUTF(((ConfigString) value).unwrapped());
            break;
        case LIST:
            ConfigList list = (ConfigList) value;
            out.writeInt(list.size());
            for (ConfigValue v : list) {
                writeValue(out, v, (SimpleConfigOrigin) list.origin());
            }
            break;
        case OBJECT:
            ConfigObject obj = (ConfigObject) value;
            out.writeInt(obj.size());
            for (Map.Entry<String, ConfigValue> e : obj.entrySet()) {
                out.writeUTF(e.getKey());
                writeValue(out, e.getValue(), (SimpleConfigOrigin) obj.origin());
            }
            break;
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ConfigObject(com.typesafe.config.ConfigObject) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map) ConfigList(com.typesafe.config.ConfigList)

Example 2 with ConfigList

use of com.typesafe.config.ConfigList in project config by typesafehub.

the class ConfigBeanImpl method getListValue.

private static Object getListValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config, String configPropName) {
    Type elementType = ((ParameterizedType) parameterType).getActualTypeArguments()[0];
    if (elementType == Boolean.class) {
        return config.getBooleanList(configPropName);
    } else if (elementType == Integer.class) {
        return config.getIntList(configPropName);
    } else if (elementType == Double.class) {
        return config.getDoubleList(configPropName);
    } else if (elementType == Long.class) {
        return config.getLongList(configPropName);
    } else if (elementType == String.class) {
        return config.getStringList(configPropName);
    } else if (elementType == Duration.class) {
        return config.getDurationList(configPropName);
    } else if (elementType == ConfigMemorySize.class) {
        return config.getMemorySizeList(configPropName);
    } else if (elementType == Object.class) {
        return config.getAnyRefList(configPropName);
    } else if (elementType == Config.class) {
        return config.getConfigList(configPropName);
    } else if (elementType == ConfigObject.class) {
        return config.getObjectList(configPropName);
    } else if (elementType == ConfigValue.class) {
        return config.getList(configPropName);
    } else if (((Class<?>) elementType).isEnum()) {
        @SuppressWarnings("unchecked") List<Enum> enumValues = config.getEnumList((Class<Enum>) elementType, configPropName);
        return enumValues;
    } else if (hasAtLeastOneBeanProperty((Class<?>) elementType)) {
        List<Object> beanList = new ArrayList<Object>();
        List<? extends Config> configList = config.getConfigList(configPropName);
        for (Config listMember : configList) {
            beanList.add(createInternal(listMember, (Class<?>) elementType));
        }
        return beanList;
    } else {
        throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported list element type " + elementType);
    }
}
Also used : Config(com.typesafe.config.Config) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ConfigValueType(com.typesafe.config.ConfigValueType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ConfigObject(com.typesafe.config.ConfigObject) ConfigList(com.typesafe.config.ConfigList) ArrayList(java.util.ArrayList) List(java.util.List) ConfigObject(com.typesafe.config.ConfigObject)

Example 3 with ConfigList

use of com.typesafe.config.ConfigList in project helios by spotify.

the class TemporaryJobs method getListByKey.

private static List<String> getListByKey(final String key, final Config config) {
    final ConfigList endpointList = config.getList(key);
    final List<String> stringList = Lists.newArrayList();
    for (final ConfigValue v : endpointList) {
        if (v.valueType() != ConfigValueType.STRING) {
            throw new RuntimeException("Item in " + key + " list [" + v + "] is not a string");
        }
        stringList.add((String) v.unwrapped());
    }
    return stringList;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ConfigList(com.typesafe.config.ConfigList)

Aggregations

ConfigList (com.typesafe.config.ConfigList)3 ConfigObject (com.typesafe.config.ConfigObject)2 ConfigValue (com.typesafe.config.ConfigValue)2 Config (com.typesafe.config.Config)1 ConfigValueType (com.typesafe.config.ConfigValueType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1