List of usage examples for java.util Properties entrySet
@Override
public Set<Map.Entry<Object, Object>> entrySet()
From source file:com.manydesigns.elements.annotations.AnnotationsManager.java
public AnnotationsManager() { annotationClassMap = new HashMap<Class, Class>(); Properties mappings = elementsConfiguration .getProperties(ElementsProperties.ANNOTATIONS_IMPLEMENTATION_LIST); if (mappings == null) { logger.debug("Empty list"); return;/*www. j av a 2 s. com*/ } for (Map.Entry<Object, Object> mapping : mappings.entrySet()) { String annotationName = (String) mapping.getKey(); String annotationImplName = (String) mapping.getValue(); addAnnotationMapping(annotationName, annotationImplName); } }
From source file:com.netflix.spinnaker.igor.jenkins.service.JenkinsService.java
@Override @SuppressWarnings("unchecked") public Map<String, Object> getBuildProperties(String job, int buildNumber, String fileName) { if (StringUtils.isEmpty(fileName)) { return new HashMap<>(); }//from w w w . j a va 2s .c o m Map<String, Object> map = new HashMap<>(); try { String path = getArtifactPathFromBuild(job, buildNumber, fileName); try (InputStream propertyStream = this.getPropertyFile(job, buildNumber, path).getBody().in()) { if (fileName.endsWith(".yml") || fileName.endsWith(".yaml")) { Yaml yml = new Yaml(new SafeConstructor()); map = (Map<String, Object>) yml.load(propertyStream); } else if (fileName.endsWith(".json")) { map = objectMapper.readValue(propertyStream, new TypeReference<Map<String, Object>>() { }); } else { Properties properties = new Properties(); properties.load(propertyStream); map = properties.entrySet().stream() .collect(Collectors.toMap(e -> e.getKey().toString(), Map.Entry::getValue)); } } } catch (NotFoundException e) { throw e; } catch (Exception e) { log.error("Unable to get igorProperties '{}'", kv("job", job), e); } return map; }
From source file:io.wcm.maven.plugins.i18n.readers.PropertiesI18nReader.java
@Override public Map<String, String> read(File sourceFile) throws IOException { // read properties Properties props = new Properties(); try (FileInputStream is = new FileInputStream(sourceFile); InputStreamReader reader = new InputStreamReader(is, CharEncoding.UTF_8)) { props.load(reader);/*w w w .ja v a 2s .c om*/ } // convert to map Map<String, String> map = new HashMap<>(); for (Map.Entry<Object, Object> entry : props.entrySet()) { map.put(entry.getKey().toString(), entry.getValue().toString()); } return map; }
From source file:com.netflix.config.ConcurrentMapConfiguration.java
/** * Load properties into the configuration. This method iterates through * the entries of the properties and call {@link #setProperty(String, Object)} for * non-null key/value./* w ww. j a va 2 s. com*/ */ public void loadProperties(Properties props) { for (Map.Entry<Object, Object> entry : props.entrySet()) { String key = (String) entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { setProperty(key, value); } } }
From source file:org.vbossica.springbox.config.PropertyPlaceholderDebuggingConfigurer.java
@Override protected String resolvePlaceholder(String placeholder, Properties props) { String value = super.resolvePlaceholder(placeholder, props); if (value == null) { log.error("Placeholder '{}' couldn't be resolved", placeholder); if (log.isDebugEnabled()) { log.debug(" properties:"); for (Map.Entry<Object, Object> entry : props.entrySet()) { log.debug(" {}: '{}'", entry.getKey(), entry.getValue()); }/*from ww w . j av a 2 s. c om*/ } } return value; }
From source file:hudson.plugins.sonar.utils.PathResolverOperator.java
public Properties resolvePaths(Properties prop) throws IOException, InterruptedException { Properties result = new Properties(); Map<String, Set<String>> rawResults = Maps.newHashMap(); for (Map.Entry<Object, Object> entry : prop.entrySet()) { String key = entry.getKey().toString(); if (!PATH_PROPERTIES.contains(key)) { result.put(key, entry.getValue()); continue; }/* w w w. java 2 s . co m*/ String value = entry.getValue().toString(); rawResults.put(key, doResolvePathSegments(key, value)); } rawResults = mergeInternalProperties(rawResults); for (Map.Entry<String, Set<String>> rawEntry : rawResults.entrySet()) { result.put(rawEntry.getKey(), joiner.join(rawEntry.getValue())); } return result; }
From source file:com.trafficspaces.api.controller.Connector.java
private String toQueryString(Properties params) throws TrafficspacesAPIException { StringBuffer queryString = new StringBuffer(); if (params != null && !params.isEmpty()) { Iterator itr = params.entrySet().iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); try { queryString.append(URLEncoder.encode((String) entry.getKey(), "UTF-8")); queryString.append("="); queryString.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); queryString.append("&"); } catch (UnsupportedEncodingException uee) { throw new TrafficspacesAPIException(uee); }//from ww w . j a v a 2 s .co m } } return queryString.toString(); }
From source file:com.mongodb.hadoop.hive.MongoStorageHandler.java
/** * Helper function to copy properties//from w w w .j av a 2 s. c om */ private void copyJobProperties(final Properties from, final Map<String, String> to) { // Copy Hive-specific properties used directly by // HiveMongoInputFormat, BSONSerDe. if (from.containsKey(serdeConstants.LIST_COLUMNS)) { to.put(serdeConstants.LIST_COLUMNS, (String) from.get(serdeConstants.LIST_COLUMNS)); } if (from.containsKey(serdeConstants.LIST_COLUMN_TYPES)) { to.put(serdeConstants.LIST_COLUMN_TYPES, (String) from.get(serdeConstants.LIST_COLUMN_TYPES)); } if (from.containsKey(MONGO_COLS)) { to.put(MONGO_COLS, (String) from.get(MONGO_COLS)); } if (from.containsKey(TABLE_LOCATION)) { to.put(TABLE_LOCATION, (String) from.get(TABLE_LOCATION)); } // First, merge properties from the given properties file, if there // was one. These can be overwritten by other table properties later. String propertiesFilePathString = from.getProperty(PROPERTIES_FILE_PATH); if (propertiesFilePathString != null) { try { Properties properties = getProperties(getConf(), propertiesFilePathString); for (Map.Entry<Object, Object> prop : properties.entrySet()) { String key = (String) prop.getKey(); String value = (String) prop.getValue(); if (key.equals(MONGO_URI)) { // Copy to input/output URI. to.put(MongoConfigUtil.INPUT_URI, value); to.put(MongoConfigUtil.OUTPUT_URI, value); } else { to.put(key, value); } } } catch (IOException e) { LOG.error("Error while trying to read properties file " + propertiesFilePathString, e); } } // Copy general connector properties, such as ones defined in // MongoConfigUtil. These are all prefixed with "mongo.". for (Entry<Object, Object> entry : from.entrySet()) { String key = (String) entry.getKey(); if (key.startsWith("mongo.")) { to.put(key, (String) from.get(key)); } } // Update the keys for MONGO_URI per MongoConfigUtil. if (from.containsKey(MONGO_URI)) { String mongoURIStr = (String) from.get(MONGO_URI); to.put(MongoConfigUtil.INPUT_URI, mongoURIStr); to.put(MongoConfigUtil.OUTPUT_URI, mongoURIStr); } }
From source file:com.opengamma.transport.TaxonomyGatheringFudgeMessageSenderTest.java
@Test(timeOut = 10000) public void taxonomyGathering() throws IOException, InterruptedException { File tmpFile = File.createTempFile("TaxonomyGatheringFudgeMessageSenderTest_taxonomyGathering", ".properties"); FileUtils.forceDelete(tmpFile);// w w w .j a va2s .c o m FileUtils.forceDeleteOnExit(tmpFile); FudgeContext context = new FudgeContext(); CollectingFudgeMessageReceiver collectingReceiver = new CollectingFudgeMessageReceiver(); ByteArrayFudgeMessageReceiver fudgeReceiver = new ByteArrayFudgeMessageReceiver(collectingReceiver); DirectInvocationByteArrayMessageSender byteArraySender = new DirectInvocationByteArrayMessageSender( fudgeReceiver); ByteArrayFudgeMessageSender fudgeSender = new ByteArrayFudgeMessageSender(byteArraySender, context); TaxonomyGatheringFudgeMessageSender gatheringSender = new TaxonomyGatheringFudgeMessageSender(fudgeSender, tmpFile.getAbsolutePath(), context, 1000L); MutableFudgeMsg msg1 = context.newMessage(); msg1.add("name1", 1); msg1.add("name2", 1); msg1.add("name3", 1); msg1.add("name1", 1); MutableFudgeMsg msg2 = context.newMessage(); msg1.add("name4", msg2); msg2.add(14, 1); msg2.add("name5", "foo"); gatheringSender.send(msg1); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name1")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name2")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name3")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name4")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name5")); assertEquals(5, gatheringSender.getCurrentTaxonomy().size()); Properties props = new Properties(); gatheringSender.waitForNextWrite(); InputStream is = new FileInputStream(tmpFile); props.load(new BufferedInputStream(is)); is.close(); for (Map.Entry<Object, Object> propEntry : props.entrySet()) { Integer ordinal = gatheringSender.getCurrentTaxonomy().get(propEntry.getValue()); assertEquals(ordinal.intValue(), Integer.parseInt((String) propEntry.getKey())); } assertEquals(5, props.size()); }
From source file:cc.pp.analyzer.paoding.knife.PaodingMaker.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static Paoding createPaodingWithKnives(Properties p) throws Exception { // PaodingHolderPaoding // ?Paoding?paodingHolder Paoding paoding = new Paoding(); // Knife/*from w ww . jav a 2 s . com*/ final Map /* <String, Knife> */ knifeMap = new HashMap /* * <String, * Knife> */(); final List /* <Knife> */ knifeList = new LinkedList/* <Knife> */(); final List /* <Function> */<Function> functions = new LinkedList/* <Function> */(); Iterator iter = p.entrySet().iterator(); while (iter.hasNext()) { Map.Entry e = (Map.Entry) iter.next(); final String key = (String) e.getKey(); final String value = (String) e.getValue(); int index = key.indexOf(Constants.KNIFE_CLASS); if (index == 0 && key.length() > Constants.KNIFE_CLASS.length()) { final int end = key.indexOf('.', Constants.KNIFE_CLASS.length()); if (end == -1) { Class clazz = Class.forName(value); Knife knife = (Knife) clazz.newInstance(); knifeList.add(knife); knifeMap.put(key, knife); log.info("add knike: " + value); } else { // hashkey???????knife? // ?functionsknife?? functions.add(new Function() { @Override public void run() throws Exception { String knifeName = key.substring(0, end); Object obj = knifeMap.get(knifeName); if (!obj.getClass().getName().equals("org.springframework.beans.BeanWrapperImpl")) { Class beanWrapperImplClass = Class .forName("org.springframework.beans.BeanWrapperImpl"); Method setWrappedInstance = beanWrapperImplClass.getMethod("setWrappedInstance", new Class[] { Object.class }); Object beanWrapperImpl = beanWrapperImplClass.newInstance(); setWrappedInstance.invoke(beanWrapperImpl, new Object[] { obj }); knifeMap.put(knifeName, beanWrapperImpl); obj = beanWrapperImpl; } String propertyName = key.substring(end + 1); Method setPropertyValue = obj.getClass().getMethod("setPropertyValue", new Class[] { String.class, Object.class }); setPropertyValue.invoke(obj, new Object[] { propertyName, value }); } }); } } } // ??? for (Iterator iterator = functions.iterator(); iterator.hasNext();) { Function function = (Function) iterator.next(); function.run(); } // ? paoding.setKnives(knifeList); return paoding; }