当前位置: 首页>>代码示例>>Java>>正文


Java ConfigValue.valueType方法代码示例

本文整理汇总了Java中com.typesafe.config.ConfigValue.valueType方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigValue.valueType方法的具体用法?Java ConfigValue.valueType怎么用?Java ConfigValue.valueType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.typesafe.config.ConfigValue的用法示例。


在下文中一共展示了ConfigValue.valueType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CustomTagMappings

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
/**
 * Creates a new custom tag mappings object from the given configuration. The keys of the
 * configuration are well-known tag names, and the values are the custom tag names.
 *
 * @param config config holding custom tags
 * @throws IllegalArgumentException if any configuration value is not a string or is empty
 */
public CustomTagMappings(Config config) {
  ImmutableMap.Builder<String, String> b = ImmutableMap.builder();

  if (config != null) {
    for (Map.Entry<String,ConfigValue> e : config.entrySet()) {
      String key = e.getKey();
      ConfigValue value = e.getValue();
      switch (value.valueType()) {
        case STRING:
          String customTagName = (String) value.unwrapped();
          if (customTagName.isEmpty()) {
            throw new IllegalArgumentException("Tag mapping " + key + " is empty");
          }
          b.put(key, customTagName);
          break;
        default:
          throw new IllegalArgumentException("Tag mapping " + key + " is not a string: " + value);
      }
    }
  }

  customTagNames = b.build();
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:31,代码来源:CustomTagMappings.java

示例2: AWSTimeouts

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
/**
 * Creates a new timeouts object from the given configuration. It is
 * expected that every value in the recursive tree of the configuration is
 * numeric. Each (recursive) key in the config serves as the key for a
 * timeout.
 *
 * @param config config holding timeouts
 * @throws IllegalArgumentException if any configuration value is non-numeric
 */
public AWSTimeouts(Config config) {
  ImmutableMap.Builder<String, Long> b = ImmutableMap.builder();

  if (config != null) {
    for (Map.Entry<String,ConfigValue> e : config.entrySet()) {
      String key = e.getKey();
      ConfigValue value = e.getValue();
      switch (value.valueType()) {
        case NUMBER:
          long num =((Number) value.unwrapped()).longValue();
          if (num <= 0L) {
            throw new IllegalArgumentException("Timeout " + key + " is negative: " + value);
          }
          b.put(key, num);
          break;
        default:
          throw new IllegalArgumentException("Timeout " + key + " is not a number: " + value);
      }
    }
  }

  timeouts = b.build();
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:33,代码来源:AWSTimeouts.java

示例3: readConfigValue

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
private void readConfigValue(ConfigValue value, CommentedConfigurationNode node) {
    if (!value.origin().comments().isEmpty()) {
        node.setComment(CRLF_MATCH.matcher(Joiner.on('\n').join(value.origin().comments())).replaceAll(""));
    }
    switch (value.valueType()) {
        case OBJECT:
            if (((ConfigObject) value).isEmpty()) {
                node.setValue(ImmutableMap.of());
            } else {
                for (Map.Entry<String, ConfigValue> ent : ((ConfigObject) value).entrySet()) {
                    readConfigValue(ent.getValue(), node.getNode(ent.getKey()));
                }
            }
            break;
        case LIST:
            List<ConfigValue> values = (ConfigList) value;
            for (int i = 0; i < values.size(); ++i) {
                readConfigValue(values.get(i), node.getNode(i));
            }
            break;
        case NULL:
            return;
        default:
            node.setValue(value.unwrapped());
    }
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:27,代码来源:HoconConfigurationLoader.java

示例4: parseJson

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
void parseJson(String jsonString, LogRecord logRecord) {
  String cleanedJsonString = IngestUtilities.removeUnprintableCharacters(jsonString);
  Config cfg = ConfigFactory.parseString(cleanedJsonString);
  for (Map.Entry<String, ConfigValue> entry : cfg.entrySet()) {
    String key = entry.getKey();
    ConfigValue value = entry.getValue();
    switch (value.valueType()) {
      case BOOLEAN:
      case NUMBER:
      case OBJECT:
      case STRING:
        logRecord.setValue(key, ObjectUtils.toString(value.unwrapped()));
        break;
      case LIST:
        ConfigList list = (ConfigList) value;
        Gson gson = new Gson();
        String json = gson.toJson(list.unwrapped());
        logRecord.setValue(key, json);
        break;
      case NULL:
      default:
        // skip
    }
  }
}
 
开发者ID:boozallen,项目名称:cognition,代码行数:26,代码来源:FlattenJsonBolt.java

示例5: checkValue

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
private Object checkValue(String k, ConfigValue value, ConfigPropertyType<?> t) {
    Object v = value.unwrapped();
    switch (value.valueType()) {
        case STRING:
            // allow auto-conversion from string
            return t.check(k, value.unwrapped(), value.origin());
        case NUMBER:
            if (t.getBaseType() != ConfigPropertyType.INT && t.getBaseType() != ConfigPropertyType.FLOAT) {
                throw invalidValue(value, k, v, t.getBaseType());
            }
            if (t.getBaseType() == ConfigPropertyType.INT) {
                Number n = (Number) value.unwrapped();
                if (n.intValue() != n.doubleValue()) {
                    throw invalidValue(value, k, v, t.getBaseType());
                }
            }
            return t.check(k, v, null);
        case BOOLEAN:
            if (t.getBaseType() != ConfigPropertyType.BOOLEAN) {
                throw invalidValue(value, k, v, t.getBaseType());
            }
            return value.unwrapped();
        default:
            return t.check(k, v, value.origin());
    }
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:27,代码来源:SwiftConfigSchema.java

示例6: expandSugar

import com.typesafe.config.ConfigValue; //导入方法依赖的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);
}
 
开发者ID:addthis,项目名称:codec,代码行数:25,代码来源:Configs.java

示例7: currentNumericNode

import com.typesafe.config.ConfigValue; //导入方法依赖的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");
}
 
开发者ID:addthis,项目名称:codec,代码行数:20,代码来源:ConfigTraversingParser.java

示例8: parse

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
@Override
protected Map<String, String> parse(ResourceObject file) throws IOException,
		ResourceObjectException {
	Config config = file.parsedTo(parser).asIs();

	Map<String, String> result = new HashMap<String, String>();
	Set<Entry<String, ConfigValue>> entrySet = config.entrySet();
	for (Entry<String, ConfigValue> entry : entrySet) {
		ConfigValue value = entry.getValue();
		switch (value.valueType()) {
		case BOOLEAN:
		case NUMBER:
		case STRING:
			result.put(entry.getKey(), String.valueOf(value.unwrapped()));
			break;
		default:
			result.put(entry.getKey(), value.render());
		}

	}
	return result;
}
 
开发者ID:resource4j,项目名称:resource4j,代码行数:23,代码来源:ConfigMapParser.java

示例9: InputConfiguration

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
public InputConfiguration(String id, Config config) {
    this.id = id;

    if (config.hasPath("outputs")) {
        this.outputs = Sets.newHashSet(Splitter.on(",").omitEmptyStrings().trimResults().split(config.getString("outputs")));
    }

    if (config.hasPath("message-fields")) {
        final Config messageFieldsConfig = config.getConfig("message-fields");

        for (Map.Entry<String, ConfigValue> entry : messageFieldsConfig.entrySet()) {
            final String key = entry.getKey();
            final ConfigValue value = entry.getValue();

            switch (value.valueType()) {
                case NUMBER:
                    this.messageFields.put(key, messageFieldsConfig.getNumber(key));
                    break;
                case BOOLEAN:
                    this.messageFields.put(key, messageFieldsConfig.getBoolean(key));
                    break;
                case STRING:
                    this.messageFields.put(key, messageFieldsConfig.getString(key));
                    break;
                default:
                    log.warn("{}[{}] Message field value of type \"{}\" is not supported for key \"{}\" (value: {})",
                            getClass().getSimpleName(), getId(), value.valueType(), key, value.toString());
                    break;
            }
        }
    }
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:33,代码来源:InputConfiguration.java

示例10: next

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
@Override
public OptionValue next() {
  final Entry<String, ConfigValue> e = entries.next();
  final ConfigValue cv = e.getValue();
  final String name = e.getKey();
  OptionValue optionValue = null;
  switch(cv.valueType()) {
  case BOOLEAN:
    optionValue = OptionValue.createBoolean(OptionType.BOOT, name, (Boolean) cv.unwrapped());
    break;

  case LIST:
  case OBJECT:
  case STRING:
    optionValue = OptionValue.createString(OptionType.BOOT, name, cv.render());
    break;

  case NUMBER:
    optionValue = OptionValue.createLong(OptionType.BOOT, name, ((Number) cv.unwrapped()).longValue());
    break;

  case NULL:
    throw new IllegalStateException("Config value \"" + name + "\" has NULL type");
  }

  return optionValue;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:28,代码来源:DrillConfigIterator.java

示例11: print2

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
public static void print2(String s, ConfigValue configValue, String p, int level) {
    int l = level + 1;
    switch (configValue.valueType()) {
        case OBJECT:
            printTab(level);
            System.out.printf("interface %s {%n", s.replace('-', '_'));
            printTab(level);
            System.out.printf("    Config cfg = %s.cfg.getObject(\"%s\").toConfig();%n%n", p, s);
            ((ConfigObject) configValue).forEach((s1, configValue2) -> print2(s1, configValue2, s, l));
            printTab(level);
            System.out.printf("}%n%n");
            break;
        case STRING:
            printTab(level);
            System.out.printf("  String %s = cfg.getString(\"%s\");%n%n", s.replace('-', '_'), s);
            break;
        case NUMBER:
            printTab(level);
            System.out.printf("  Number %s = cfg.getNumber(\"%s\");%n%n", s.replace('-', '_'), s);
            break;
        case BOOLEAN:
            printTab(level);
            System.out.printf("  Boolean %s = cfg.getBoolean(\"%s\");%n%n", s.replace('-', '_'), s);
            break;
        case LIST:
            printTab(level);
            System.out.printf("  List<Object> %s = cfg.getList(\"%s\").unwrapped();%n%n", s.replace('-', '_'), s);
            break;
    }
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:31,代码来源:ConfigCenterTest.java

示例12: initializeUDFs

import com.typesafe.config.ConfigValue; //导入方法依赖的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);
  }
}
 
开发者ID:cloudera-labs,项目名称:envelope,代码行数:33,代码来源:Runner.java

示例13: configureObject

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
/**
 * Configure an object of a given class.
 * 
 * @param loggerContext
 *            the context to assign to this object if it is
 *            {@link ContextAwareBase}
 * @param clazz
 *            the class to instantiate
 * @param config
 *            a configuration containing the object's properties - each
 *            top-level key except for "class" must have a corresponding
 *            setter method, or an adder method in the case of lists
 * @param children
 *            a list which, if not null, will be filled with any child
 *            objects assigned as properties
 * @return the object instantiated with all properties assigned
 * @throws ReflectiveOperationException
 *             if any setter/adder method is missing or if the class cannot
 *             be instantiated with a no-argument constructor
 */
private <T> T configureObject(LoggerContext loggerContext, Class<T> clazz, Config config, List<Object> children)
		throws ReflectiveOperationException {
	T object = clazz.newInstance();

	if (object instanceof ContextAwareBase)
		((ContextAwareBase) object).setContext(loggerContext);

	ConfigPropertySetter propertySetter = new ConfigPropertySetter(beanCache, object);
	propertySetter.setContext(loggerContext);

	for (Entry<String, ConfigValue> entry : config.withoutPath("class").root().entrySet()) {
		ConfigValue value = entry.getValue();
		switch (value.valueType()) {
		case OBJECT:
			Config subConfig = config.getConfig("\"" + entry.getKey() + "\"");
			if (subConfig.hasPath("class")) {
				Class<?> childClass = Class.forName(subConfig.getString("class"));
				Object child = this.configureObject(loggerContext, childClass, subConfig, null);
				String propertyName = NameUtils.toLowerCamelCase(entry.getKey());
				propertySetter.setRawProperty(propertyName, child);
				if (children != null)
					children.add(child);
			} else {
				propertySetter.setProperty(entry.getKey(), config);
			}
			break;
		default:
			propertySetter.setProperty(entry.getKey(), config);
			break;
		}
	}

	return object;
}
 
开发者ID:gnieh,项目名称:logback-config,代码行数:55,代码来源:ConfigConfigurator.java

示例14: next

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
@Override
public OptionValue next() {
  final Entry<String, ConfigValue> e = entries.next();
  final ConfigValue cv = e.getValue();
  final String name = e.getKey();
  OptionValue optionValue = null;
  switch(cv.valueType()) {
  case BOOLEAN:
    optionValue = OptionValue.create(AccessibleScopes.BOOT, name, (Boolean) cv.unwrapped(), OptionScope.BOOT);
    break;

  case LIST:
  case OBJECT:
  case STRING:
    optionValue = OptionValue.create(AccessibleScopes.BOOT, name, cv.render(),OptionScope.BOOT);
    break;

  case NUMBER:
    optionValue = OptionValue.create(OptionValue.AccessibleScopes.BOOT, name, ((Number) cv.unwrapped()).longValue(),OptionScope.BOOT);
    break;

  case NULL:
    throw new IllegalStateException("Config value \"" + name + "\" has NULL type");

  default:
    throw new IllegalStateException("Unknown type: " + cv.valueType());
  }

  return optionValue;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:31,代码来源:DrillConfigIterator.java

示例15: getConfigValue

import com.typesafe.config.ConfigValue; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getConfigValue(Class<?> paramClass, Type paramType, String path) {
	Optional<Object> extractedValue = ConfigExtractors.extractConfigValue(config, paramClass, path);
	if (extractedValue.isPresent()) {
		return extractedValue.get();
	}

	ConfigValue configValue = config.getValue(path);
	ConfigValueType valueType = configValue.valueType();
	if (valueType.equals(ConfigValueType.OBJECT) && Map.class.isAssignableFrom(paramClass)) {
		ConfigObject object = config.getObject(path);
           return object.unwrapped();
	} else if (valueType.equals(ConfigValueType.OBJECT)) {
		Object bean = ConfigBeanFactory.create(config.getConfig(path), paramClass);
		return bean;
	} else if (valueType.equals(ConfigValueType.LIST) && List.class.isAssignableFrom(paramClass)) {
		Type listType = ((ParameterizedType) paramType).getActualTypeArguments()[0];
		
		Optional<List<?>> extractedListValue = 
			ListExtractors.extractConfigListValue(config, listType, path);
		
		if (extractedListValue.isPresent()) {
			return extractedListValue.get();
		} else {
			List<? extends Config> configList = config.getConfigList(path);
			return configList.stream()
				.map(cfg -> {
					Object created = ConfigBeanFactory.create(cfg, (Class) listType);
					return created;
				})
				.collect(Collectors.toList());
		}
	}
	
	throw new RuntimeException("Cannot obtain config value for " + paramType + " at path: " + path);
}
 
开发者ID:racc,项目名称:typesafeconfig-guice,代码行数:37,代码来源:TypesafeConfigModule.java


注:本文中的com.typesafe.config.ConfigValue.valueType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。