java.util.Properties.stringPropertyNames()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(227)

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

Properties.stringPropertyNames介绍

[英]Returns those property names (keys) in this Properties object for which both key and value are strings.
[中]返回此属性对象中键和值均为字符串的属性名称(键)。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

public static Properties overWriteProperties(Properties bp, Properties ovp) {
 for (String propertyName : ovp.stringPropertyNames()) {
  bp.setProperty(propertyName,ovp.getProperty(propertyName));
 }
 return bp;
}

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

public static Map<String, String> parseProperties(String content) throws IOException {
  Map<String, String> map = new HashMap<>();
  if (StringUtils.isEmpty(content)) {
    logger.warn("You specified the config centre, but there's not even one single config item in it.");
  } else {
    Properties properties = new Properties();
    properties.load(new StringReader(content));
    properties.stringPropertyNames().forEach(
        k -> map.put(k, properties.getProperty(k))
    );
  }
  return map;
}

代码示例来源:origin: azkaban/azkaban

/**
 * Put the given Properties into the Props. This method performs any variable substitution in the
 * value replacing any occurrence of ${name} with the value of get("name"). get() is called first
 * on the Props and next on the Properties object.
 *
 * @param properties The properties to put
 * @throws IllegalArgumentException If the variable given for substitution is not a valid key in
 * this Props.
 */
public void put(final Properties properties) {
 for (final String propName : properties.stringPropertyNames()) {
  this._current.put(propName, properties.getProperty(propName));
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public void initializeVariablesFrom( VariableSpace parent ) {
 this.parent = parent;
 // Clone the system properties to avoid ConcurrentModificationException while iterating
 // and then add all of them to properties variable.
 Set<String> systemPropertiesNames = System.getProperties().stringPropertyNames();
 for ( String key : systemPropertiesNames ) {
  getProperties().put( key, System.getProperties().getProperty( key ) );
 }
 if ( parent != null ) {
  copyVariablesFrom( parent );
 }
 if ( injection != null ) {
  properties.putAll( injection );
  injection = null;
 }
 initialized = true;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Constructs a mapping of configuration and includes all properties that
 * start with the specified configuration prefix.  Property names in the
 * mapping are trimmed to remove the configuration prefix.
 *
 * @param confPrefix configuration prefix
 * @return mapping of configuration properties with prefix stripped
 */
public Map<String, String> getPropsWithPrefix(String confPrefix) {
 Properties props = getProps();
 Map<String, String> configMap = new HashMap<>();
 for (String name : props.stringPropertyNames()) {
  if (name.startsWith(confPrefix)) {
   String value = get(name);
   String keyName = name.substring(confPrefix.length());
   configMap.put(keyName, value);
  }
 }
 return configMap;
}

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

@Test
public void validateThatHyphensConvertedToCamelCase() throws Exception {
 Properties poolProperties = new Properties();
 poolProperties.setProperty("foo-bar-zoo", "value");
 poolProperties.setProperty("foo", "value");
 poolProperties.setProperty("-bar", "value");
 poolProperties.setProperty("zoo-", "value");
 Properties hikariProperties = instance.convertToHikari(poolProperties);
 assertThat(hikariProperties.stringPropertyNames()).containsExactlyInAnyOrder("foo", "Bar",
   "zoo", "fooBarZoo");
}

代码示例来源:origin: embulk/embulk

private static Collection<String> readPropertyKeys(String name) {
  try (InputStream in = PluginClassLoaderModule.class.getResourceAsStream(name)) {
    if (in == null) {
      throw new NullPointerException(String.format("Resource '%s' is not found in classpath. Jar file or classloader is broken.", name));
    }
    Properties prop = new Properties();
    prop.load(in);
    return prop.stringPropertyNames();
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: ctripcorp/apollo

List<ConfigChange> calcPropertyChanges(String namespace, Properties previous,
                    Properties current) {
 if (previous == null) {
  previous = new Properties();
  current = new Properties();
 Set<String> previousKeys = previous.stringPropertyNames();
 Set<String> currentKeys = current.stringPropertyNames();
  changes.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey),
    PropertyChangeType.ADDED));
  changes.add(new ConfigChange(namespace, removedKey, previous.getProperty(removedKey), null,
    PropertyChangeType.DELETED));
  String previousValue = previous.getProperty(commonKey);
  String currentValue = current.getProperty(commonKey);
  if (Objects.equal(previousValue, currentValue)) {

代码示例来源:origin: voldemort/voldemort

private static String getPropertiesString(Properties props) {
  StringBuilder finalVersionList = new StringBuilder();
  for(String propName: props.stringPropertyNames()) {
    if(finalVersionList.length() == 0) {
      finalVersionList.append(propName + "=" + props.getProperty(propName));
    } else {
      finalVersionList.append("\n" + propName + "=" + props.getProperty(propName));
    }
  }
  return finalVersionList.toString();
}

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

private Properties getOverriddenDefaults() throws IOException {
 Properties overriddenDefaults = new Properties();
 overriddenDefaults.put(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX.concat(LOG_FILE),
   getLogFile().getCanonicalPath());
 for (String key : System.getProperties().stringPropertyNames()) {
  if (key.startsWith(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX)) {
   overriddenDefaults.put(key, System.getProperty(key));
  }
 }
 return overriddenDefaults;
}

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

public static Map<String, String> parseProperties(String content) throws IOException {
  Map<String, String> map = new HashMap<>();
  if (StringUtils.isEmpty(content)) {
    logger.warn("You specified the config centre, but there's not even one single config item in it.");
  } else {
    Properties properties = new Properties();
    properties.load(new StringReader(content));
    properties.stringPropertyNames().forEach(
        k -> map.put(k, properties.getProperty(k))
    );
  }
  return map;
}

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

public static Map<String, String[]> extractDimensions(Properties props, List<String> dimensions)
{
 Map<String, String[]> dimensionsMap = new HashMap<>();
 for (String property : props.stringPropertyNames()) {
  if (property.startsWith(MonitorsConfig.METRIC_DIMENSION_PREFIX)) {
   String dimension = property.substring(MonitorsConfig.METRIC_DIMENSION_PREFIX.length());
   if (dimensions.contains(dimension)) {
    dimensionsMap.put(
      dimension,
      new String[]{props.getProperty(property)}
    );
   }
  }
 }
 return dimensionsMap;
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static Properties noClobberWriteProperties(Properties bp, Properties ovp) {
 for (String propertyName : ovp.stringPropertyNames()) {
  if (bp.containsKey(propertyName))
   continue;
  bp.setProperty(propertyName,ovp.getProperty(propertyName));
 }
 return bp;
}

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

@Test
public void validateThatJdbcDriverClassConvertedToDriverClassName() throws Exception {
 Properties poolProperties = new Properties();
 poolProperties.setProperty("jdbc-driver-class", "foo");
 Properties hikariProperties = instance.convertToHikari(poolProperties);
 assertThat(hikariProperties.stringPropertyNames()).contains("driverClassName");
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Loads the keys from the specified translation file into a set.
 * @param file translation file.
 * @return a Set object which holds the loaded keys.
 */
private Set<String> getTranslationKeys(File file) {
  Set<String> keys = new HashSet<>();
  try (InputStream inStream = Files.newInputStream(file.toPath())) {
    final Properties translations = new Properties();
    translations.load(inStream);
    keys = translations.stringPropertyNames();
  }
  // -@cs[IllegalCatch] It is better to catch all exceptions since it can throw
  // a runtime exception.
  catch (final Exception ex) {
    logException(ex, file);
  }
  return keys;
}

代码示例来源:origin: SonarSource/sonarqube

private void writeSystemProps(BufferedWriter fileWriter) throws IOException {
 fileWriter.write("System properties:\n");
 Properties sysProps = system.properties();
 for (String prop : new TreeSet<>(sysProps.stringPropertyNames())) {
  if (prop.startsWith(SONAR_PROP_PREFIX)) {
   continue;
  }
  fileWriter.append(String.format(KEY_VALUE_FORMAT, prop, sysProps.getProperty(prop))).append('\n');
 }
}

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

private Properties getOverriddenDefaults() throws IOException {
 final Properties overriddenDefaults = new Properties();
 overriddenDefaults.put(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX.concat(LOG_FILE),
   getLogFile().getCanonicalPath());
 for (String key : System.getProperties().stringPropertyNames()) {
  if (key.startsWith(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX)) {
   overriddenDefaults.put(key, System.getProperty(key));
  }
 }
 return overriddenDefaults;
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static Properties updatePropertiesWithOptions(Properties props, String[] args) {
 Properties allProperties = new Properties();
 // copy it so props isn't changed but can be overridden by args
 for (String key : props.stringPropertyNames()) {
  allProperties.setProperty(key, props.getProperty(key));
 }
 Properties options = StringUtils.argsToProperties(args);
 for (String key : options.stringPropertyNames()) {
  allProperties.setProperty(key, options.getProperty(key));
 }
 return allProperties;
}

代码示例来源:origin: confluentinc/ksql

private static Map<String, Object> propertiesToMap(final Properties properties) {
 final Map<String, Object> propertiesMap = new HashMap<>();
 properties.stringPropertyNames().forEach(
   prop -> propertiesMap.put(prop, properties.getProperty(prop)));
 return propertiesMap;
}

代码示例来源:origin: org.postgresql/postgresql

@Override
public ChainedLogicalStreamBuilder withSlotOptions(Properties options) {
 for (String propertyName : options.stringPropertyNames()) {
  slotOptions.setProperty(propertyName, options.getProperty(propertyName));
 }
 return this;
}

相关文章

微信公众号

最新文章

更多