Java Code Examples for java.util.Properties#entrySet()
The following examples show how to use
java.util.Properties#entrySet() .
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: ContentTypes.java From config-toolkit with Apache License 2.0 | 6 votes |
private ContentTypes() { try { Properties props = new Properties(); // Load register file contents Enumeration<URL> registerFiles = this.getClass().getClassLoader().getResources(REGISTER_FILE); URL registerFile = null; while (registerFiles.hasMoreElements()) { registerFile = registerFiles.nextElement(); try (InputStream in = registerFile.openStream()) { props.load(in); } } // Initialize protocol beans contentTypes = new HashMap<>(); for (Map.Entry<Object, Object> entry : props.entrySet()) { final String contentTypeName = ((String) entry.getKey()).toLowerCase(); @SuppressWarnings("unchecked") final Class<ContentType> contentTypeBeanClazz = (Class<ContentType>) Class.forName((String) entry.getValue()); contentTypes.put(contentTypeName, contentTypeBeanClazz); } } catch (Exception e) { throw new RuntimeException(e); } }
Example 2
Source File: PropertiesUtils.java From lemon with Apache License 2.0 | 6 votes |
public static void bindProperties(Object object, Properties properties, String prefix) { if (properties == null) { throw new IllegalArgumentException( "there is no properties setting."); } logger.debug("prefix : {}", prefix); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (!key.startsWith(prefix)) { continue; } String propertyName = key.substring(prefix.length()); tryToSetProperty(object, propertyName, value); } }
Example 3
Source File: KylinConfig.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
public String exportToString(Collection<String> propertyKeys) { Properties filteredProps = getProperties(propertyKeys); OrderedProperties orderedProperties = KylinConfig.buildSiteOrderedProps(); for (String key : propertyKeys) { if (!filteredProps.containsKey(key)) { filteredProps.put(key, orderedProperties.getProperty(key, "")); } } final StringBuilder sb = new StringBuilder(); for (Map.Entry<Object, Object> entry : filteredProps.entrySet()) { sb.append(entry.getKey() + "=" + entry.getValue()).append('\n'); } return sb.toString(); }
Example 4
Source File: InfrastructureParameter.java From testgrid with Apache License 2.0 | 6 votes |
/** * Processes the {@link #properties} field, and generate a list of sub infrastructure parameters. * * @return list of sub infra parameters */ public Properties getSubProperties() { try { Properties properties = new Properties(); String propertiesStr = this.getProperties(); properties.load(new StringReader(propertiesStr)); //Remove if invalid properties found for (Map.Entry entry : properties.entrySet()) { String name = (String) entry.getValue(); String type = (String) entry.getKey(); String regex = "[\\w,-\\.@:]*"; if (type.isEmpty() || !type.matches(regex) || name.isEmpty() || !name.matches(regex)) { properties.remove(type, name); } } return properties; } catch (IOException e) { logger.warn("Error while loading the infrastructure parameter's properties string for: " + this); } return null; }
Example 5
Source File: EjbTimerServiceImpl.java From tomee with Apache License 2.0 | 6 votes |
private static int putAll(final Properties a, final Properties b) { int number = 0; for (final Map.Entry<Object, Object> entry : b.entrySet()) { final String key = entry.getKey().toString(); if (key.startsWith("org.quartz.") || key.startsWith("org.apache.openejb.quartz.") || key.startsWith("openejb.quartz.") || DefaultTimerThreadPoolAdapter.OPENEJB_TIMER_POOL_SIZE.equals(key) || "org.terracotta.quartz.skipUpdateCheck".equals(key)) { number++; } final Object value = entry.getValue(); if (String.class.isInstance(value)) { if (!key.startsWith("org.quartz")) { a.put(key, value); } else { a.put("org.apache.openejb.quartz" + key.substring("org.quartz".length()), value); } } } return number; }
Example 6
Source File: EnvUtils.java From sofa-lookout with Apache License 2.0 | 5 votes |
public static Map<String, Object> getPropertySubView(String prefix, Properties properties) { if (prefix == null) { return Collections.emptyMap(); } Map<String, Object> map = new HashMap<>(); for (Map.Entry<Object, Object> e : properties.entrySet()) { String key = e.getKey().toString(); if (key.startsWith(prefix)) { map.put(key.substring(prefix.length()), e.getValue().toString()); } } return map; }
Example 7
Source File: MynlpSegmenterFactoryTestCase.java From jstarcraft-nlp with Apache License 2.0 | 5 votes |
@Override protected NlpSegmentFactory getSegmenterFactory() throws Exception { Properties keyValues = new Properties(); keyValues.load(this.getClass().getResourceAsStream("mynlp.properties")); Map<String, String> configurations = new LinkedHashMap<>(); for (Entry<Object, Object> keyValue : keyValues.entrySet()) { String key = String.valueOf(keyValue.getKey()); String value = String.valueOf(keyValue.getValue()); configurations.put(key, value); } MynlpSegmentFactory factory = new MynlpSegmentFactory(configurations); return factory; }
Example 8
Source File: LocalizationUtilIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testImportedLocaleIntoDomainWithSameLocale() throws Exception { // this test exercises all known places where localized strings are located String locale = "en_US"; XmiParser parser = new XmiParser(); Domain domain = null; domain = parser.parseXmi( getClass().getResourceAsStream( "/modelWith_EN_US.xmi" ) ); LocalizationUtil util = new LocalizationUtil(); // Load the properties from the exported properties file Properties exportedPropertyFileProps = new Properties(); exportedPropertyFileProps.load( getClass().getResourceAsStream( "/modelWith_EN_US_en_US.properties" ) ); // import the properties into the domain util.importLocalizedProperties( domain, exportedPropertyFileProps, locale ); // Out imported localization will have the string "en_US" before each non empty string. // take the printing of all the properties out before checking in Properties en_US_FromDomain = util.exportLocalizedProperties( domain, locale ); for ( Entry<Object, Object> entry : en_US_FromDomain.entrySet() ) { System.out.println( entry.getKey().toString() + " => " + entry.getValue().toString() ); } assertEquals( "en_US Num children at home", en_US_FromDomain .get( "[IPhysicalModel-foodmart].[PT_CUSTOMER].[num_children_at_home].[name]" ) ); }
Example 9
Source File: ManagedSEDeployableContainer.java From camel-spring-boot with Apache License 2.0 | 5 votes |
private List<String> buildProcessCommand(Properties properties) { final List<String> command = new ArrayList<>(); final File javaHome = new File(System.getProperty(SYSPROP_KEY_JAVA_HOME)); command.add(javaHome.getAbsolutePath() + File.separator + "bin" + File.separator + "java"); if (getJavaMajorVersion() >= 9) { command.add("--add-modules"); command.add("java.sql"); } command.add("-cp"); StringBuilder builder = new StringBuilder(); Set<File> classPathEntries = new HashSet<>(materializedFiles); classPathEntries.addAll(classpathDependencies); for (Iterator<File> iterator = classPathEntries.iterator(); iterator.hasNext();) { builder.append(iterator.next().getPath()); if (iterator.hasNext()) { builder.append(File.pathSeparator); } } command.add(builder.toString()); command.add("-Dcom.sun.management.jmxremote"); command.add("-Dcom.sun.management.jmxremote.port=" + port); command.add("-Dcom.sun.management.jmxremote.authenticate=false"); command.add("-Dcom.sun.management.jmxremote.ssl=false"); if (debugModeEnabled) { command.add(DEBUG_AGENT_STRING); } for (String option : additionalJavaOpts) { command.add(option); } if (properties != null) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { addSystemProperty(command, entry.getKey().toString(), entry.getValue().toString()); } } command.add(SERVER_MAIN_CLASS_FQN); return command; }
Example 10
Source File: PropertyHelper.java From marathonv5 with Apache License 2.0 | 5 votes |
public static String toCSS(Properties properties) { Entry<Object, Object> typeProperty = null; Entry<Object, Object> indexProperty = null; Entry<Object, Object> tagNameProperty = null; StringBuilder sb = new StringBuilder(); Set<Entry<Object, Object>> entries = properties.entrySet(); for (Entry<Object, Object> entry : entries) { if (entry.getKey().equals("type")) { typeProperty = entry; } else if (entry.getKey().equals("indexOfType")) { indexProperty = entry; } else if (entry.getKey().equals("tagName")) { tagNameProperty = entry; } else { String value = entry.getValue().toString(); value = value.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'"); sb.append("[").append(entry.getKey().toString()).append("=").append("'").append(value).append("']"); } } String r = sb.toString(); if (tagNameProperty != null) { r = tagNameProperty.getValue().toString(); } if (typeProperty != null) { r = "[" + typeProperty.getKey().toString() + "=" + "'" + typeProperty.getValue().toString() + "']" + sb.toString(); } if (indexProperty != null) { int index = Integer.parseInt(indexProperty.getValue().toString()); r = r + ":nth(" + (index + 1) + ")"; } return r; }
Example 11
Source File: StringSubstitution.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public void addAdditionalStringSubstitutionVariables(Properties stringSubstitutionVariables) { if (stringSubstitutionVariables != null) { if (variableSubstitution == null) { variableSubstitution = new HashMap<>(); } Set<Entry<Object, Object>> entrySet = stringSubstitutionVariables.entrySet(); for (Entry<Object, Object> entry : entrySet) { variableSubstitution.put(entry.getKey().toString(), entry.getValue().toString()); } } }
Example 12
Source File: SimpleXmlEncoder.java From metafacture-core with Apache License 2.0 | 5 votes |
public void setNamespaceFile(final String file) { final Properties properties; try { properties = ResourceUtil.loadProperties(file); } catch (IOException e) { throw new MetafactureException("Failed to load namespaces list", e); } for (final Entry<Object, Object> entry : properties.entrySet()) { namespaces.put(entry.getKey().toString(), entry.getValue().toString()); } }
Example 13
Source File: SlimConfigurationProcessor.java From spring-init with Apache License 2.0 | 5 votes |
public void loadState() { Properties properties = new Properties(); try { FileObject resource = filer.getResource(StandardLocation.CLASS_OUTPUT, "", SLIM_STATE_PATH); try (InputStream stream = resource.openInputStream();) { properties.load(stream); } messager.printMessage(Kind.NOTE, "Loading imports information from previous build:" + properties); for (Map.Entry<Object, Object> property : properties.entrySet()) { String annotationType = (String) property.getKey(); // registrarinitializer.XXXX.YYY.ZZZ String k = annotationType.substring("import.".length()); TypeElement kte = utils.asTypeElement(k); for (String v : ((String) property.getValue()).split(",")) { TypeElement vte = utils.asTypeElement(v); if (kte == null || vte == null) { // TODO need to cope with types being removed across incremental // builds - is this ok? messager.printMessage(Kind.NOTE, "Looks like a type has been removed, ignoring registrar entry " + k + "=" + v + " resolved to " + kte + "=" + vte); } else { imports.addImport(kte, vte); } } } messager.printMessage(Kind.NOTE, "Loaded " + properties.size() + " import definitions"); } catch (IOException e) { messager.printMessage(Kind.NOTE, "Cannot load " + SLIM_STATE_PATH + " (normal on first full build)"); } }
Example 14
Source File: XulDatabaseDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private IDatabaseConnection getData() { if ( this.meta == null ) { return null; } final DatabaseConnection connection = new DatabaseConnection(); connection.setAccessType( convertAccessTypeFromKettle( meta.getAccessType() ) ); final Properties attributes = meta.getAttributes(); for ( final Map.Entry e : attributes.entrySet() ) { connection.getAttributes().put( (String) e.getKey(), (String) e.getValue() ); } connection.setUsername( meta.getUsername() ); connection.setPassword( meta.getPassword() ); connection.setName( meta.getName() ); connection.setId( id ); connection.setDataTablespace( meta.getDataTablespace() ); connection.setDatabaseName( meta.getDatabaseName() ); connection.setDatabasePort( meta.getDatabasePortNumberString() ); connection.setHostname( meta.getHostname() ); connection.setIndexTablespace( meta.getIndexTablespace() ); connection.setInformixServername( meta.getServername() ); final String shortName = meta.getDatabaseInterface().getPluginId(); connection.setDatabaseType( databaseTypeHelper.getDatabaseTypeByShortName( shortName ) ); connection.getAttributes().put( "_kettle_native_plugin_id", shortName ); return connection; }
Example 15
Source File: FileController.java From oneplatform with Apache License 2.0 | 5 votes |
@Override public void afterPropertiesSet() throws Exception { Properties properties = ResourceUtils.getAllProperties(); Set<Entry<Object, Object>> entrySet = properties.entrySet(); for (Entry<Object, Object> entry : entrySet) { if(entry.getKey().toString().endsWith(".filesystem.provider")){ uploadGroups.add(entry.getKey().toString().split("\\.")[0]); if(!uploadProviders.contains(entry.getValue().toString()))uploadProviders.add(entry.getValue().toString()); } } }
Example 16
Source File: DatabaseMetaReadHandler.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected void doneParsing() throws SAXException { if ( propertiesReadHandler == null ) { return; } final Properties result = propertiesReadHandler.getResult(); for ( final Map.Entry<Object, Object> entry : result.entrySet() ) { final String code = (String) entry.getKey(); final String attribute = (String) entry.getValue(); databaseConnection.getAttributes().put( code, ( attribute == null || attribute.length() == 0 ) ? "" : attribute ); //$NON-NLS-1$ } }
Example 17
Source File: Settings.java From rtc2jira with GNU General Public License v2.0 | 5 votes |
void setProperties(Properties props) { for (Entry<Object, Object> entry : props.entrySet()) { if (entry.getValue() != null) { entry.setValue(entry.getValue().toString().trim()); } } this.props = props; }
Example 18
Source File: BasicConnectorPropertyFactory.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
public T merge(Properties properties) { Set<Map.Entry<Object, Object>> set = properties.entrySet(); connectorProps.putAll(set.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b)->b))); return (T) this; }
Example 19
Source File: HQuorumPeer.java From hbase with Apache License 2.0 | 4 votes |
static void writeMyID(Properties properties) throws IOException { long myId = -1; Configuration conf = HBaseConfiguration.create(); String myAddress = Strings.domainNamePointerToHostName(DNS.getDefaultHost( conf.get("hbase.zookeeper.dns.interface","default"), conf.get("hbase.zookeeper.dns.nameserver","default"))); List<String> ips = new ArrayList<>(); // Add what could be the best (configured) match ips.add(myAddress.contains(".") ? myAddress : StringUtils.simpleHostname(myAddress)); // For all nics get all hostnames and IPs Enumeration<?> nics = NetworkInterface.getNetworkInterfaces(); while(nics.hasMoreElements()) { Enumeration<?> rawAdrs = ((NetworkInterface)nics.nextElement()).getInetAddresses(); while(rawAdrs.hasMoreElements()) { InetAddress inet = (InetAddress) rawAdrs.nextElement(); ips.add(StringUtils.simpleHostname(inet.getHostName())); ips.add(inet.getHostAddress()); } } for (Entry<Object, Object> entry : properties.entrySet()) { String key = entry.getKey().toString().trim(); String value = entry.getValue().toString().trim(); if (key.startsWith("server.")) { int dot = key.indexOf('.'); long id = Long.parseLong(key.substring(dot + 1)); String[] parts = value.split(":"); String address = parts[0]; if (addressIsLocalHost(address) || ips.contains(address)) { myId = id; break; } } } // Set the max session timeout from the provided client-side timeout properties.setProperty("maxSessionTimeout", conf.get(HConstants.ZK_SESSION_TIMEOUT, Integer.toString(HConstants.DEFAULT_ZK_SESSION_TIMEOUT))); if (myId == -1) { throw new IOException("Could not find my address: " + myAddress + " in list of ZooKeeper quorum servers"); } String dataDirStr = properties.get("dataDir").toString().trim(); File dataDir = new File(dataDirStr); if (!dataDir.isDirectory()) { if (!dataDir.mkdirs()) { throw new IOException("Unable to create data dir " + dataDir); } } File myIdFile = new File(dataDir, "myid"); PrintWriter w = new PrintWriter(myIdFile, StandardCharsets.UTF_8.name()); w.println(myId); w.close(); }
Example 20
Source File: PropertiesToStringConverter.java From geekbang-lessons with Apache License 2.0 | 3 votes |
@Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { Properties properties = (Properties) source; StringBuilder textBuilder = new StringBuilder(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { textBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(System.getProperty("line.separator")); } return textBuilder.toString(); }