use of com.typesafe.config.ConfigValue in project config by typesafehub.
the class SimpleConfig method getBytesList.
@Override
public List<Long> getBytesList(String path) {
List<Long> l = new ArrayList<Long>();
List<? extends ConfigValue> list = getList(path);
for (ConfigValue v : list) {
if (v.valueType() == ConfigValueType.NUMBER) {
l.add(((Number) v.unwrapped()).longValue());
} else if (v.valueType() == ConfigValueType.STRING) {
String s = (String) v.unwrapped();
Long n = parseBytes(s, v.origin(), path);
l.add(n);
} else {
throw new ConfigException.WrongType(v.origin(), path, "memory size string or number of bytes", v.valueType().name());
}
}
return l;
}
use of com.typesafe.config.ConfigValue in project archaius by Netflix.
the class TypesafeConfigurationSource method load.
synchronized Map<String, Object> load() throws Exception {
Config config = config();
Map<String, Object> map = new HashMap<String, Object>();
for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue().unwrapped();
if (value instanceof List) {
if (false == safeArrayKeyExpansion(config, key)) {
log.error("Unable to expand array: {}", key);
continue;
}
List values = (List) value;
map.put(lengthKey(key), values.size());
for (int i = 0; i < values.size(); i++) {
map.put(indexedKey(key, i), values.get(i));
}
} else {
map.put(key, value);
}
}
return map;
}
use of com.typesafe.config.ConfigValue in project apollo by spotify.
the class ConfigFilter method filterConfigObject.
static ConfigObject filterConfigObject(ConfigObject config, Set<String> filter) {
ConfigObject result = config;
for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
String key = entry.getKey();
final ConfigValue filteredValue;
if (!isFiltered(key, filter)) {
final ConfigValue value = entry.getValue();
if (!"_meta".equals(key) && value.valueType() == ConfigValueType.OBJECT) {
filteredValue = filterConfigObject((ConfigObject) value, filter);
} else {
filteredValue = value;
}
} else {
filteredValue = fromAnyRef("*******", "filtered by config-filter settings");
}
result = result.withValue(key, filteredValue);
}
return result;
}
use of com.typesafe.config.ConfigValue in project play2-elasticsearch by cleverage.
the class IndexConfig method loadMappingFromConfig.
/**
* Load additional mappings from config entry "elasticsearch.index.mapping"
* @param indexName
*/
private void loadMappingFromConfig(String indexName) {
Configuration mappingConfig = (configuration.getConfig("elasticsearch." + indexName + ".mappings") == Option.apply((Configuration) null)) ? null : configuration.getConfig("elasticsearch." + indexName + ".mappings").get();
if (mappingConfig != null) {
Iterator<Tuple2<String, ConfigValue>> iter = mappingConfig.entrySet().iterator();
while (iter.hasNext()) {
Tuple2<String, ConfigValue> mapping = iter.next();
String indexType = mapping._1();
IndexQueryPath indexQueryPath = new IndexQueryPath(indexName, indexType);
if (mapping._2().unwrapped() instanceof String) {
indexMappings.put(indexQueryPath, (String) mapping._2().unwrapped());
} else {
try {
indexMappings.put(indexQueryPath, Json.toJson(mapping._2().unwrapped()).toString());
} catch (Exception e) {
Logger.warn("Incorrect value in elasticsearch.index.mappings", e);
}
}
}
}
}
use of com.typesafe.config.ConfigValue 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;
}
Aggregations