List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testEntrySetRemove() { HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("A", "B"); HashMap<String, String> dummy = new HashMap<String, String>(); dummy.put("A", "b"); Map.Entry<String, String> bogus = dummy.entrySet().iterator().next(); Set<Map.Entry<String, String>> entrySet = hashMap.entrySet(); boolean removed = entrySet.remove(bogus); assertEquals(removed, false);//www. j a v a 2 s . c om assertEquals(hashMap.get("A"), "B"); }
From source file:net.dahanne.gallery.g2.java.client.business.G2Client.java
/** * This is where we convert the infos from the gallery to G2Picture objects * /*from w ww. ja va2 s. co m*/ * @param fetchImages * @return * @throws GalleryConnectionException */ public Collection<G2Picture> extractG2PicturesFromProperties(HashMap<String, String> fetchImages) throws GalleryConnectionException { Map<Integer, G2Picture> picturesMap = new HashMap<Integer, G2Picture>(); List<Integer> tmpImageNumbers = new ArrayList<Integer>(); int imageNumber = 0; for (Entry<String, String> entry : fetchImages.entrySet()) { if (entry.getKey().contains("image") && !entry.getKey().contains("image_count")) { // what is the picture id of this field ? imageNumber = new Integer(entry.getKey().substring(entry.getKey().lastIndexOf(".") + 1)); G2Picture picture = null; // a new picture, let's create it! if (!tmpImageNumbers.contains(imageNumber)) { picture = new G2Picture(); picture.setId(imageNumber); picturesMap.put(imageNumber, picture); tmpImageNumbers.add(imageNumber); } // a known picture, let's get it back else { picture = picturesMap.get(imageNumber); } try { if (entry.getKey().contains("image.title.")) { picture.setTitle(entry.getValue()); } else if (entry.getKey().contains("image.thumbName.")) { picture.setThumbName(entry.getValue()); } else if (entry.getKey().contains("image.thumb_width.")) { picture.setThumbWidth(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.thumb_height.")) { picture.setThumbHeight(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.resizedName.")) { picture.setResizedName(entry.getValue()); } else if (entry.getKey().contains("image.resized_width.")) { picture.setResizedWidth(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.resized_height.")) { picture.setResizedHeight(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.name.")) { picture.setName(entry.getValue()); } else if (entry.getKey().contains("image.raw_width.")) { picture.setRawWidth(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.raw_height.")) { picture.setRawHeight(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.raw_filesize.")) { picture.setRawFilesize(new Integer(entry.getValue())); } else if (entry.getKey().contains("image.caption.")) { picture.setCaption(entry.getValue()); } else if (entry.getKey().contains("image.forceExtension.")) { picture.setForceExtension(entry.getValue()); } else if (entry.getKey().contains("image.hidden.")) { picture.setHidden(Boolean.valueOf(entry.getValue())); } } catch (NumberFormatException nfe) { throw new GalleryConnectionException(nfe); } } } return picturesMap.values(); }
From source file:au.org.ala.layers.dao.LayerIntersectDAOImpl.java
@Override public HashMap<String, String> sampling(double longitude, double latitude) { init();//from w w w . j a v a 2 s. co m HashMap<String, String> output = new HashMap<String, String>(); if (getConfig().getShapeFileCache() != null) { HashMap<String, SimpleShapeFile> ssfs = getConfig().getShapeFileCache().getAll(); for (Entry<String, SimpleShapeFile> entry : ssfs.entrySet()) { String s = entry.getValue().intersect(longitude, latitude); if (s == null) { s = ""; } output.put(entry.getKey(), s); } } if (gridReaders != null) { GridCacheReader gcr = null; HashMap<String, Float> gridValues = null; try { gcr = gridReaders.take(); gridValues = gcr.sample(longitude, latitude); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (gcr != null) { try { gridReaders.put(gcr); } catch (Exception e) { logger.error(e.getMessage(), e); } } } if (gridValues != null) { for (Entry<String, Float> entry : gridValues.entrySet()) { if (entry.getValue() == null || entry.getValue().isNaN()) { output.put(entry.getKey(), ""); } else { output.put(entry.getKey(), entry.getValue().toString()); } } } } return output; }
From source file:org.apache.lens.regression.util.Util.java
public static void changeConfig(HashMap<String, String> map, String remotePath) throws Exception { Path p = Paths.get(remotePath); String fileName = p.getFileName().toString(); backupFile = localFilePath + "backup-" + fileName; localFile = localFilePath + fileName; log.info("Copying " + remotePath + " to " + localFile); remoteFile("get", remotePath, localFile); Files.copy(new File(localFile).toPath(), new File(backupFile).toPath(), REPLACE_EXISTING); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.parse(new FileInputStream(localFile)); doc.normalize();//from w w w. j av a 2 s. c o m NodeList rootNodes = doc.getElementsByTagName("configuration"); Node root = rootNodes.item(0); Element rootElement = (Element) root; NodeList property = rootElement.getElementsByTagName("property"); for (int i = 0; i < property.getLength(); i++) { //Deleting redundant properties from the document Node prop = property.item(i); Element propElement = (Element) prop; Node propChild = propElement.getElementsByTagName("name").item(0); Element nameElement = (Element) propChild; if (map.containsKey(nameElement.getTextContent())) { rootElement.removeChild(prop); i--; } } Iterator<Entry<String, String>> ab = map.entrySet().iterator(); while (ab.hasNext()) { Entry<String, String> entry = ab.next(); String propertyName = entry.getKey(); String propertyValue = entry.getValue(); System.out.println(propertyName + " " + propertyValue + "\n"); Node newNode = doc.createElement("property"); rootElement.appendChild(newNode); Node newName = doc.createElement("name"); Element newNodeElement = (Element) newNode; newName.setTextContent(propertyName); newNodeElement.appendChild(newName); Node newValue = doc.createElement("value"); newValue.setTextContent(propertyValue); newNodeElement.appendChild(newValue); } prettyPrint(doc); remoteFile("put", remotePath, localFile); }
From source file:biomine.bmvis2.pipeline.KMedoidsHighlight.java
@Override public void doOperation(VisualGraph g) throws GraphOperationException { ArrayList<VisualNode> rlist = cache.get(g); HashMap<VisualNode, Integer> clusters = clusterCache.get(g); if (rlist == null) { rlist = new ArrayList<VisualNode>(); SimpleVisualGraph sg = new SimpleVisualGraph(g); KMedoidsResult r = KMedoids.runKMedoids(sg, k); int[] meds = r.medoids; for (int i = 0; i < k; i++) rlist.add(sg.getVisualNode(meds[i])); cache.put(g, rlist);//from w w w. j a va 2 s . c o m clusters = new HashMap<VisualNode, Integer>(); for (int i = 0; i < sg.n; i++) { clusters.put(sg.getVisualNode(i), r.clusters[i]); } clusterCache.put(g, clusters); } assert (rlist.size() == k); if (showClusters && k < ColorPalette.pastelShades.length) { for (Entry<VisualNode, Integer> ent : clusters.entrySet()) { ent.getKey().setBaseColor(ColorPalette.pastelShades[ent.getValue()]); } } for (int i = 0; i < rlist.size(); i++) { rlist.get(i).setBaseColor(hlColor); //System.out.println(rlist.get(i)); int c = i + 1; //rlist.get(i).addExtraLabel(""+c+". representative"); } }
From source file:ExcelFx.FXMLDocumentController.java
private void printXls(String patch, HashMap<String, HashSet<CountedMap>> result) throws IOException { System.out.println("printXls was started"); System.out.println("patch name:" + patch); System.out.println("result size: " + result.size()); try (Workbook wb = new XSSFWorkbook()) { Integer yStart = null;/* w w w .j a va 2 s . co m*/ Integer yEnd = null; for (Map.Entry<String, HashSet<CountedMap>> entry : result.entrySet()) { Sheet sheet = wb.createSheet(entry.getKey()); Map<String, CellStyle> styles = createStyles(wb); Row row; Cell cell; row = sheet.createRow(0); cell = row.createCell(0); cell.setCellValue("???"); cell.setCellStyle(styles.get("header")); for (int i = 0; i < list.get(0).size(); i++) { if (list.get(0).get(i).equals(initaldata.getYStart())) { yStart = i; } if (list.get(0).get(i).equals(initaldata.getYEnd())) { yEnd = i; } } for (int i = yStart; i <= yEnd; i++) { cell = row.createCell((i - yStart) + 1); cell.setCellValue(list.get(0).get(i)); cell.setCellStyle(styles.get("header")); } int i = 1; Iterator<CountedMap> itr = entry.getValue().iterator(); while (itr.hasNext()) { CountedMap next = itr.next(); row = sheet.createRow(i); cell = row.createCell(0); cell.setCellValue(next.getName().substring(0, 1).toUpperCase() + next.getName().substring(1)); cell.setCellStyle(styles.get("total")); for (int j = 0; j < next.getNeededStaff().size(); j++) { cell = row.createCell(j + 1);// //System.out.println(next.getNeededStaff().get(j)); cell.setCellValue(Double.parseDouble(next.getNeededStaff().get(j))); cell.setCellStyle(styles.get("total")); } Iterator<String> itrWay = next.getEdWay().iterator(); while (itrWay.hasNext()) { i++; String next1 = itrWay.next(); row = sheet.createRow(i); cell = row.createCell(0); cell.setCellValue(next1.substring(0, 1).toUpperCase() + next1.substring(1)); cell.setCellStyle(styles.get("normal")); for (int j = 0; j < next.getNeededStaff().size(); j++) { cell = row.createCell(j + 1);// //System.out.println(next.getNeededStaff().get(j)); cell.setCellValue( Double.parseDouble(next.getNeededStaff().get(j)) / next.getEdWay().size()); cell.setCellStyle(styles.get("normal")); } } i++; } } wb.write(new FileOutputStream(patch + ".xlsx")); System.out.println("File saved"); } System.out.println("printXlsx finished"); }
From source file:com.jci.flatfile.repo.FlatFileRepoImpl.java
@Override public void batchUpdate(BatchUpdateReq request) { LOG.info("### Starting in FlatFileRepoImpl.batchUpdate ###"); int errorCount = 0; int successCount = 0; HashMap<String, List<TableEntity>> tableNameToEntityMap = request.getTableNameToEntityMap(); CloudTable cloudTable = null;//w ww . j ava 2 s.c o m TableEntity entity = null; for (Map.Entry<String, List<TableEntity>> entry : tableNameToEntityMap.entrySet()) { try { cloudTable = azureStorage.getTable(entry.getKey()); } catch (Exception e) { throw errorService.createException(FlatFileException.class, e, ErrorEnum.ERROR_TABLE_NOT_FOUND, entry.getKey()); } // Define a batch operation. TableBatchOperation batchOperation = new TableBatchOperation(); List<TableEntity> value = entry.getValue(); for (int i = 0; i < value.size(); i++) { entity = value.get(i); if (entity instanceof PoEntity) { PoEntity en = (PoEntity) entity; if (request.isSuccess()) { en.setSupplierDeliveryState(Constants.STATUS_SUCCESS); successCount = successCount + 1; } else {//Request is for error status update en.setSupplierDeliveryState(Constants.STATUS_ERROR); errorCount = errorCount + 1; } if (request.getGlobalId() != null) { en.setComment(request.getComment()); en.setUserName(request.getUserName()); en.setGlobalId(request.getGlobalId()); } batchOperation.insertOrMerge(en); } else if (entity instanceof SuppEntity) { SuppEntity en = (SuppEntity) entity; if (request.isSuccess()) { en.setSupplierDeliveryState(Constants.STATUS_SUCCESS); successCount = successCount + 1; } else {//Request is for error status update en.setSupplierDeliveryState(Constants.STATUS_ERROR); errorCount = errorCount + 1; } if (request.getGlobalId() != null) { en.setComment(request.getComment()); en.setUserName(request.getUserName()); en.setGlobalId(request.getGlobalId()); } batchOperation.insertOrMerge(en); } else if (entity instanceof ItemEntity) { ItemEntity en = (ItemEntity) entity; if (request.isSuccess()) { en.setSupplierDeliveryState(Constants.STATUS_SUCCESS); successCount = successCount + 1; } else {//Request is for error status update en.setSupplierDeliveryState(Constants.STATUS_ERROR); errorCount = errorCount + 1; } if (request.getGlobalId() != null) { en.setComment(request.getComment()); en.setUserName(request.getUserName()); en.setGlobalId(request.getGlobalId()); } batchOperation.insertOrMerge(en); } else if (entity instanceof GrEntity) { GrEntity en = (GrEntity) entity; if (request.isSuccess()) { en.setSupplierDeliveryState(Constants.STATUS_SUCCESS); successCount = successCount + 1; } else {//Request is for error status update en.setSupplierDeliveryState(Constants.STATUS_ERROR); errorCount = errorCount + 1; } if (request.getGlobalId() != null) { en.setComment(request.getComment()); en.setUserName(request.getUserName()); en.setGlobalId(request.getGlobalId()); } batchOperation.insertOrMerge(en); } if (i != 0 && (i % batchSize) == 0) { try { cloudTable.execute(batchOperation); batchOperation.clear(); } catch (Exception e) { LOG.error("### Exception in FlatFileRepoImpl.batchUpdate.execute ###" + e); continue; } } } if (batchOperation.size() > 0) { try { cloudTable.execute(batchOperation); } catch (Exception e) { continue; } } if (successCount > 0 || errorCount > 0) { updateMiscEntity(request.getErpName(), entry.getKey(), successCount, errorCount, request.isErrorReq()); } } LOG.info("### Ending in FlatFileRepoImpl.batchUpdate ###"); }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testEntrySetEntrySetterString() { HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("A", "B"); Set<Map.Entry<String, String>> entrySet = hashMap.entrySet(); Map.Entry<String, String> entry = entrySet.iterator().next(); entry.setValue("C"); assertEquals("C", hashMap.get("A")); hashMap.put("A", "D"); assertEquals("D", entry.getValue()); assertEquals(1, hashMap.size());//from www . j a va2 s.c om }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testEntrySetEntrySetterNonString() { HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>(); hashMap.put(1, 2);//w w w. j a v a2s . c om Set<Map.Entry<Integer, Integer>> entrySet = hashMap.entrySet(); Map.Entry<Integer, Integer> entry = entrySet.iterator().next(); entry.setValue(3); assertEquals(3, hashMap.get(1).intValue()); hashMap.put(1, 4); assertEquals(4, entry.getValue().intValue()); assertEquals(1, hashMap.size()); }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testEntrySetEntrySetterNull() { HashMap<String, Integer> hashMap = new HashMap<String, Integer>(); hashMap.put(null, 2);/*from w ww. j av a 2 s . c o m*/ Set<Map.Entry<String, Integer>> entrySet = hashMap.entrySet(); Map.Entry<String, Integer> entry = entrySet.iterator().next(); entry.setValue(3); assertEquals(3, hashMap.get(null).intValue()); hashMap.put(null, 4); assertEquals(4, entry.getValue().intValue()); assertEquals(1, hashMap.size()); }