List of usage examples for java.util Properties entrySet
@Override
public Set<Map.Entry<Object, Object>> entrySet()
From source file:nz.co.fortytwo.signalk.util.Util.java
public static SignalKModel populateModel(SignalKModel model, String mapDump) throws IOException { Properties props = new Properties(); props.load(new StringReader(mapDump.substring(1, mapDump.length() - 1).replace(", ", "\n"))); for (Map.Entry<Object, Object> e : props.entrySet()) { if (e.getValue().equals("true") || e.getValue().equals("false")) { model.put((String) e.getKey(), Boolean.getBoolean((String) e.getValue())); } else if (NumberUtils.isNumber((String) e.getValue())) { model.put((String) e.getKey(), NumberUtils.createDouble((String) e.getValue())); } else {// www. j ava 2 s .c o m model.put((String) e.getKey(), e.getValue()); } } return model; }
From source file:org.apache.hadoop.hbase.zookeeper.HQuorumPeer.java
/** * Return the ZK Quorum servers string given zk properties returned by * makeZKProps/*from ww w . j a va 2 s . com*/ * @param properties * @return */ public static String getZKQuorumServersString(Properties properties) { String clientPort = null; List<String> servers = new ArrayList<String>(); // The clientPort option may come after the server.X hosts, so we need to // grab everything and then create the final host:port comma separated list. boolean anyValid = false; for (Entry<Object, Object> property : properties.entrySet()) { String key = property.getKey().toString().trim(); String value = property.getValue().toString().trim(); if (key.equals("clientPort")) { clientPort = value; } else if (key.startsWith("server.")) { String host = value.substring(0, value.indexOf(':')); servers.add(host); try { //noinspection ResultOfMethodCallIgnored InetAddress.getByName(host); anyValid = true; } catch (UnknownHostException e) { LOG.warn(StringUtils.stringifyException(e)); } } } if (!anyValid) { LOG.error("no valid quorum servers found in " + HConstants.ZOOKEEPER_CONFIG_NAME); return null; } if (clientPort == null) { LOG.error("no clientPort found in " + HConstants.ZOOKEEPER_CONFIG_NAME); return null; } if (servers.isEmpty()) { LOG.fatal("No server.X lines found in conf/zoo.cfg. HBase must have a " + "ZooKeeper cluster configured for its operation."); return null; } StringBuilder hostPortBuilder = new StringBuilder(); for (int i = 0; i < servers.size(); ++i) { String host = servers.get(i); if (i > 0) { hostPortBuilder.append(','); } hostPortBuilder.append(host); hostPortBuilder.append(':'); hostPortBuilder.append(clientPort); } return hostPortBuilder.toString(); }
From source file:org.apache.falcon.lifecycle.engine.oozie.utils.OozieBuilderUtils.java
private static Configuration getHiveCredentialsAsConf(Cluster cluster) { Properties hiveCredentials = getHiveCredentials(cluster); Configuration hiveConf = new Configuration(false); for (Map.Entry<Object, Object> entry : hiveCredentials.entrySet()) { hiveConf.set((String) entry.getKey(), (String) entry.getValue()); }/*w w w.j a v a 2 s . c om*/ return hiveConf; }
From source file:com.wavemaker.runtime.data.util.DataServiceUtils.java
public static Properties toHibernateConnectionProperties(Properties p) { Properties rtn = new Properties(); rtn.putAll(p);/*from w w w. j av a 2s. c o m*/ for (Iterator<Map.Entry<Object, Object>> iter = p.entrySet().iterator(); iter.hasNext();) { Map.Entry<Object, Object> entry = iter.next(); String name = (String) entry.getKey(); String newName = null; if (name.endsWith(DataServiceConstants.DB_USERNAME)) { newName = DataServiceConstants.HIBERNATE_USER_PROPERTY; } else if (name.endsWith(DataServiceConstants.DB_PASS)) { newName = DataServiceConstants.HIBERNATE_PASS_PROPERTY; } else if (name.endsWith(DataServiceConstants.DB_DRIVER_CLASS_NAME)) { newName = DataServiceConstants.HIBERNATE_DRIVER_CLASS_NAME_PROPERTY; } else if (name.endsWith(DataServiceConstants.DB_URL)) { newName = DataServiceConstants.HIBERNATE_CONNECTION_URL_PROPERTY; } else if (name.endsWith(DataServiceConstants.DB_DIALECT)) { newName = DataServiceConstants.HIBERNATE_DIALECT_PROPERTY; } if (newName != null && rtn.getProperty(newName) == null) { rtn.setProperty(newName, (String) entry.getValue()); } } return rtn; }
From source file:org.apache.falcon.lifecycle.engine.oozie.utils.OozieBuilderUtils.java
private static org.apache.falcon.oozie.workflow.CONFIGURATION getWorkflowConfig(Properties props) { org.apache.falcon.oozie.workflow.CONFIGURATION conf = new org.apache.falcon.oozie.workflow.CONFIGURATION(); for (Map.Entry<Object, Object> prop : props.entrySet()) { org.apache.falcon.oozie.workflow.CONFIGURATION.Property confProp = new org.apache.falcon.oozie.workflow.CONFIGURATION.Property(); confProp.setName((String) prop.getKey()); confProp.setValue((String) prop.getValue()); conf.getProperty().add(confProp); }/*from w w w . jav a 2 s. com*/ return conf; }
From source file:org.apache.kylin.job.streaming.Kafka10DataLoader.java
private static Properties constructDefaultKafkaProducerProperties(String brokers, Properties properties) { Properties props = new Properties(); props.put("retry.backoff.ms", "1000"); props.put("bootstrap.servers", brokers); props.put("key.serializer", StringSerializer.class.getName()); props.put("value.serializer", StringSerializer.class.getName()); props.put("acks", "1"); props.put("buffer.memory", 33554432); props.put("retries", 0); props.put("batch.size", 16384); props.put("linger.ms", 50); props.put("request.timeout.ms", "30000"); if (properties != null) { for (Map.Entry entry : properties.entrySet()) { props.put(entry.getKey(), entry.getValue()); }//from w ww . ja v a2 s .co m } return props; }
From source file:io.stallion.reflection.PropertyUtils.java
private static Map getNestedProperties(String prefix, Properties properties) { Map result = new HashMap(); Iterator it = properties.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); String value = (String) entry.getValue(); result.put(prefix + '.' + name, value); }//from w w w .j a v a2s.c o m return result; }
From source file:eionet.cr.harvest.util.MediaTypeToDcmiTypeConverter.java
/** * Loads the mimetypes from the file and puts them into mimeToRdfMap. */// www . j a va 2 s . c o m private static void initialize() { mappings = new LinkedHashMap<String, String>(); InputStream inputStream = null; Properties properties = new Properties(); try { inputStream = MediaTypeToDcmiTypeConverter.class.getClassLoader() .getResourceAsStream(MAPPINGS_FILENAME); properties.loadFromXML(inputStream); } catch (IOException e) { LOGGER.error("Failed to load XML-formatted properties from " + MAPPINGS_FILENAME, e); } finally { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } if (!properties.isEmpty()) { for (Map.Entry entry : properties.entrySet()) { String rdfType = entry.getKey().toString(); String[] mediaTypes = entry.getValue().toString().split("\\s+"); if (!StringUtils.isBlank(rdfType) && mediaTypes != null && mediaTypes.length > 0) { for (int i = 0; i < mediaTypes.length; i++) { if (!StringUtils.isBlank(mediaTypes[i])) { mappings.put(mediaTypes[i].trim(), rdfType.trim()); } } } } } }
From source file:com.espertech.esper.core.service.EPServicesContextFactoryDefault.java
private static Map<String, Object> createPropertyTypes(Properties properties) { Map<String, Object> propertyTypes = new LinkedHashMap<String, Object>(); for (Map.Entry entry : properties.entrySet()) { String property = (String) entry.getKey(); String className = (String) entry.getValue(); Class clazz = JavaClassHelper.getClassForSimpleName(className); if (clazz == null) { throw new ConfigurationException("The type '" + className + "' is not a recognized type"); }// w ww. j a v a 2s . co m propertyTypes.put(property, clazz); } return propertyTypes; }
From source file:net.sourceforge.jaulp.lang.PropertiesUtils.java
/** * Finds redundant values from the given Properties object and saves it to a Map. * /*from w ww. j a va 2 s.c o m*/ * @param properties * The Properties to check. * @return A map that contains the redundant value as the key of the map and a List(as value of * the map) of keys that have the redundant value. */ public static Map<String, List<String>> findRedundantValues(Properties properties) { Map<String, List<String>> reverseEntries = new LinkedHashMap<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (!reverseEntries.containsKey(value)) { List<String> keys = new ArrayList<>(); keys.add(key); reverseEntries.put(value, keys); } else { List<String> keys = reverseEntries.get(value); keys.add(key); } } Map<String, List<String>> redundantValues = new LinkedHashMap<>(); for (Map.Entry<String, List<String>> entry : reverseEntries.entrySet()) { String key = entry.getKey(); List<String> keys = entry.getValue(); if (1 < keys.size()) { redundantValues.put(key, keys); } } return redundantValues; }