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.IdentityHashMapTest.java
public void testEntrySetEntrySetterString() { HashMap hashMap = new HashMap(); String key = "A"; hashMap.put(key, "B"); Set entrySet = hashMap.entrySet(); Entry entry = (Entry) entrySet.iterator().next(); entry.setValue("C"); assertEquals("C", hashMap.get(key)); hashMap.put(key, "D"); assertEquals("D", entry.getValue()); assertEquals(1, hashMap.size());//from w w w.j a v a 2 s .c o m }
From source file:com.tealeaf.util.HTTP.java
public HttpResponse getFileResponse(URI uri, String fileName, HashMap<String, String> requestHeaders) { HttpResponse response = null;// w w w .j a v a2 s.co m InputStream in = null; File file = new File(fileName); FileOutputStream fo = null; AndroidHttpClient client = null; try { client = AndroidHttpClient.newInstance(userAgent); HttpGet request = new HttpGet(); if (requestHeaders != null) { for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { request.addHeader(new BasicHeader(entry.getKey(), entry.getValue())); } } request.setURI(uri); response = client.execute(request, localContext); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { client.close(); return null; } try { new File(file.getParent()).mkdirs(); file.createNewFile(); fo = new FileOutputStream(file); } catch (IOException e1) { logger.log(e1); return null; } in = response.getEntity().getContent(); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = in.read(buffer)) != -1) { fo.write(buffer, 0, bytesRead); } fo.close(); in.close(); client.close(); } catch (SocketTimeoutException e) { // forget it--we don't care that the user failed to connect } catch (IllegalArgumentException e) { // forget it--we don't care that the user failed to connect logger.log("{http} WARNING: Illegal argument" + uri); } catch (IOException e) { if (!caughtIOException) { caughtIOException = true; logger.log(e); } file = null; response = null; } finally { if (client != null) { client.close(); } if (in != null) { try { in.close(); } catch (IOException e) { // ignore it } } } return response; }
From source file:com.ibm.xsp.webdav.repository.DAVRepositoryDominoCategorizedDocuments.java
public String getAdditionalParameterValue(String key) { DAVRepositoryMETA drm = WebDavManager.getManager(null).getRepositoryMeta(); if (drm == null) { // // LOGGER.info("Error; dm is null"); return ""; }/*from w w w. j a v a 2 s. c o m*/ DAVRepositoryListing drl; HashMap<String, DAVRepositoryListing> hm = drm.getRepositoryList(); IDAVAddressInformation repAdr = (IDAVAddressInformation) this; String intAdr = repAdr.getPublicHref(); String repName = intAdr; // // LOGGER.info("Pub Href="+repName); String[] part = repName.split("/"); for (int i = 0; i < part.length; i++) { // // LOGGER.info("Part["+new Integer(i).toString()+"]="+part[i]); } drl = null; if (part.length > 2) { drl = hm.get(part[2]); if (drl == null) { // // LOGGER.info("Error; drl is null for repositor ##"); return ""; } HashMap<String, String> additionalParameters = drl.getAdditionalParameters(); if (additionalParameters == null) { // // LOGGER.info("Error; additionalParameters is null"); return ""; } Iterator<Entry<String, String>> i = additionalParameters.entrySet().iterator(); while (i.hasNext()) { Map.Entry<String, String> me = (Map.Entry<String, String>) i.next(); if (me.getKey().toString().equals(key)) { return me.getValue().toString(); } // // LOGGER.info("MAP name="+ // me.getKey().toString()+" value="+me.getValue().toString()); } } return ""; }
From source file:GitBackend.GitAPI.java
private String getMostRecentCommit(HashMap<String, DateTime> commitMap, DateTime execDate) { Iterator it = commitMap.entrySet().iterator(); Map.Entry<String, DateTime> mostRecentCommit = null; System.out.println("Number of commits: " + commitMap.size()); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); DateTime currentCommitDate = (DateTime) pair.getValue(); if (mostRecentCommit == null && ((DateTime) pair.getValue()).isBefore(execDate)) { System.out.println("most recent war null bei vergleich"); mostRecentCommit = pair;//from w w w. j a v a2s. c o m } else if (currentCommitDate.isBefore(execDate)) { System.out.println("Current date is before exec"); if (currentCommitDate.isAfter(mostRecentCommit.getValue())) { System.out.println("Current date is before exec and after the most recent one"); mostRecentCommit = pair; } } } System.out.println( "Current most recent: " + mostRecentCommit.getKey() + " = " + mostRecentCommit.getValue()); return mostRecentCommit.getKey(); }
From source file:com.pwn9.PwnFilter.minecraft.PwnFilterPlugin.java
private void saveDefaultConfig() { HashMap<String, String> configFiles = Maps.newHashMap(); configFiles.put("pwnfilter.conf", "pwnfilter.conf"); configFiles.put("book.txt", "rules/book.txt"); configFiles.put("chat.txt", "rules/chat.txt"); configFiles.put("command.txt", "rules/command.txt"); configFiles.put("console.txt", "rules/console.txt"); configFiles.put("item.txt", "rules/item.txt"); configFiles.put("book.txt", "rules/sign.txt"); if (!dataFolder.exists()) { new File(dataFolder, "rules").mkdirs(); for (HashMap.Entry<String, String> entry : configFiles.entrySet()) { URL url = PwnFilterPlugin.class.getResource(entry.getKey()); try { FileUtils.copyURLToFile(url, new File(dataFolder, entry.getValue())); } catch (IOException e) { e.printStackTrace();// w w w . j a va2 s .c om } } } }
From source file:com.jvoid.customers.customer.service.CustomerMasterService.java
public int updateCustomer(JSONObject jObj) { int status = 0; Customer customer = null;//from w w w .j av a 2 s.c o m int customerId = 0; try { customerId = jObj.getInt("id"); customer = this.customerService.getcustomerById(customerId); } catch (JSONException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } if (null != customer) { System.out.println("Date:" + Utilities.getCurrentDateTime()); System.out.println("CO:" + customer.toString()); customer.setUpdatedAt(Utilities.getCurrentDateTime()); customer.setCreatedAt(customer.getCreatedAt()); try { customer.setEmail(jObj.getString("email")); customer.setCustomerGroupId(jObj.getInt("customerGroup")); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } this.customerService.updatecustomer(customer); List<Entities> listAttributes = this.entitiesService.listAttributes(); HashMap<Integer, String> attrs = getAttributesList(listAttributes, "Customer"); System.out.println("attrs==>" + attrs.toString()); for (Entry<Integer, String> entry : attrs.entrySet()) { Integer attrId = entry.getKey(); String attrName = entry.getValue(); CustomerEntityValues customerEntityValue = this.customerEntityValuesService .getCustomerEntityValuesByCustomerIdAndAttributeId(customerId, attrId); String attrValue; try { attrValue = jObj.getString(attrName); if (null != attrValue) { CustomerEntityValues custAttrValue = new CustomerEntityValues(); custAttrValue.setCustomerId(customerId); custAttrValue.setLanguage(customerEntityValue.getLanguage()); custAttrValue.setAttributeId(attrId); custAttrValue.setValue(attrValue); custAttrValue.setId(customerEntityValue.getId()); customerEntityValuesService.updateCustomerAttributeValues(custAttrValue); System.out.println("custAttrValue-->" + custAttrValue.toString()); } } catch (JSONException e) { e.printStackTrace(); } } status = 1; } else { status = 0; } return status; }
From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
public PieDataset createDataSetForPatientReports() { DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> organDonorMap = new HashMap<>(); for (Patient patient : patientList) { if (organDonorMap.containsKey(patient.getOrganNeeded().getOrganName())) { Integer count = organDonorMap.get(patient.getOrganNeeded().getOrganName()); count++;// w w w . ja v a2 s . c o m organDonorMap.put(patient.getOrganNeeded().getOrganName(), count); } else { organDonorMap.put(patient.getOrganNeeded().getOrganName(), 1); } } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { Integer noOfDonors = entry.getValue(); noOfDonors = (noOfDonors * 100) / patientList.size(); organDonorMap.put(entry.getKey(), noOfDonors); } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { dataset.setValue(entry.getKey() + " = " + entry.getValue(), entry.getValue()); } return dataset; }
From source file:io.pravega.segmentstore.server.reading.StorageReaderTests.java
/** * Tests the ability to auto-cancel the requests when the StorageReader is closed. */// w w w.jav a 2 s. c o m @Test public void testAutoCancelRequests() { final int readCount = 100; TestStorage storage = new TestStorage(); storage.readImplementation = CompletableFuture::new; // Just return a Future which we will never complete - simulates a high latency read. @Cleanup StorageReader reader = new StorageReader(SEGMENT_METADATA, storage, executorService()); // Create some reads. HashMap<StorageReader.Request, CompletableFuture<StorageReader.Result>> requestCompletions = new HashMap<>(); for (int i = 0; i < readCount; i++) { CompletableFuture<StorageReader.Result> requestCompletion = new CompletableFuture<>(); StorageReader.Request r = new StorageReader.Request(i * 10, 9, requestCompletion::complete, requestCompletion::completeExceptionally, TIMEOUT); reader.execute(r); requestCompletions.put(r, requestCompletion); } // Verify the reads aren't failed yet. for (val entry : requestCompletions.entrySet()) { Assert.assertFalse("Request is unexpectedly completed before close for request " + entry.getKey(), entry.getValue().isDone()); } // Close the reader and verify the reads have all been cancelled. reader.close(); for (val entry : requestCompletions.entrySet()) { Assert.assertTrue("Request is not completed with exception after close for request " + entry.getKey(), entry.getValue().isCompletedExceptionally()); AssertExtensions.assertThrows( "Request was not failed with a CancellationException after close for request " + entry.getKey(), entry.getValue()::join, ex -> ex instanceof CancellationException); } }
From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
public PieDataset createDataSetForDonorReports() { DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> organDonorMap = new HashMap<>(); for (Donor donor : donorList) { for (Organ organ : donor.getOrganDonateList()) { if (organDonorMap.containsKey(organ.getOrganName())) { Integer count = organDonorMap.get(organ.getOrganName()); count++;/*from ww w .ja v a 2 s .c om*/ organDonorMap.put(organ.getOrganName(), count); } else { organDonorMap.put(organ.getOrganName(), 1); } } } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { Integer noOfDonors = entry.getValue(); noOfDonors = noOfDonors * 100 / donorList.size(); organDonorMap.put(entry.getKey(), noOfDonors); } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { dataset.setValue(entry.getKey() + " = " + entry.getValue(), entry.getValue()); } return dataset; }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
private void iterateThrough(final HashMap<?, ?> expected) { Iterator<?> iter = expected.entrySet().iterator(); for (int i = 0; i < expected.size(); i++) { iter.next();/*w ww . j a v a2 s.c o m*/ } }