當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。