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

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

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

Properties.size介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Resolve the given interface mappings, turning class names into Class objects.
 * @param mappings the specified interface mappings
 * @return the resolved interface mappings (with Class objects as values)
 */
private Map<String, Class<?>[]> resolveInterfaceMappings(Properties mappings) {
  Map<String, Class<?>[]> resolvedMappings = new HashMap<>(mappings.size());
  for (Enumeration<?> en = mappings.propertyNames(); en.hasMoreElements();) {
    String beanKey = (String) en.nextElement();
    String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
    Class<?>[] classes = resolveClassNames(classNames, beanKey);
    resolvedMappings.put(beanKey, classes);
  }
  return resolvedMappings;
}

代码示例来源:origin: spring-projects/spring-framework

Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
Map<String, Object> map = new LinkedHashMap<>();
Properties props = new Properties();
    throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex);
  Assert.state(props.size() == 1, () -> "Failed to load exactly one test environment property from [" + pair + "]");
  for (String name : props.stringPropertyNames()) {
    map.put(name, props.getProperty(name));

代码示例来源:origin: alibaba/jstorm

private static Map loadProperty(String prop) {
  Map ret = new HashMap<>();
  Properties properties = new Properties();
  try {
    InputStream stream = new FileInputStream(prop);
    properties.load(stream);
    if (properties.size() == 0) {
      return null;
    } else {
      ret.putAll(properties);
    }
  } catch (Exception e1) {
    throw new RuntimeException(e1);
  }
  return ret;
}

代码示例来源:origin: qunarcorp/qmq

private void loadConfig() {
  try {
    final Properties p = new Properties();
    try (Reader reader = new BufferedReader(new FileReader(file))) {
      p.load(reader);
    }
    final Map<String, String> map = new LinkedHashMap<>(p.size());
    for (String key : p.stringPropertyNames()) {
      map.put(key, tryTrim(p.getProperty(key)));
    }
    config = Collections.unmodifiableMap(map);
  } catch (IOException e) {
    LOG.error("load local config failed. config: {}", file.getAbsolutePath(), e);
  }
}

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

public static ScramCredential credentialFromString(String str) {
  Properties props = toProps(str);
  if (props.size() != 4 || !props.containsKey(SALT) || !props.containsKey(STORED_KEY) ||
      !props.containsKey(SERVER_KEY) || !props.containsKey(ITERATIONS)) {
    throw new IllegalArgumentException("Credentials not valid: " + str);
  }
  byte[] salt = Base64.getDecoder().decode(props.getProperty(SALT));
  byte[] storedKey = Base64.getDecoder().decode(props.getProperty(STORED_KEY));
  byte[] serverKey = Base64.getDecoder().decode(props.getProperty(SERVER_KEY));
  int iterations = Integer.parseInt(props.getProperty(ITERATIONS));
  return new ScramCredential(salt, storedKey, serverKey, iterations);
}

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

public static Optional<Config> getOptionalRuntimeConfig(Properties properties) {
  Properties runtimeConfigProps = new Properties();
  for (Map.Entry<Object, Object> entry : properties.entrySet()) {
   if (entry.getKey().toString().startsWith(ConfigurationKeys.CONFIG_RUNTIME_PREFIX)) {
    runtimeConfigProps.put(entry.getKey().toString().replace(ConfigurationKeys.CONFIG_RUNTIME_PREFIX, ""),
      entry.getValue().toString());
   }
  }
  if (runtimeConfigProps.size() == 0) {
   return Optional.<Config>absent();
  }
  Config config = ConfigUtils.propertiesToConfig(runtimeConfigProps);
  return Optional.fromNullable(config);
 }
}

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

/**
 * @return an array of strings, made up of all the environment variables available in the VM, format var=value. To be
 *         used for Runtime.exec(cmd, envp)
 */
public static final String[] getEnvironmentVariablesForRuntimeExec() {
 Properties sysprops = new Properties();
 sysprops.putAll( getEnv() );
 sysprops.putAll( System.getProperties() );
 addInternalVariables( sysprops );
 String[] envp = new String[sysprops.size()];
 List<Object> list = new ArrayList<Object>( sysprops.keySet() );
 for ( int i = 0; i < list.size(); i++ ) {
  String var = (String) list.get( i );
  String val = sysprops.getProperty( var );
  envp[i] = var + "=" + val;
 }
 return envp;
}

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

/**
 * Creates a new PropertiesExpander.
 * @param properties the underlying properties to use for
 *     property resolution.
 * @throws IllegalArgumentException indicates null was passed
 */
public PropertiesExpander(Properties properties) {
  if (properties == null) {
    throw new IllegalArgumentException("cannot pass null");
  }
  values = new HashMap<>(properties.size());
  for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
    final String name = (String) e.nextElement();
    values.put(name, properties.getProperty(name));
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void start() {
  if (dataSourceName == null || dataSourceName.equals("")) {
    Log.error("No name specified for DataSource. JNDI lookup will fail", new Throwable());
    return;
  }
  try {
    Properties contextProperties = new Properties();
    for (String key: jndiPropertyKeys) {
      String value = JiveGlobals.getXMLProperty(key);
      if (value != null) {
        contextProperties.setProperty(key, value);
      }
    }
    Context context;
    if (contextProperties.size() > 0) {
      context = new InitialContext(contextProperties);
    }
    else {
      context = new InitialContext();
    }
    dataSource = (DataSource)context.lookup(dataSourceName);
  }
  catch (Exception e) {
    Log.error("Could not lookup DataSource at '" + dataSourceName + "'", e);
  }
}

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

@Test
public void testPropertiesToConfiguration() {
  final Properties properties = new Properties();
  final int entries = 10;
  for (int i = 0; i < entries; i++) {
    properties.setProperty("key" + i, "value" + i);
  }
  final Configuration configuration = ConfigurationUtils.createConfiguration(properties);
  for (String key : properties.stringPropertyNames()) {
    assertThat(configuration.getString(key, ""), is(equalTo(properties.getProperty(key))));
  }
  assertThat(configuration.toMap().size(), is(properties.size()));
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Resolve the given interface mappings, turning class names into Class objects.
 * @param mappings the specified interface mappings
 * @return the resolved interface mappings (with Class objects as values)
 */
private Map<String, Class<?>[]> resolveInterfaceMappings(Properties mappings) {
  Map<String, Class<?>[]> resolvedMappings = new HashMap<>(mappings.size());
  for (Enumeration<?> en = mappings.propertyNames(); en.hasMoreElements();) {
    String beanKey = (String) en.nextElement();
    String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
    Class<?>[] classes = resolveClassNames(classNames, beanKey);
    resolvedMappings.put(beanKey, classes);
  }
  return resolvedMappings;
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public static <T> T createPropertiesConfiguration(Class<T> clazz, String[] locations) {
    if (clazz == null) {
      throw new IllegalArgumentException("clazz should not be null");
    }
    if (!clazz.isAnnotationPresent(ConfigurationProperties.class)) {
      throw new IllegalArgumentException(clazz.getName() + " must annotation with @" + ConfigurationProperties.class.getName());
    }
    if (locations == null || locations.length == 0) {
      throw new IllegalArgumentException(clazz.getName() + " must specified the properties locations");
    }
    Properties properties = new Properties();
    for (String location : locations) {
      try {
        properties.load(PropertiesConfigurationFactory.class.getClassLoader().getResourceAsStream(location.trim()));
      } catch (IOException e) {
        throw new IllegalStateException("Load properties [" + location + "] error", e);
      }
    }
    Map<String, String> map = new HashMap<String, String>(properties.size());
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
      String key = entry.getKey().toString();
      String value = entry.getValue() == null ? null : entry.getValue().toString();
      if (value != null) {
        map.put(key, value);
      }
    }
    return createPropertiesConfiguration(clazz, map);
  }
}

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

@Test
 public void testMonkeyPropertiesParsing() {
  final Configuration conf = new Configuration(false);
  conf.set(MonkeyConstants.BATCH_RESTART_RS_RATIO, "0.85");
  conf.set(MonkeyConstants.MOVE_REGIONS_MAX_TIME, "60000");
  conf.set("hbase.rootdir", "/foo/bar/baz");

  final Properties props = new Properties();
  IntegrationTestBase testBase = new IntegrationTestDDLMasterFailover();
  assertEquals(0, props.size());
  testBase.loadMonkeyProperties(props, conf);
  assertEquals(2, props.size());
  assertEquals("0.85", props.getProperty(MonkeyConstants.BATCH_RESTART_RS_RATIO));
  assertEquals("60000", props.getProperty(MonkeyConstants.MOVE_REGIONS_MAX_TIME));
 }
}

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

/**
 * Create a new JNDI initial context. Invoked by {@link #execute}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 *
 * @return the initial Context instance
 * @throws NamingException in case of initialization errors
 */
@SuppressWarnings({"unchecked"})
protected Context createInitialContext() throws NamingException {
  Properties env = getEnvironment();
  Hashtable icEnv = null;
  if (env != null) {
    icEnv = new Hashtable(env.size());
    for (Enumeration en = env.propertyNames(); en.hasMoreElements();) {
      String key = (String) en.nextElement();
      icEnv.put(key, env.getProperty(key));
    }
  }
  return new InitialContext(icEnv);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public static <T> T createPropertiesConfiguration(Class<T> clazz, String[] locations) {
    if (clazz == null) {
      throw new IllegalArgumentException("clazz should not be null");
    }
    if (!clazz.isAnnotationPresent(ConfigurationProperties.class)) {
      throw new IllegalArgumentException(clazz.getName() + " must annotation with @" + ConfigurationProperties.class.getName());
    }
    if (locations == null || locations.length == 0) {
      throw new IllegalArgumentException(clazz.getName() + " must specified the properties locations");
    }
    Properties properties = new Properties();
    for (String location : locations) {
      try {
        properties.load(PropertiesConfigurationFactory.class.getClassLoader().getResourceAsStream(location.trim()));
      } catch (IOException e) {
        throw new IllegalStateException("Load properties [" + location + "] error", e);
      }
    }
    Map<String, String> map = new HashMap<String, String>(properties.size());
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
      String key = entry.getKey().toString();
      String value = entry.getValue() == null ? null : entry.getValue().toString();
      if (value != null) {
        map.put(key, value);
      }
    }
    return createPropertiesConfiguration(clazz, map);
  }
}

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

final Properties cacheAfterFirstRun = new Properties();
cacheAfterFirstRun.load(Files.newBufferedReader(cacheFile.toPath()));
final Properties cacheAfterSecondRun = new Properties();
cacheAfterSecondRun.load(Files.newBufferedReader(cacheFile.toPath()));
  cacheAfterFirstRun.getProperty(pathToEmptyFile),
  cacheAfterSecondRun.getProperty(pathToEmptyFile)
);
assertEquals(
    "Cache has changed its hash",
  cacheAfterFirstRun.getProperty(PropertyCacheFile.CONFIG_HASH_KEY),
  cacheAfterSecondRun.getProperty(PropertyCacheFile.CONFIG_HASH_KEY)
);
final int expectedNumberOfObjectsInCache = 2;
assertEquals("Number of items in cache differs from expected",
    expectedNumberOfObjectsInCache, cacheAfterFirstRun.size());
assertEquals("Number of items in cache differs from expected",
    expectedNumberOfObjectsInCache, cacheAfterSecondRun.size());

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

@Override
public void write(DataOutput out)
  throws IOException {
 out.writeInt(this.commonProperties.size() + this.specProperties.size());
 for (Object key : this.commonProperties.keySet()) {
  TextSerializer.writeStringAsText(out, (String) key);
  TextSerializer.writeStringAsText(out, this.commonProperties.getProperty((String) key));
 }
 for (Object key : this.specProperties.keySet()) {
  TextSerializer.writeStringAsText(out, (String) key);
  TextSerializer.writeStringAsText(out, this.specProperties.getProperty((String) key));
 }
}

代码示例来源:origin: alibaba/druid

@SuppressWarnings("rawtypes")
public void setConnectProperties(Properties properties) {
  if (properties == null) {
    properties = new Properties();
  if (properties.size() == this.connectProperties.size()) {
    equals = true;
    for (Map.Entry entry : properties.entrySet()) {

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testGetRestartJobParametersWithDefaults() {
  JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator;
  JobExecution jobExecution = new JobExecution(1L,
      new JobParametersBuilder().addString("prevKey1", "prevVal1").addString("prevKey2", "prevVal2").toJobParameters());
  Properties defaultProperties = new Properties();
  defaultProperties.setProperty("prevKey2", "not value 2");
  Properties userProperties = new Properties(defaultProperties);
  Properties properties = jobOperator.getJobRestartProperties(userProperties, jobExecution);
  assertTrue(properties.size() == 2);
  assertTrue(properties.getProperty("prevKey1").equals("prevVal1"));
  assertTrue("prevKey2 = " + properties.getProperty("prevKey2"), properties.getProperty("prevKey2").equals("not value 2"));
}

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

public static Config fromProperties(Properties properties) {
 if (properties == null || properties.size() == 0) return null;
 return new Implementation(
   parseSdkArrayProperty(properties.getProperty("sdk", "")),
   parseSdkInt(properties.getProperty("minSdk", "-1")),
   parseSdkInt(properties.getProperty("maxSdk", "-1")),
   properties.getProperty("manifest", DEFAULT_VALUE_STRING),
   properties.getProperty("qualifiers", DEFAULT_QUALIFIERS),
   properties.getProperty("packageName", DEFAULT_PACKAGE_NAME),
   properties.getProperty("resourceDir", DEFAULT_RES_FOLDER),
   properties.getProperty("assetDir", DEFAULT_ASSET_FOLDER),
   parseClasses(properties.getProperty("shadows", "")),
   parseStringArrayProperty(properties.getProperty("instrumentedPackages", "")),
   parseApplication(
     properties.getProperty("application", DEFAULT_APPLICATION.getCanonicalName())),
   parseStringArrayProperty(properties.getProperty("libraries", "")));
}

相关文章

微信公众号

最新文章

更多