org.apache.commons.configuration.Configuration.getKeys()方法的使用及代码示例

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

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

Configuration.getKeys介绍

[英]Get the list of the keys contained in the configuration. The returned iterator can be used to obtain all defined keys. Note that the exact behavior of the iterator's remove() method is specific to a concrete implementation. It may remove the corresponding property from the configuration, but this is not guaranteed. In any case it is no replacement for calling #clearProperty(String) for this property. So it is highly recommended to avoid using the iterator's remove()method.
[中]获取配置中包含的密钥列表。返回的迭代器可用于获取所有定义的键。请注意,迭代器的remove()方法的确切行为是特定于具体实现的。它可以从配置中删除相应的属性,但这不能保证。在任何情况下,它都不能替代为此属性调用#clearProperty(String)。因此,强烈建议避免使用迭代器的remove()方法。

代码示例

代码示例来源:origin: thinkaurelius/titan

@Override
public Iterable<String> getKeys(String prefix) {
  List<String> result = Lists.newArrayList();
  Iterator<String> keys;
  if (StringUtils.isNotBlank(prefix)) keys = config.getKeys(prefix);
  else keys = config.getKeys();
  while (keys.hasNext()) result.add(keys.next());
  return result;
}

代码示例来源:origin: apache/tinkerpop

public static void applyConfiguration(final Configuration configuration) {
  if (null == KryoShimServiceLoader.configuration ||
      null == KryoShimServiceLoader.cachedShimService ||
      !KryoShimServiceLoader.configuration.getKeys().hasNext()) {
    KryoShimServiceLoader.configuration = configuration;
    load(true);
  }
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public Iterable<String> getKeys(String prefix) {
  List<String> result = Lists.newArrayList();
  Iterator<String> keys;
  if (StringUtils.isNotBlank(prefix)) keys = config.getKeys(prefix);
  else keys = config.getKeys();
  while (keys.hasNext()) result.add(keys.next());
  return result;
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

public static void applyConfiguration(final Configuration configuration) {
  if (null == KryoShimServiceLoader.configuration ||
      null == KryoShimServiceLoader.cachedShimService ||
      !KryoShimServiceLoader.configuration.getKeys().hasNext()) {
    KryoShimServiceLoader.configuration = configuration;
    load(true);
  }
}

代码示例来源:origin: thinkaurelius/titan

public static List<String> getUnqiuePrefixes(Configuration config) {
  Set<String> nameSet = new HashSet<String>();
  List<String> names = new ArrayList<String>();
  Iterator<String> keyiter = config.getKeys();
  while (keyiter.hasNext()) {
    String key = keyiter.next();
    int pos = key.indexOf(CONFIGURATION_SEPARATOR);
    if (pos > 0) {
      String name = key.substring(0, pos);
      if (nameSet.add(name)) {
        names.add(name);
      }
    }
  }
  return names;
}

代码示例来源:origin: JanusGraph/janusgraph

public static List<String> getUniquePrefixes(Configuration config) {
  final Set<String> nameSet = new HashSet<>();
  final List<String> names = new ArrayList<>();
  final Iterator<String> keyIterator = config.getKeys();
  while (keyIterator.hasNext()) {
    String key = keyIterator.next();
    int pos = key.indexOf(CONFIGURATION_SEPARATOR);
    if (pos > 0) {
      String name = key.substring(0, pos);
      if (nameSet.add(name)) {
        names.add(name);
      }
    }
  }
  return names;
}

代码示例来源:origin: apache/incubator-pinot

private static void logFetcherInitConfig(SegmentFetcher fetcher, String protocol, Configuration conf) {
  LOGGER.info("Initializing protocol [{}] with the following configs:", protocol);
  Iterator iter = conf.getKeys();
  Set<String> secretKeys = fetcher.getProtectedConfigKeys();
  while (iter.hasNext()) {
   String key = (String) iter.next();
   if (secretKeys.contains(key)) {
    LOGGER.info("{}: {}", key, "********");
   } else {
    LOGGER.info("{}: {}", key, conf.getString(key));
   }
  }
  LOGGER.info("");
 }
}

代码示例来源:origin: Netflix/eureka

/**
 * Gets the metadata map associated with the instance. The properties that
 * will be looked up for this will be <code>namespace + ".metadata"</code>.
 *
 * <p>
 * For instance, if the given namespace is <code>eureka.appinfo</code>, the
 * metadata keys are searched under the namespace
 * <code>eureka.appinfo.metadata</code>.
 * </p>
 */
@Override
public Map<String, String> getMetadataMap() {
  String metadataNamespace = namespace + INSTANCE_METADATA_PREFIX + ".";
  Map<String, String> metadataMap = new LinkedHashMap<String, String>();
  Configuration config = (Configuration) configInstance.getBackingConfigurationSource();
  String subsetPrefix = metadataNamespace.charAt(metadataNamespace.length() - 1) == '.'
      ? metadataNamespace.substring(0, metadataNamespace.length() - 1)
      : metadataNamespace;
  for (Iterator<String> iter = config.subset(subsetPrefix).getKeys(); iter.hasNext(); ) {
    String key = iter.next();
    String value = config.getString(subsetPrefix + "." + key);
    metadataMap.put(key, value);
  }
  return metadataMap;
}

代码示例来源:origin: apache/incubator-pinot

public HelixInstanceDataManagerConfig(Configuration serverConfig)
  throws ConfigurationException {
 _instanceDataManagerConfiguration = serverConfig;
 Iterator keysIterator = serverConfig.getKeys();
 while (keysIterator.hasNext()) {
  String key = (String) keysIterator.next();
  LOGGER.info("InstanceDataManagerConfig, key: {} , value: {}", key, serverConfig.getProperty(key));
 }
 checkRequiredKeys();
}

代码示例来源:origin: apache/incubator-gobblin

private static Properties getProperties(Configuration config) {
 Properties props = new Properties();
 char delimiter = (config instanceof AbstractConfiguration)
      ? ((AbstractConfiguration) config).getListDelimiter() : ',';
  Iterator keys = config.getKeys();
  while (keys.hasNext())
  {
   String key = (String) keys.next();
   List list = config.getList(key);
   props.setProperty("flyway." + key, StringUtils.join(list.iterator(), delimiter));
  }
  return props;
}

代码示例来源:origin: apache/incubator-pinot

public static Configuration getDefaultBrokerConf(Configuration externalConfigs) {
  final Configuration defaultConfigs = getDefaultBrokerConf();
  @SuppressWarnings("unchecked")
  Iterator<String> iterable = externalConfigs.getKeys();
  while (iterable.hasNext()) {
   String key = iterable.next();
   defaultConfigs.setProperty(key, externalConfigs.getProperty(key));
  }
  return defaultConfigs;
 }
}

代码示例来源:origin: thinkaurelius/titan

private static void copyInputKeys(org.apache.hadoop.conf.Configuration hadoopConf, org.apache.commons.configuration.Configuration source) {
  // Copy IndexUpdateJob settings into the hadoop-backed cfg
  Iterator<String> keyIter = source.getKeys();
  while (keyIter.hasNext()) {
    String key = keyIter.next();
    ConfigElement.PathIdentifier pid;
    try {
      pid = ConfigElement.parse(ROOT_NS, key);
    } catch (RuntimeException e) {
      log.debug("[inputkeys] Skipping {}", key, e);
      continue;
    }
    if (!pid.element.isOption())
      continue;
    String k = ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + key;
    String v = source.getProperty(key).toString();
    hadoopConf.set(k, v);
    log.debug("[inputkeys] Set {}={}", k, v);
  }
}

代码示例来源:origin: twitter/distributedlog

/**
 * Load configurations with prefixed <i>section</i> from source configuration <i>srcConf</i> into
 * target configuration <i>targetConf</i>.
 *
 * @param targetConf
 *          Target Configuration
 * @param srcConf
 *          Source Configuration
 * @param section
 *          Section Key
 */
public static void loadConfiguration(Configuration targetConf, Configuration srcConf, String section) {
  Iterator confKeys = srcConf.getKeys();
  while (confKeys.hasNext()) {
    Object keyObject = confKeys.next();
    if (!(keyObject instanceof String)) {
      continue;
    }
    String key = (String) keyObject;
    if (key.startsWith(section)) {
      targetConf.setProperty(key.substring(section.length()), srcConf.getProperty(key));
    }
  }
}

代码示例来源:origin: apache/incubator-pinot

public static void init(Configuration fsConfig) {
 // Get schemes and their respective classes
 Iterator<String> keys = fsConfig.subset(CLASS).getKeys();
 if (!keys.hasNext()) {
  LOGGER.info("Did not find any fs classes in the configuration");
 }
 while (keys.hasNext()) {
  String key = keys.next();
  String fsClassName = (String) fsConfig.getProperty(CLASS + "." + key);
  LOGGER.info("Got scheme {}, classname {}, starting to initialize", key, fsClassName);
  try {
   PinotFS pinotFS = (PinotFS) Class.forName(fsClassName).newInstance();
   pinotFS.init(fsConfig.subset(key));
   LOGGER.info("Initializing PinotFS for scheme {}, classname {}", key, fsClassName);
   _fileSystemMap.put(key, pinotFS);
  } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
   LOGGER.error("Could not instantiate file system for class {}", fsClassName, e);
   throw new RuntimeException(e);
  }
 }
 if (!_fileSystemMap.containsKey(DEFAULT_FS_SCHEME)) {
  LOGGER.info("LocalPinotFS not configured, adding as default");
  _fileSystemMap.put(DEFAULT_FS_SCHEME, new LocalPinotFS());
 }
}

代码示例来源:origin: apache/incubator-pinot

Iterator<String> keys = config.subset(CLASS).getKeys();
if (!keys.hasNext()) {
 LOGGER.info("Did not find any crypter classes in the configuration");
while (keys.hasNext()) {
 String key = keys.next();
 String className = (String) config.getProperty(CLASS + "." + key);
 LOGGER.info("Got crypter class name {}, full crypter path {}, starting to initialize", key, className);

代码示例来源:origin: apache/incubator-pinot

public static ServerConf getDefaultHelixServerConfig(Configuration externalConfigs) {
 Configuration defaultConfigs = loadDefaultServerConf();
 @SuppressWarnings("unchecked")
 Iterator<String> iterable = externalConfigs.getKeys();
 while (iterable.hasNext()) {
  String key = iterable.next();
  defaultConfigs.setProperty(key, externalConfigs.getProperty(key));
  LOGGER.info("External config key: {}, value: {}", key, externalConfigs.getProperty(key));
 }
 return new ServerConf(defaultConfigs);
}

代码示例来源:origin: apache/servicecomb-java-chassis

public static Map<String, String> getPropertiesWithPrefix(Configuration configuration, String prefix) {
 Map<String, String> propertiesMap = new HashMap<>();
 Iterator<String> keysIterator = configuration.getKeys(prefix);
 while (keysIterator.hasNext()) {
  String key = keysIterator.next();
  propertiesMap.put(key.substring(prefix.length() + 1), String.valueOf(configuration.getProperty(key)));
 }
 return propertiesMap;
}

代码示例来源:origin: jbake-org/jbake

@Override
public List<String> getAsciidoctorOptionKeys() {
  List<String> options = new ArrayList<>();
  Configuration subConfig = compositeConfiguration.subset(JBakeProperty.ASCIIDOCTOR_OPTION);
  Iterator<String> iterator = subConfig.getKeys();
  while (iterator.hasNext()) {
    String key = iterator.next();
    options.add(key);
  }
  return options;
}

代码示例来源:origin: apache/tinkerpop

private static Configuration maskedConfiguration(final Configuration configuration) {
  final Configuration maskedConfiguration = new BaseConfiguration();
  final Iterator keys = configuration.getKeys();
  while(keys.hasNext()) {
    final String key = (String)keys.next();
    if (key.matches(maskedProperties))
      maskedConfiguration.setProperty(key, "******");
    else
      maskedConfiguration.setProperty(key, configuration.getProperty(key));
  }
  return maskedConfiguration;
}

代码示例来源:origin: com.thinkaurelius.titan/titan-core

@Override
public Iterable<String> getKeys(String prefix) {
  List<String> result = Lists.newArrayList();
  Iterator<String> keys;
  if (StringUtils.isNotBlank(prefix)) keys = config.getKeys(prefix);
  else keys = config.getKeys();
  while (keys.hasNext()) result.add(keys.next());
  return result;
}

相关文章