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

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

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

Config.traverse介绍

[英]Iterative deepening depth-first traversal of the node and its subtree as a Stream.

If the config node does not exist or is a leaf the returned stream is empty.

Depending on the structure of the configuration the returned stream can deliver a mix of object, list, and leaf value nodes. The stream will include and traverse through object members and list elements.
[中]作为流对节点及其子树进行迭代深度优先遍历。
如果配置节点不存在或是叶,则返回的流为空。
根据配置的结构,返回的流可以提供对象、列表和叶值节点的混合。流将包含并遍历对象成员和列表元素。

代码示例

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

/**
 * <strong>Iterative deepening depth-first traversal</strong> of the node
 * and its subtree as a {@code Stream<Config>}.
 * <p>
 * If the config node does not exist or is a leaf the returned stream is
 * empty.
 * <p>
 * Depending on the structure of the configuration the returned stream can
 * deliver a mix of object, list, and leaf value nodes. The stream will
 * include and traverse through object members and list elements.
 *
 * @return stream of deepening depth-first sub-nodes
 */
default Stream<Config> traverse() {
  return traverse((node) -> true);
}

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

/**
 * Create a new instance.
 *
 * @param config           configuration
 * @param mpConfigSources  config sources
 * @param converterClasses classes of converters
 * @param converters       class to converter mapping
 */
MpConfig(Config config,
        List<ConfigSource> mpConfigSources,
        Set<Class<?>> converterClasses,
        Map<Class<?>, Converter<?>> converters) {
  final AtomicReference<Config> ref = new AtomicReference<>(config);
  config.onChange(newConfig -> {
    ref.set(newConfig);
    return true;
  });
  this.config = ref::get;
  this.mpConfigSources = mpConfigSources;
  this.propertyNames =
      Stream.concat(mpConfigSources.stream()
                 .flatMap(cs -> cs.getPropertyNames().stream()),
             config.traverse(Config::isLeaf)
                 .map(Config::key)
                 .map(Config.Key::toString))
          .collect(Collectors.toSet());
  this.converterClasses = new HashSet<>(converterClasses);
  this.converters = converters;
}

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

/**
 * Computes the difference between the first {@code Config} and the second
 * one.
 * @param origConfig original configuration
 * @param newConfig newer configuration
 * @return {@code ConfigDiff} representing the changes
 */
static ConfigDiff from(Config origConfig, Config newConfig) {
  Stream<Config> forward = origConfig.traverse()
      .filter(origNode -> notEqual(origNode, newConfig.get(origNode.key())));
  Stream<Config> backward = newConfig.traverse()
      .filter(newNode -> notEqual(newNode, origConfig.get(newNode.key())));
  Set<Config.Key> changedKeys = Stream.concat(forward, backward)
      .map(Config::key)
      .distinct()
      .flatMap(ConfigDiff::expandKey)
      .distinct()
      .collect(toSet());
  return new ConfigDiff(newConfig, changedKeys);
}

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

return new StringMap(config.key().toString(), config.asString().get());
} else {
  return new StringMap(config.traverse()
                 .filter(Config::isLeaf)
                 .map(node -> new AbstractMap.SimpleEntry<>(node.key().toString(), node.asString().get()))

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

/**
 * <strong>Iterative deepening depth-first traversal</strong> of the node
 * and its subtree as a {@code Stream<Config>}.
 * <p>
 * If the config node does not exist or is a leaf the returned stream is
 * empty.
 * <p>
 * Depending on the structure of the configuration the returned stream can
 * deliver a mix of object, list, and leaf value nodes. The stream will
 * include and traverse through object members and list elements.
 *
 * @return stream of deepening depth-first sub-nodes
 */
default Stream<Config> traverse() {
  return traverse((node) -> true);
}

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

/**
 * Create a new instance.
 *
 * @param config           configuration
 * @param mpConfigSources  config sources
 * @param converterClasses classes of converters
 * @param converters       class to converter mapping
 */
MpConfig(Config config,
        List<ConfigSource> mpConfigSources,
        Set<Class<?>> converterClasses,
        Map<Class<?>, Converter<?>> converters) {
  final AtomicReference<Config> ref = new AtomicReference<>(config);
  config.onChange(newConfig -> {
    ref.set(newConfig);
    return true;
  });
  this.config = ref::get;
  this.mpConfigSources = mpConfigSources;
  this.propertyNames =
      Stream.concat(mpConfigSources.stream()
                 .flatMap(cs -> cs.getPropertyNames().stream()),
             config.traverse(Config::isLeaf)
                 .map(Config::key)
                 .map(Config.Key::toString))
          .collect(Collectors.toSet());
  this.converterClasses = new HashSet<>(converterClasses);
  this.converters = converters;
}

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

/**
 * Computes the difference between the first {@code Config} and the second
 * one.
 * @param origConfig original configuration
 * @param newConfig newer configuration
 * @return {@code ConfigDiff} representing the changes
 */
static ConfigDiff from(Config origConfig, Config newConfig) {
  Stream<Config> forward = origConfig.traverse()
      .filter(origNode -> notEqual(origNode, newConfig.get(origNode.key())));
  Stream<Config> backward = newConfig.traverse()
      .filter(newNode -> notEqual(newNode, origConfig.get(newNode.key())));
  Set<Config.Key> changedKeys = Stream.concat(forward, backward)
      .map(Config::key)
      .distinct()
      .flatMap(ConfigDiff::expandKey)
      .distinct()
      .collect(toSet());
  return new ConfigDiff(newConfig, changedKeys);
}

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

return new StringMap(config.key().toString(), config.asString().get());
} else {
  return new StringMap(config.traverse()
                 .filter(Config::isLeaf)
                 .map(node -> new AbstractMap.SimpleEntry<>(node.key().toString(), node.asString().get()))

相关文章