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

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

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

Config.asList介绍

[英]Returns list of specified type.
[中]返回指定类型的列表。

代码示例

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

@Override
public <T> ConfigValue<List<T>> asList(Function<Config, T> mapper) throws ConfigMappingException {
  return ConfigValues.create(this, Optional::empty, aConfig -> aConfig.asList(mapper));
}

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

@Override
public <T> ConfigValue<List<T>> asList(Class<T> type) throws ConfigMappingException {
  return ConfigValues.create(this, Optional::empty, aConfig -> aConfig.asList(type));
}

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

@Override
public <T> ConfigValue<List<T>> asList(Class<T> type) throws ConfigMappingException {
  return ConfigValues.createList(this,
                config -> config.as(type),
                config -> config.asList(type));
}

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

@Override
public <T> ConfigValue<List<T>> asList(Function<Config, T> mapper) throws ConfigMappingException {
  return ConfigValues.createList(this,
                config -> config.as(mapper),
                config -> config.asList(mapper));
}

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

static OutboundConfig createFromConfig(Config providerConfig, OutboundTarget[] defaults) {
  Config config = providerConfig.get(CONFIG_OUTBOUND);
  List<OutboundTarget> configuredTargets = config.asList(OutboundTarget::create).orElse(CollectionsHelper.listOf());
  boolean useDefaults = configuredTargets.stream().noneMatch(targetConfig -> "default".equals(targetConfig.name()))
      && (null != defaults);
  Builder builder = OutboundConfig.builder();
  if (useDefaults) {
    //first add default values
    Arrays.stream(defaults).forEach(builder::addTarget);
  }
  //then add configured values
  configuredTargets.forEach(builder::addTarget);
  return builder.build();
}

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

Optional<T> get(Config configNode) {
  try {
    if (configNode.exists()) {
      if (list) {
        return Optional.of(propertyType.cast(configNode.asList(configAsType).get()));
      } else {
        return Optional.of(propertyType.cast(configNode.as(configAsType).get()));
      }
    } else {
      if (defaultSupplier != null) {
        return Optional.ofNullable(defaultSupplier.apply(propertyType, configNode));
      } else {
        return Optional.empty();
      }
    }
  } catch (ConfigException ex) {
    throw ex;
  } catch (Throwable throwable) {
    throw new ConfigException("Unable to set '" + name + "' property.", throwable);
  }
}

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

private Object findArrayValue(String propertyName, Class<?> element) {
  // there should not be io.helidon.Config[]
  return findInMpSources(propertyName)
      .map(value -> asArray(value, element))
      .orElseGet(() -> {
        Config arrayConfig = config.get().get(propertyName);
        if (arrayConfig.isLeaf()) {
          return asArray(arrayConfig.asString().get(), element);
        }
        List<?> objects = arrayConfig.asList(element).get();
        Object array = Array.newInstance(element, objects.size());
        for (int i = 0; i < objects.size(); i++) {
          Array.set(array, i, objects.get(i));
        }
        return array;
      });
}

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

/**
 * Create an instance from configuration (of endpoint).
 *
 * @param config config located on the key of this validator
 * @return configuration based on the config
 */
public static ScopesConfig create(Config config) {
  return new ScopesConfig(config.asList(String.class).orElse(CollectionsHelper.listOf()));
}

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

/**
 * Return value as a {@link List} of values.
 *
 * @param propertyName name of property
 * @param typeArg      type of elements in the list
 * @param <T>          type of elements
 * @return list with elements found in properties
 */
public <T> List<T> asList(String propertyName, Class<T> typeArg) {
  if (typeArg == Config.class) {
    return config.get().get(propertyName).asList(typeArg).get();
  }
  return findInMpSources(propertyName)
      .map(value -> {
        String[] valueArray = toArray(value);
        List<T> result = new LinkedList<>();
        for (String element : valueArray) {
          result.add(convert(typeArg, element));
        }
        return result;
      })
      .orElseGet(() -> config.get().get(propertyName).asList(typeArg).get());
}

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

@Override
public <T> ConfigValue<List<T>> asList(Class<T> type) throws ConfigMappingException {
  return ConfigValues.create(this, () -> as(type).map(CollectionsHelper::listOf), config -> config.asList(type));
}

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

@Override
public <T> ConfigValue<List<T>> asList(Function<Config, T> mapper) throws ConfigMappingException {
  return ConfigValues.create(this, () -> as(mapper).map(CollectionsHelper::listOf), config -> config.asList(mapper));
}

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

/**
   * Update this builder from configuration.
   *
   * @param config node located on this component's configuration
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("web-context").asString().ifPresent(this::webContext);
    config.get("include").asList(String.class).ifPresent(list -> {
      list.forEach(this::addIncluded);
    });
    config.get("exclude").asList(String.class).ifPresent(list -> {
      list.forEach(this::addExcluded);
    });
    return this;
  }
}

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

/**
 * Create a new instance from configuration.
 *
 * @param config configuration located at header config
 * @return instance configured from config
 */
public static HeadersConfig create(Config config) {
  return create(config.get("always").asList(String.class).orElse(CollectionsHelper.listOf()),
         config.get("if-present").asList(String.class).orElse(CollectionsHelper.listOf()));
}

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

static OutboundTarget create(Config c) {
  Builder builder = new Builder();
  builder.config(c);
  builder.name(c.get(CONFIG_NAME).asString().get());
  c.get(CONFIG_TRANSPORTS).asList(String.class).orElse(CollectionsHelper.listOf())
      .forEach(builder::addTransport);
  c.get(CONFIG_HOSTS).asList(String.class).orElse(CollectionsHelper.listOf())
      .forEach(builder::addHost);
  c.get(CONFIG_PATHS).asList(String.class).orElse(CollectionsHelper.listOf())
      .forEach(builder::addPath);
  return builder.build();
}

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

/**
 * Create an time config from configuration.
 *
 * @param config configuration located on this validator config key
 * @return time configuration based on the config
 */
public static TimeConfig create(Config config) {
  Builder builder = TimeConfig.builder();
  config.get("time-of-day").asList(Config.class)
      .get()
      .forEach(tod -> builder.addBetween(LocalTime.parse(tod.get("from").asString().orElse("00:00:00")),
                        LocalTime.parse(tod.get("to").asString().orElse("24:00:00"))));
  config.get("days-of-week").asList(DayOfWeek.class)
      .ifPresent(builder::addDaysOfWeek);
  return builder.build();
}

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

/**
   * Load configuration data from configuration.
   *
   * @param config configuration located the key of this attribute config
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("user").asList(String.class).ifPresent(this::addRoles);
    config.get("service").asList(String.class).ifPresent(this::addServiceRoles);
    config.get("permit-all").asBoolean().ifPresent(this::permitAll);
    config.get("deny-all").asBoolean().ifPresent(this::denyAll);
    return this;
  }
}

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

static ConfigUser create(Config config) {
  ConfigUser cu = new ConfigUser();
  cu.login = config.get("login").asString().get();
  cu.password = config.get("password").asString().orElse("").toCharArray();
  cu.roles.addAll(config.get("roles").asList(String.class).orElse(CollectionsHelper.listOf()));
  return cu;
}

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

/**
 * Create a builder from configuration.
 *
 * @param config Config located at http-signatures key
 * @return builder instance configured from config
 */
public Builder config(Config config) {
  config.get("headers").asList(HttpSignHeader.class).ifPresent(list -> list.forEach(this::addAcceptHeader));
  config.get("optional").asBoolean().ifPresent(this::optional);
  config.get("realm").asString().ifPresent(this::realm);
  config.get("sign-headers").as(SignedHeadersConfig::create).ifPresent(this::inboundRequiredHeaders);
  outboundConfig = OutboundConfig.create(config);
  config.get("inbound.keys")
      .asList(InboundClientDefinition::create)
      .ifPresent(list -> list.forEach(inbound -> inboundKeys.put(inbound.keyId(), inbound)));
  return this;
}

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

/**
 * Update this builder from configuration.
 *
 * @param config configuration instance located on {@link PolicyValidatorService#configKey()}
 * @return updated builder instance
 */
public Builder config(Config config) {
  this.config = config;
  config.get("validators").asList(Config.class).ifPresent(configs -> {
    for (Config validatorConfig : configs) {
      validatorConfig.get("class").asString()
          .ifPresentOrElse(clazz -> {
            //attempt to instantiate
            addExecutor(instantiate(clazz));
          }, () -> {
            throw new SecurityException(
                "validators key may only contain an array of class to class names, at key: "
                    + validatorConfig.key());
          });
    }
  });
  return this;
}

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

/**
 * Update fields from configuration.
 *
 * @param config Configuration
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("name").asString().ifPresent(this::name);
  config.get("default").asBoolean().ifPresent(this::isDefault);
  config.get("authentication").asList(FlaggedProvider::create)
      .ifPresent(this.authenticators::addAll);
  config.get("authorization").asList(FlaggedProvider::create)
      .ifPresent(this.authorizers::addAll);
  config.get("outbound").asNodeList()
      .ifPresent(configs -> configs.forEach(outConfig -> addOutboundProvider(outConfig.get("name")
                                              .asString()
                                              .get())));
  return this;
}

相关文章