io.helidon.config.Config.asMap()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中io.helidon.config.Config.asMap()方法的一些代码示例,展示了Config.asMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.asMap()方法的具体详情如下:
包路径:io.helidon.config.Config
类名称:Config
方法名:asMap

Config.asMap介绍

[英]Transform all leaf nodes (values) into Map instance.

Fully qualified key of config node is used as a key in returned Map. #detach() config node before transforming to Map in case you want to cut current Config node key prefix.

Let's say we work with following configuration:

app: 
name: Example 1 
page-size: 20 
logging: 
app.level = INFO 
level = WARNING

Map app1 contains two keys: app.name, app.page-size.

Map app1 = config.get("app").asMap();

#detach() app config node returns new Config instance with "reset" local root.

Map app2 = config.get("app").detach().asMap();

Map app2 contains two keys without app prefix: name, page-size.
[中]将所有叶节点(值)转换为贴图实例。
config节点的完全限定键用作返回映射中的键#如果要剪切当前配置节点键前缀,请在转换为映射之前分离()配置节点。
假设我们使用以下配置:

app: 
name: Example 1 
page-size: 20 
logging: 
app.level = INFO 
level = WARNING

地图应用程序1包含两个键:应用程序。名称,应用程序。页面大小

Map app1 = config.get("app").asMap();

#detach()app config节点返回具有“reset”本地根的新配置实例

Map app2 = config.get("app").detach().asMap();

Map app2包含两个不带应用前缀的键:名称、页面大小。

代码示例

代码示例来源:origin: oracle/helidon

/**
 * Get all properties of this config as a map.
 *
 * @return map where keys are configuration keys and values are associated string values
 */
public Map<String, String> asMap() {
  // config from helidon config instance
  Map<String, String> map = new HashMap<>(config.get().asMap().get());
  // now add all properties from sources of MP config
  List<ConfigSource> configSources = new ArrayList<>(mpConfigSources);
  Collections.reverse(configSources);
  for (ConfigSource configSource : configSources) {
    map.putAll(configSource.getProperties());
  }
  return map;
}

代码示例来源:origin: oracle/helidon

private void validateConfig(EndpointConfig config, Errors.Collector collector) {
  config.config("abac")
      .ifPresent(abacConfig -> abacConfig.asMap()
          .ifPresent(theMap -> {
            int attributes = 0;

代码示例来源:origin: oracle/helidon

/**
 * Returns a {@link ConfigSource} that contains the same configuration model
 * as the provided {@link Config
 * config}.
 *
 * @param config the original {@code Config}
 * @return {@code ConfigSource} for the same {@code Config} as the original
 */
public static ConfigSource create(Config config) {
  return ConfigSources.create(config.asMap().get()).get();
}

代码示例来源:origin: oracle/helidon

private SeContainer createContainter(ClassLoader classLoader) {
  // not in CDI
  SeContainerInitializer initializer = SeContainerInitializer.newInstance();
  initializer.setClassLoader(classLoader);
  Map<String, Object> props = new HashMap<>(config.helidonConfig()
                           .get("cdi")
                           .detach()
                           .asMap()
                           .orElse(CollectionsHelper.mapOf()));
  initializer.setProperties(props);
  // add resource classes explicitly configured without CDI annotations
  this.resourceClasses.stream()
      .filter(this::notACdiBean)
      .forEach(initializer::addBeanClasses);
  STARTUP_LOGGER.finest("Initializer");
  SeContainer container = initializer.initialize();
  STARTUP_LOGGER.finest("Initalizer.initialize()");
  return container;
}

代码示例来源:origin: oracle/helidon

/**
 * {@inheritDoc}
 * <ul>
 * <li>{@code media-type-mapping} - type {@code Map} - key to media type, see {@link #mediaTypeMapping(Function)}</li>
 * </ul>
 *
 * @param metaConfig configuration properties used to initialize a builder instance.
 * @return modified builder instance
 */
@Override
protected B init(Config metaConfig) {
  //media-type-mapping
  metaConfig.get(MEDIA_TYPE_MAPPING_KEY).detach().asMap()
      .ifPresent(this::initMediaTypeMapping);
  return super.init(metaConfig);
}

代码示例来源:origin: oracle/helidon

return mpConfig.helidonConfig().get(configKey).detach().asMap();
} else if (rawType.isAssignableFrom(Set.class)) {
  return mpConfig.asSet(configKey, typeArg);

代码示例来源:origin: oracle/helidon

@Override
public ZipkinTracerBuilder config(Config config) {
  config.get("service").asString().ifPresent(this::serviceName);
  config.get("protocol").asString().ifPresent(this::collectorProtocol);
  config.get("host").asString().ifPresent(this::collectorHost);
  config.get("port").asInt().ifPresent(this::collectorPort);
  config.get("path").asString().ifPresent(this::collectorPath);
  config.get("api-version").asString().ifPresent(this::configApiVersion);
  config.get("enabled").asBoolean().ifPresent(this::enabled);
  config.get("tags").detach()
      .asMap()
      .orElseGet(CollectionsHelper::mapOf)
      .forEach(this::addTracerTag);
  config.get("boolean-tags")
      .asNodeList()
      .ifPresent(nodes -> {
        nodes.forEach(node -> {
          this.addTracerTag(node.key().name(), node.asBoolean().get());
        });
      });
  config.get("int-tags")
      .asNodeList()
      .ifPresent(nodes -> {
        nodes.forEach(node -> {
          this.addTracerTag(node.key().name(), node.asInt().get());
        });
      });
  return this;
}

代码示例来源:origin: io.helidon.microprofile.config/helidon-microprofile-config

/**
 * Get all properties of this config as a map.
 *
 * @return map where keys are configuration keys and values are associated string values
 */
public Map<String, String> asMap() {
  // config from helidon config instance
  Map<String, String> map = new HashMap<>(config.get().asMap().get());
  // now add all properties from sources of MP config
  List<ConfigSource> configSources = new ArrayList<>(mpConfigSources);
  Collections.reverse(configSources);
  for (ConfigSource configSource : configSources) {
    map.putAll(configSource.getProperties());
  }
  return map;
}

代码示例来源:origin: io.helidon.config/helidon-config

/**
 * Returns a {@link ConfigSource} that contains the same configuration model
 * as the provided {@link Config
 * config}.
 *
 * @param config the original {@code Config}
 * @return {@code ConfigSource} for the same {@code Config} as the original
 */
public static ConfigSource create(Config config) {
  return ConfigSources.create(config.asMap().get()).get();
}

代码示例来源:origin: io.helidon.security.providers/helidon-security-providers-abac

private void validateConfig(EndpointConfig config, Errors.Collector collector) {
  config.config("abac")
      .ifPresent(abacConfig -> abacConfig.asMap()
          .ifPresent(theMap -> {
            int attributes = 0;

代码示例来源:origin: io.helidon.microprofile.server/helidon-microprofile-server

private SeContainer createContainter(ClassLoader classLoader) {
  // not in CDI
  SeContainerInitializer initializer = SeContainerInitializer.newInstance();
  initializer.setClassLoader(classLoader);
  Map<String, Object> props = new HashMap<>(config.helidonConfig()
                           .get("cdi")
                           .detach()
                           .asMap()
                           .orElse(CollectionsHelper.mapOf()));
  initializer.setProperties(props);
  // add resource classes explicitly configured without CDI annotations
  this.resourceClasses.stream()
      .filter(this::notACdiBean)
      .forEach(initializer::addBeanClasses);
  STARTUP_LOGGER.finest("Initializer");
  SeContainer container = initializer.initialize();
  STARTUP_LOGGER.finest("Initalizer.initialize()");
  return container;
}

代码示例来源:origin: io.helidon.config/helidon-config

/**
 * {@inheritDoc}
 * <ul>
 * <li>{@code media-type-mapping} - type {@code Map} - key to media type, see {@link #mediaTypeMapping(Function)}</li>
 * </ul>
 *
 * @param metaConfig configuration properties used to initialize a builder instance.
 * @return modified builder instance
 */
@Override
protected B init(Config metaConfig) {
  //media-type-mapping
  metaConfig.get(MEDIA_TYPE_MAPPING_KEY).detach().asMap()
      .ifPresent(this::initMediaTypeMapping);
  return super.init(metaConfig);
}

代码示例来源:origin: io.helidon.microprofile.config/helidon-microprofile-config-cdi

return mpConfig.helidonConfig().get(configKey).detach().asMap();
} else if (rawType.isAssignableFrom(Set.class)) {
  return mpConfig.asSet(configKey, typeArg);

相关文章