Java Code Examples for java.util.Properties#size()
The following examples show how to use
java.util.Properties#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static void readMessages () { messages = new Properties (); Enumeration fileList = msgFiles.elements (); DataInputStream stream; while (fileList.hasMoreElements ()) try { stream = FileLocator.locateLocaleSpecificFileInClassPath ((String)fileList.nextElement ()); messages.load (stream); } catch (IOException e) { } if (messages.size () == 0) messages.put (defaultKey, "Error reading Messages File."); }
Example 2
Source File: CoreStorageModelProvider.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
@Override protected CoreServiceModel loadWriteModel ( final StorageContext context ) throws Exception { final Properties p = new Properties (); try ( Reader reader = Files.newBufferedReader ( makePath ( context ) ) ) { p.load ( reader ); } catch ( final NoSuchFileException e ) { // simply ignore } // now convert to a hash set final Map<MetaKey, String> result = new HashMap<> ( p.size () ); for ( final String key : p.stringPropertyNames () ) { final MetaKey metaKey = MetaKey.fromString ( key ); result.put ( metaKey, p.getProperty ( key ) ); } return new CoreServiceModel ( result ); }
Example 3
Source File: ClientConnection.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * <code>setClientInfo</code> will throw a <code>SQLClientInfoException</code> * uless the <code>properties</code> paramenter is empty, since GemFireXD does * not support any properties. */ @Override public void setClientInfo(Properties properties) throws SQLClientInfoException { if (properties != null && !properties.isEmpty()) { HashMap<String, ClientInfoStatus> failedProperties = new HashMap<String, ClientInfoStatus>(properties.size()); String firstKey = null; for (String key : properties.stringPropertyNames()) { if (firstKey == null) { firstKey = key; } failedProperties.put(key, ClientInfoStatus.REASON_UNKNOWN_PROPERTY); } throw ThriftExceptionUtil.newSQLClientInfoException( SQLState.PROPERTY_UNSUPPORTED_CHANGE, failedProperties, null, firstKey, properties.getProperty(firstKey)); } }
Example 4
Source File: FD.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { String str; super.setProperties(props); str=props.getProperty("timeout"); if(str != null) { timeout=Long.parseLong(str); props.remove("timeout"); } if(props.size() > 0) { log.error(ExternalStrings.FD_FDSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } return true; }
Example 5
Source File: COMPRESS.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { String str; super.setProperties(props); str=props.getProperty("compression_level"); if(str != null) { compression_level=Integer.parseInt(str); props.remove("compression_level"); } str=props.getProperty("min_size"); if(str != null) { min_size=Long.parseLong(str); props.remove("min_size"); } if(props.size() > 0) { log.error(ExternalStrings.COMPRESS_COMPRESSSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } return true; }
Example 6
Source File: COMPRESS.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { String str; super.setProperties(props); str=props.getProperty("compression_level"); if(str != null) { compression_level=Integer.parseInt(str); props.remove("compression_level"); } str=props.getProperty("min_size"); if(str != null) { min_size=Long.parseLong(str); props.remove("min_size"); } if(props.size() > 0) { log.error(ExternalStrings.COMPRESS_COMPRESSSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } return true; }
Example 7
Source File: BaseMessage.java From sakai with Educational Community License v2.0 | 5 votes |
/** * try to add synoptic options for this tool to the archive, if they exist * @param siteId * @param doc * @param element */ public void archiveSynopticOptions(String siteId, Document doc, Element element) { try { // archive the synoptic tool options Site site = m_siteService.getSite(siteId); ToolConfiguration synTool = site.getToolForCommonId("sakai.synoptic." + getLabel()); Properties synProp = synTool.getPlacementConfig(); if (synProp != null && synProp.size() > 0) { Element synElement = doc.createElement(SYNOPTIC_TOOL); Element synProps = doc.createElement(PROPERTIES); Set synPropSet = synProp.keySet(); Iterator propIter = synPropSet.iterator(); while (propIter.hasNext()) { String propName = (String)propIter.next(); Element synPropEl = doc.createElement(PROPERTY); synPropEl.setAttribute(NAME, propName); synPropEl.setAttribute(VALUE, synProp.getProperty(propName)); synProps.appendChild(synPropEl); } synElement.appendChild(synProps); element.appendChild(synElement); } } catch (Exception e) { log.warn("archive: exception archiving synoptic options for service: " + serviceName()); } }
Example 8
Source File: Wizard.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
void compareSimulatorProperties() { SimulatorProperties defaultProperties = new SimulatorProperties(); String defaultPropertiesString = defaultProperties.getDefaultsAsString(); Properties userProperties = WizardUtils.getUserProperties(); int size = userProperties.size(); if (size == 0) { echo(format("Found no %s file or file was empty!", SimulatorProperties.PROPERTIES_FILE_NAME)); return; } echo("Defined user properties:"); int unknownProperties = 0; int changedProperties = 0; for (String property : new TreeSet<>(userProperties.stringPropertyNames())) { boolean commentedOutProperty = containsCommentedOutProperty(defaultPropertiesString, property); String userValue = userProperties.getProperty(property); String defaultValue = (commentedOutProperty ? getCommentedOutProperty(defaultPropertiesString, property) : defaultProperties.get(property)); if (!defaultProperties.containsKey(property) && !commentedOutProperty) { echo("%s = %s [unknown property]", property, userValue); unknownProperties++; } else if (!userValue.equals(defaultValue)) { echo("%s = %s [default: %s]", property, userValue, defaultValue); changedProperties++; } else { echo("%s = %s", property, userValue); } } logResults(size, unknownProperties, changedProperties); }
Example 9
Source File: ShowLocationActivity.java From PocketMaps with MIT License | 5 votes |
private boolean checkLocationParameters(Properties prop) { if (prop.size() == 0) { return false; } if (prop.get("q") != null) { return true; } if (prop.get("lat") == null) { return false; } if (prop.get("lon") == null) { return false; } return true; }
Example 10
Source File: BusEntityResolver.java From cxf with Apache License 2.0 | 5 votes |
public BusEntityResolver(ClassLoader loader, EntityResolver dr, EntityResolver sr) { super(dr, sr); classLoader = loader; dtdResolver = dr; schemaResolver = sr; try { Properties mappings = PropertiesLoaderUtils.loadAllProperties("META-INF/spring.schemas", classLoader); schemaMappings = new ConcurrentHashMap<>(mappings.size()); CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings); } catch (IOException e) { //ignore } }
Example 11
Source File: DefaultNamespaceHandlerResolver.java From java-technology-stack with MIT License | 5 votes |
/** * Load the specified NamespaceHandler mappings lazily. */ private Map<String, Object> getHandlerMappings() { Map<String, Object> handlerMappings = this.handlerMappings; if (handlerMappings == null) { synchronized (this) { handlerMappings = this.handlerMappings; if (handlerMappings == null) { if (logger.isTraceEnabled()) { logger.trace("Loading NamespaceHandler mappings from [" + this.handlerMappingsLocation + "]"); } try { Properties mappings = PropertiesLoaderUtils.loadAllProperties(this.handlerMappingsLocation, this.classLoader); if (logger.isTraceEnabled()) { logger.trace("Loaded NamespaceHandler mappings: " + mappings); } handlerMappings = new ConcurrentHashMap<>(mappings.size()); CollectionUtils.mergePropertiesIntoMap(mappings, handlerMappings); this.handlerMappings = handlerMappings; } catch (IOException ex) { throw new IllegalStateException( "Unable to load NamespaceHandler mappings from location [" + this.handlerMappingsLocation + "]", ex); } } } } return handlerMappings; }
Example 12
Source File: STATE_TRANSFER.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { String str; super.setProperties(props); // Milliseconds to wait for application to provide requested state, events are // STATE_TRANSFER up and STATE_TRANSFER_OK down str=props.getProperty("timeout_get_appl_state"); if(str != null) { timeout_get_appl_state=Long.parseLong(str); props.remove("timeout_get_appl_state"); } // Milliseconds to wait for 1 or all members to return its/their state. 0 means wait // forever. States are retrieved using GroupRequest/RequestCorrelator str=props.getProperty("timeout_return_state"); if(str != null) { timeout_return_state=Long.parseLong(str); props.remove("timeout_return_state"); } if(props.size() > 0) { log.error(ExternalStrings.STATE_TRANSFER_STATE_TRANSFERSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } return true; }
Example 13
Source File: STATE_TRANSFER.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { super.setProperties(props); if(props.size() > 0) { log.error(ExternalStrings.STATE_TRANSFER_STATE_TRANSFERSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } return true; }
Example 14
Source File: STATE_TRANSFER.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { String str; super.setProperties(props); // Milliseconds to wait for application to provide requested state, events are // STATE_TRANSFER up and STATE_TRANSFER_OK down str=props.getProperty("timeout_get_appl_state"); if(str != null) { timeout_get_appl_state=Long.parseLong(str); props.remove("timeout_get_appl_state"); } // Milliseconds to wait for 1 or all members to return its/their state. 0 means wait // forever. States are retrieved using GroupRequest/RequestCorrelator str=props.getProperty("timeout_return_state"); if(str != null) { timeout_return_state=Long.parseLong(str); props.remove("timeout_return_state"); } if(props.size() > 0) { log.error(ExternalStrings.STATE_TRANSFER_STATE_TRANSFERSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } return true; }
Example 15
Source File: ReCaptchaImpl.java From live-chat-engine with Apache License 2.0 | 5 votes |
/** * Produces javascript array with the RecaptchaOptions encoded. * * @param properties * @return */ @SuppressWarnings("rawtypes") private String fetchJSOptions(Properties properties) { if (properties == null || properties.size() == 0) { return ""; } String jsOptions = "<script type=\"text/javascript\">\r\n" + "var RecaptchaOptions = {"; for (Enumeration e = properties.keys(); e.hasMoreElements(); ) { String property = (String) e.nextElement(); jsOptions += property + ":'" + properties.getProperty(property)+"'"; if (e.hasMoreElements()) { jsOptions += ","; } } jsOptions += "};\r\n</script>\r\n"; return jsOptions; }
Example 16
Source File: InterfaceBasedMBeanInfoAssembler.java From spring-analysis-note with MIT License | 5 votes |
/** * 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; }
Example 17
Source File: PathUtils.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Convert a Properties object to an array of "key=value" -Strings. * * @param prop key/value -mappings as properties * @return an array of "key=value" -Strings. */ public static String[] getStrings(Properties prop) { String[] env = new String[prop.size()]; int i = 0; Enumeration<Object> enumeration = prop.keys(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); env[i++] = key + '=' + prop.getProperty(key); } return env; }
Example 18
Source File: PropertyUtil.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Sorts property list and print out each key=value pair prepended with * specific indentation. If indent is null, do not prepend with * indentation. * * The output string shows up in two styles, style 1 looks like * { key1=value1, key2=value2, key3=value3 } * * style 2 looks like * key1=value1 * key2=value2 * key3=value3 * where indent goes between the new line and the keys * * To get style 1, pass in a null indent * To get sytle 2, pass in non-null indent (whatever you want to go before * the key value) */ public static String sortProperties( Properties list, String indent ) { int size = list == null ? 0 : list.size(); int count = 0; String[] array = new String[size]; String key; String value; StringBuilder buffer; // Calculate the number of properties in the property list and // build an array of all the property names. // We need to go thru the enumeration because Properties has a // recursive list of defaults. if (list != null) { for (Enumeration propertyNames = list.propertyNames(); propertyNames.hasMoreElements(); ) { if (count == size) { // need to expand the array size = size*2; String[] expandedArray = new String[size]; System.arraycopy(array, 0, expandedArray, 0, count); array = expandedArray; } key = (String) propertyNames.nextElement(); array[ count++ ] = key; } // now sort the array java.util.Arrays.sort(array, 0, count); } // now stringify the array buffer = new StringBuilder(); if (indent == null) buffer.append( "{ " ); for ( int ictr = 0; ictr < count; ictr++ ) { if ( ictr > 0 && indent == null) buffer.append( ", " ); key = array[ ictr ]; if (indent != null) buffer.append( indent ); buffer.append( key ); buffer.append( "=" ); value = list.getProperty( key, "MISSING_VALUE" ); buffer.append( value ); if (indent != null) buffer.append( "\n" ); } if (indent == null) buffer.append( " }" ); return buffer.toString(); }
Example 19
Source File: FC.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
@Override // GemStoneAddition public boolean setProperties(Properties props) { String str; boolean min_credits_set=false; super.setProperties(props); str=props.getProperty("max_credits"); if(str != null) { max_credits=Long.parseLong(str); props.remove("max_credits"); } str=props.getProperty("min_threshold"); if(str != null) { min_threshold=Double.parseDouble(str); props.remove("min_threshold"); } str=props.getProperty("min_credits"); if(str != null) { min_credits=Long.parseLong(str); props.remove("min_credits"); min_credits_set=true; } if(!min_credits_set) min_credits=(long)(/*(double) GemStoneAddition */max_credits * min_threshold); str=props.getProperty("max_block_time"); if(str != null) { max_block_time=Long.parseLong(str); props.remove("max_block_time"); } if(props.size() > 0) { log.error(ExternalStrings.FC_FCSETPROPERTIES_THE_FOLLOWING_PROPERTIES_ARE_NOT_RECOGNIZED__0, props); return false; } max_credits_constant=Long.valueOf(max_credits); return true; }
Example 20
Source File: JdbcRepositoryProvider.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
@Override public void configurationChanged() { LOG.info("Begin JdbcRepository reconfiguring."); JdbcRepositoryContext oldRepoContext = repoContext; repoContext = new JdbcRepositoryContext(SqoopConfiguration.getInstance().getContext()); // reconfigure jdbc handler String newJdbcHandlerClassName = repoContext.getHandlerClassName(); if (newJdbcHandlerClassName == null || newJdbcHandlerClassName.trim().length() == 0) { throw new SqoopException(RepositoryError.JDBCREPO_0001, newJdbcHandlerClassName); } String oldJdbcHandlerClassName = oldRepoContext.getHandlerClassName(); if (!newJdbcHandlerClassName.equals(oldJdbcHandlerClassName)) { LOG.warn("Repository JDBC handler cannot be replaced at the runtime. " + "You might need to restart the server."); } // reconfigure jdbc driver String newJdbcDriverClassName = repoContext.getDriverClass(); if (newJdbcDriverClassName == null || newJdbcDriverClassName.trim().length() == 0) { throw new SqoopException(RepositoryError.JDBCREPO_0003, newJdbcDriverClassName); } String oldJdbcDriverClassName = oldRepoContext.getDriverClass(); if (!newJdbcDriverClassName.equals(oldJdbcDriverClassName)) { LOG.warn("Repository JDBC driver cannot be replaced at the runtime. " + "You might need to restart the server."); } // reconfigure max connection connectionPool.setMaxActive(repoContext.getMaximumConnections()); // reconfigure the url of repository String connectUrl = repoContext.getConnectionUrl(); String oldurl = oldRepoContext.getConnectionUrl(); if (connectUrl != null && !connectUrl.equals(oldurl)) { LOG.warn("Repository URL cannot be replaced at the runtime. " + "You might need to restart the server."); } // if connection properties or transaction isolation option changes boolean connFactoryChanged = false; // compare connection properties if (!connFactoryChanged) { Properties oldProp = oldRepoContext.getConnectionProperties(); Properties newProp = repoContext.getConnectionProperties(); if (newProp.size() != oldProp.size()) { connFactoryChanged = true; } else { for (Object key : newProp.keySet()) { if (!newProp.getProperty((String) key).equals(oldProp.getProperty((String) key))) { connFactoryChanged = true; break; } } } } // compare the transaction isolation option if (!connFactoryChanged) { String oldTxOption = oldRepoContext.getTransactionIsolation().toString(); String newTxOption = repoContext.getTransactionIsolation().toString(); if (!newTxOption.equals(oldTxOption)) { connFactoryChanged = true; } } if (connFactoryChanged) { // try to reconfigure connection factory try { LOG.info("Reconfiguring Connection Factory."); Properties jdbcProps = repoContext.getConnectionProperties(); ConnectionFactory connFactory = new DriverManagerConnectionFactory(connectUrl, jdbcProps); new PoolableConnectionFactory(connFactory, connectionPool, statementPool, handler.validationQuery(), false, false, repoContext.getTransactionIsolation().getCode()); } catch (IllegalStateException ex) { // failed to reconfigure connection factory LOG.warn("Repository connection cannot be reconfigured currently. " + "You might need to restart the server."); } } // ignore the create schema option, because the repo url is not allowed to change LOG.info("JdbcRepository reconfigured."); }