本文整理汇总了Java中com.typesafe.config.ConfigValueType类的典型用法代码示例。如果您正苦于以下问题:Java ConfigValueType类的具体用法?Java ConfigValueType怎么用?Java ConfigValueType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigValueType类属于com.typesafe.config包,在下文中一共展示了ConfigValueType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KeyValue
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
KeyValue(Map.Entry<String, ConfigValue> keyValue) {
key = keyValue.getKey();
description = createDescription(keyValue.getValue());
try {
if (keyValue.getValue().valueType() == ConfigValueType.NULL) {
valueType = "N/A (null)";
defaultValue = "null";
} else {
valueType = keyValue.getValue().valueType().name().toLowerCase();
defaultValue = render(keyValue.getValue());
}
} catch (ConfigException.NotResolved e) {
valueType = "N/A (unresolved)";
defaultValue = keyValue.getValue().render();
}
}
示例2: testNestedObject
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
@Test
public void testNestedObject() throws Exception {
final String JSON = "{\"array\":[1,2],\"obj\":{\"first\":true}}";
ConfigObject value = MAPPER.readValue(JSON, ConfigObject.class);
assertEquals(ConfigValueType.OBJECT, value.valueType());
assertEquals(2, value.size());
ConfigList array = (ConfigList) value.get("array");
assertEquals(ConfigValueType.LIST, array.valueType());
assertEquals(2, (array.unwrapped().size()));
ConfigValue objValue = value.get("obj");
assertEquals(ConfigValueType.OBJECT, objValue.valueType());
ConfigObject obj = (ConfigObject) objValue;
assertEquals(1, (obj.size()));
}
示例3: init
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
/**
* Initializes the configuration class by loading the configuration file.
* @param conf overrides the default configuration
*/
public static void init(com.typesafe.config.Config conf) {
try {
config = ConfigFactory.load().getConfig(PARA);
if (conf != null) {
config = conf.withFallback(config);
}
configMap = new HashMap<>();
for (Map.Entry<String, ConfigValue> con : config.entrySet()) {
if (con.getValue().valueType() != ConfigValueType.LIST) {
configMap.put(con.getKey(), config.getString(con.getKey()));
}
}
} catch (Exception ex) {
logger.warn("Para configuration file 'application.(conf|json|properties)' is missing from classpath.");
config = com.typesafe.config.ConfigFactory.empty();
}
}
示例4: parseFromConfig
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
/**
* Parse a play configuration.
*
* @param config play configuration
* @return ebean parsed configuration
* @see com.typesafe.config.Config
*/
public static EbeanParsedConfig parseFromConfig(Config config) {
Config playEbeanConfig = config.getConfig("play.ebean");
String defaultDatasource = playEbeanConfig.getString("defaultDatasource");
String ebeanConfigKey = playEbeanConfig.getString("config");
Map<String, List<String>> datasourceModels = new HashMap<>();
if (config.hasPath(ebeanConfigKey)) {
Config ebeanConfig = config.getConfig(ebeanConfigKey);
ebeanConfig.root().forEach((key, raw) -> {
List<String> models;
if (raw.valueType() == ConfigValueType.STRING) {
// Support legacy comma separated string
models = Arrays.asList(((String) raw.unwrapped()).split(","));
} else {
models = ebeanConfig.getStringList(key);
}
datasourceModels.put(key, models);
});
}
return new EbeanParsedConfig(defaultDatasource, datasourceModels);
}
示例5: expandSugar
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
public static ConfigValue expandSugar(Class<?> type, ConfigValue config,
PluginRegistry pluginRegistry) {
if ((type != null) && type.isAssignableFrom(ConfigValue.class)) {
return ConfigValueFactory.fromAnyRef(config.unwrapped(),
"unchanged for raw ConfigValue field "
+ config.origin().description());
}
CodableClassInfo typeInfo = new CodableClassInfo(type, pluginRegistry.config(), pluginRegistry);
PluginMap pluginMap = typeInfo.getPluginMap();
ConfigValue valueOrResolvedRoot = resolveType(type, config, pluginMap);
if (valueOrResolvedRoot.valueType() != ConfigValueType.OBJECT) {
return valueOrResolvedRoot;
}
ConfigObject root = (ConfigObject) valueOrResolvedRoot;
String classField = pluginMap.classField();
if (root.get(classField) != null) {
try {
type = pluginMap.getClass((String) root.get(classField).unwrapped());
} catch (ClassNotFoundException ignored) {
// try not to throw exceptions or at least checked exceptions from this helper method
}
}
return expandSugarSkipResolve(type, root, pluginRegistry);
}
示例6: currentNumericNode
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
protected JsonNode currentNumericNode() throws JsonParseException {
ConfigValue configValue = currentNode();
if ((configValue == null) || (configValue.valueType() != ConfigValueType.NUMBER)) {
JsonToken t = (configValue == null) ? null : ConfigNodeCursor.forConfigValue(configValue);
throw _constructError("Current token ("+t+") not numeric, can not use numeric value accessors");
}
Number value = (Number) configValue.unwrapped();
if (value instanceof Double) {
return JsonNodeFactory.instance.numberNode((Double) value);
}
if (value instanceof Long) {
return JsonNodeFactory.instance.numberNode((Long) value);
}
if (value instanceof Integer) {
return JsonNodeFactory.instance.numberNode((Integer) value);
}
// only possible if Config has since added more numeric types
throw _constructError(value.getClass() + " is not a supported numeric config type");
}
示例7: HoconTreeTraversingParser
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
public HoconTreeTraversingParser(ConfigObject n, ObjectCodec codec)
{
super(0);
_rootObject = n;
_objectCodec = codec;
if (n.valueType() == ConfigValueType.LIST) {
_nextToken = JsonToken.START_ARRAY;
_nodeCursor = new HoconNodeCursor.Array(n, null);
} else if (n.valueType() == ConfigValueType.OBJECT) {
if (HoconNodeCursor.isNumericallyIndexed(n)) {
_nextToken = JsonToken.START_ARRAY;
_nodeCursor = new HoconNodeCursor.NumericallyIndexedObjectBackedArray(n, null);
} else {
_nextToken = JsonToken.START_OBJECT;
_nodeCursor = new HoconNodeCursor.Object(n, null);
}
} else { // value node
_nodeCursor = new HoconNodeCursor.RootValue(n, null);
}
}
示例8: render
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
private static String render(ConfigValue value) {
String result;
if (value.valueType().equals(ConfigValueType.LIST)) {
result = "[" +
((ConfigList) value).stream()
.map(KeyValue::render)
.collect(Collectors.joining(", ")) +
"]";
} else if (value.valueType().equals(ConfigValueType.STRING)) {
result = '"' + value.unwrapped().toString() + '"';
} else {
result = value.unwrapped().toString();
}
return result;
}
示例9: nullValues
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
private static Set<Map.Entry<String, ConfigValue>> nullValues(ConfigObject config) {
Set<Map.Entry<String, ConfigValue>> result = new HashSet<>();
for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
try {
if (entry.getValue().valueType() == ConfigValueType.NULL) {
result.add(entry);
} else if (entry.getValue().valueType() == ConfigValueType.OBJECT) {
result.addAll(nullValues((ConfigObject) entry.getValue()));
}
} catch (ConfigException.NotResolved e) {
// unresolved substitutions are handled elsewhere, here we just ignore them
}
}
return result;
}
示例10: testSimpleArray
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
@Test
public void testSimpleArray() throws Exception {
final String JSON = "[1,true,\"foo\"]";
ConfigList value = MAPPER.readValue(JSON, ConfigList.class);
assertEquals(ConfigValueType.LIST, value.valueType());
assertEquals(3, value.size());
assertEquals(ConfigValueType.NUMBER, value.get(0).valueType());
assertEquals(true, value.get(1).unwrapped());
assertEquals(ConfigValueType.STRING, value.get(2).valueType());
}
示例11: testNestedArray
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
@Test
public void testNestedArray() throws Exception {
final String JSON = "[1,[false,45],{\"foo\":13}]";
ConfigList value = MAPPER.readValue(JSON, ConfigList.class);
assertEquals(ConfigValueType.LIST, value.valueType());
assertEquals(3, value.size());
assertEquals(ConfigValueType.NUMBER, value.get(0).valueType());
assertEquals(ConfigValueType.LIST, value.get(1).valueType());
assertEquals(ConfigValueType.OBJECT, value.get(2).valueType());
}
示例12: testSimpleObject
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
@Test
public void testSimpleObject() throws Exception {
final String JSON = "{\"a\":12.5,\"b\":\"Text\"}";
ConfigObject value = MAPPER.readValue(JSON, ConfigObject.class);
assertEquals(ConfigValueType.OBJECT, value.valueType());
assertEquals(2, value.size());
assertEquals(ConfigValueType.NUMBER, value.get("a").valueType());
assertEquals(12.5, value.get("a").unwrapped());
assertEquals(ConfigValueType.STRING, value.get("b").valueType());
assertEquals("Text", value.get("b").unwrapped());
}
示例13: getValueTypeOrNull
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
private static ConfigValueType getValueTypeOrNull(Class<?> parameterClass) {
if (parameterClass == Boolean.class || parameterClass == boolean.class) {
return ConfigValueType.BOOLEAN;
} else if (parameterClass == Integer.class || parameterClass == int.class) {
return ConfigValueType.NUMBER;
} else if (parameterClass == Double.class || parameterClass == double.class) {
return ConfigValueType.NUMBER;
} else if (parameterClass == Long.class || parameterClass == long.class) {
return ConfigValueType.NUMBER;
} else if (parameterClass == String.class) {
return ConfigValueType.STRING;
} else if (parameterClass == Duration.class) {
return null;
} else if (parameterClass == ConfigMemorySize.class) {
return null;
} else if (parameterClass == List.class) {
return ConfigValueType.LIST;
} else if (parameterClass == Map.class) {
return ConfigValueType.OBJECT;
} else if (parameterClass == Config.class) {
return ConfigValueType.OBJECT;
} else if (parameterClass == ConfigObject.class) {
return ConfigValueType.OBJECT;
} else if (parameterClass == ConfigList.class) {
return ConfigValueType.LIST;
} else {
return null;
}
}
示例14: initializeUDFs
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
private static void initializeUDFs(Config config) {
if (!config.hasPath("udfs")) return;
if (!config.getValue("udfs").valueType().equals(ConfigValueType.LIST)) {
throw new RuntimeException("UDFs must be provided as a list");
}
ConfigList udfList = config.getList("udfs");
for (ConfigValue udfValue : udfList) {
ConfigValueType udfValueType = udfValue.valueType();
if (!udfValueType.equals(ConfigValueType.OBJECT)) {
throw new RuntimeException("UDF list must contain UDF objects");
}
Config udfConfig = ((ConfigObject)udfValue).toConfig();
for (String path : Lists.newArrayList("name", "class")) {
if (!udfConfig.hasPath(path)) {
throw new RuntimeException("UDF entries must provide '" + path + "'");
}
}
String name = udfConfig.getString("name");
String className = udfConfig.getString("class");
// null third argument means that registerJava will infer the return type
Contexts.getSparkSession().udf().registerJava(name, className, null);
LOG.info("Registered Spark SQL UDF: " + name);
}
}
示例15: getArgumentDescriptions
import com.typesafe.config.ConfigValueType; //导入依赖的package包/类
public static void getArgumentDescriptions(Map<String, String> argumentDescriptions, Config config, AbstractV1Method method) {
if (config.hasPath("arguments")) {
config.getConfig("arguments").entrySet().forEach(entry -> {
if (entry.getValue().valueType() != ConfigValueType.STRING) {
throw new IllegalArgumentException("Description for argument at path " + entry.getKey() + " for method " + method.getDeclaration() + " must be a string");
}
argumentDescriptions.put(entry.getKey(), (String) entry.getValue().unwrapped());
});
}
}