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:org.owasp.benchmark.score.report.ScatterHome.java
private static void dedupify(HashMap<Point2D, String> map) { for (Entry<Point2D, String> e1 : map.entrySet()) { Entry<Point2D, String> e2 = getMatch(map, e1); while (e2 != null) { StringBuilder label = new StringBuilder(); if (e1.getValue() != null) label.append(e1.getValue()); if (e1.getValue() != null && e2.getValue() != null) label.append(","); if (e2.getValue() != null) label.append(e2.getValue()); e1.setValue(label.toString()); e2.setValue(null);/* w w w. jav a 2s .c o m*/ e2 = getMatch(map, e1); } } }
From source file:LogToFile.java
private static HttpPost Post(String url, HashMap<String, String> params, HashMap<String, ArrayList<String>> arrayParams) { try {//from w w w . j av a 2 s. c om if (!url.endsWith("/")) url += "/"; List<NameValuePair> params_list = null; if (params != null) { params_list = new LinkedList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } if (arrayParams != null) { if (params_list == null) params_list = new LinkedList<NameValuePair>(); for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet()) for (String value : entry.getValue()) params_list.add(new BasicNameValuePair(entry.getKey(), value)); } HttpPost request = new HttpPost(url); if (params != null) request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8")); return request; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }
From source file:it.univaq.incipict.profilemanager.common.utility.Utility.java
public static HashMap<Profile, Float> getPercentages(HashMap<Profile, Double> distances, int informationSetSize) { Map<Profile, Float> result = new HashMap<Profile, Float>(); if (distances.isEmpty() || distances == null) { return new HashMap<Profile, Float>(); } else {//from w w w .jav a 2 s .c o m for (Map.Entry<Profile, Double> entry : distances.entrySet()) { Profile profile = entry.getKey(); Double distance = entry.getValue(); // Calculate the percentage for the current distance // The maximum distance is sqrt(informationSetSize) because we have // 0-1 vectors // REMARK: Euclidean Distance Theory float maxDistance = (float) Math.sqrt(informationSetSize); float percentage = (float) (maxDistance - distance) * 100 / maxDistance; // put the percentage in Map formatted with two decimals. result.put(profile, (float) (Math.round(percentage * 100.0) / 100.0)); } } // return the HashMap sorted by value (DESC) return (HashMap<Profile, Float>) MapUtil.sortByValueDESC(result); }
From source file:com.clustercontrol.accesscontrol.util.RoleObjectPrivilegeUtil.java
/** * ?????DB??????//from w w w .ja va 2s .c o m */ public static List<ObjectPrivilegeInfo> beanMap2dtoList(HashMap<String, ObjectPrivilegeBean> beanMap) { List<ObjectPrivilegeInfo> resultList = new ArrayList<ObjectPrivilegeInfo>(); ObjectPrivilegeBean bean = null; for (Map.Entry<String, ObjectPrivilegeBean> keyValue : beanMap.entrySet()) { bean = keyValue.getValue(); // ?? ObjectPrivilegeInfo ?? // ?? if (bean.getReadPrivilege()) { ObjectPrivilegeInfo info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.READ.toString()); resultList.add(info); } // ? if (bean.getWritePrivilege()) { ObjectPrivilegeInfo info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.MODIFY.toString()); resultList.add(info); } // ? if (bean.getExecPrivilege()) { ObjectPrivilegeInfo info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.EXEC.toString()); resultList.add(info); } } return resultList; }
From source file:Main.java
public static final String postData(String url, HashMap<String, String> params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); String outputString = null;//from ww w. jav a2 s . c o m try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.size()); Iterator it = params.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); nameValuePairs.add(new BasicNameValuePair((String) pair.getKey(), (String) pair.getValue())); System.out.println(pair.getKey() + " = " + pair.getValue()); it.remove(); // avoids a ConcurrentModificationException } httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpURLConnection.HTTP_OK) { byte[] result = EntityUtils.toByteArray(response.getEntity()); outputString = new String(result, "UTF-8"); } } catch (ClientProtocolException e) { Log.i(CLASS_NAME, "Client protocolException happened: " + e.getMessage()); } catch (IOException e) { Log.i(CLASS_NAME, "Client IOException happened: " + e.getMessage()); } catch (NetworkOnMainThreadException e) { Log.i(CLASS_NAME, "Client NetworkOnMainThreadException happened: " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { Log.i(CLASS_NAME, "Unknown exeception: " + e.getMessage()); } return outputString; }
From source file:Main.java
public static void hashMapToXML222(String xmlFile, String xpath, HashMap hashmap) { try {/* w ww . j a v a2 s.c om*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element rootNode = document.createElement(xpath); document.appendChild(rootNode); Set set = hashmap.entrySet(); Iterator i = set.iterator(); while (i.hasNext()) { Map.Entry me = (Map.Entry) i.next(); Element em = document.createElement(me.getKey().toString()); em.appendChild(document.createTextNode(me.getValue().toString())); rootNode.appendChild(em); // System.out.println("write " + // me.getKey().toString() + "=" // + me.getValue().toString()); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); FileOutputStream fo = new FileOutputStream(xmlFile); StreamResult result = new StreamResult(fo); transformer.transform(source, result); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.owasp.benchmark.score.report.ScatterHome.java
private static Entry<Point2D, String> getMatch(HashMap<Point2D, String> map, Entry<Point2D, String> e1) { for (Entry<Point2D, String> e2 : map.entrySet()) { Double xd = Math.abs(e1.getKey().getX() - e2.getKey().getX()); Double yd = Math.abs(e1.getKey().getY() - e2.getKey().getY()); boolean close = xd < 1 && yd < 3; if (e1 != e2 && e1.getValue() != null && e2.getValue() != null && close) { return e2; }// w w w . j a v a2s . c om } return null; }
From source file:SigningProcess.java
public static String sign(String base64, HashMap map) { String base64string = null;/*from w w w . j a va 2 s . com*/ try { System.out.println("map :" + map); // Getting a set of the entries Set set = map.entrySet(); System.out.println("set :" + set); // Get an iterator Iterator it = set.iterator(); // Display elements while (it.hasNext()) { Entry me = (Entry) it.next(); String key = (String) me.getKey(); if ("privateKey".equalsIgnoreCase(key)) { privateKey = (PrivateKey) me.getValue(); } if ("certificateChain".equalsIgnoreCase(key)) { certificateChain = (X509Certificate[]) me.getValue(); } } OcspClient ocspClient = new OcspClientBouncyCastle(); TSAClient tsaClient = null; for (int i = 0; i < certificateChain.length; i++) { X509Certificate cert = (X509Certificate) certificateChain[i]; String tsaUrl = CertificateUtil.getTSAURL(cert); if (tsaUrl != null) { tsaClient = new TSAClientBouncyCastle(tsaUrl); break; } } List<CrlClient> crlList = new ArrayList<CrlClient>(); crlList.add(new CrlClientOnline(certificateChain)); String property = System.getProperty("java.io.tmpdir"); BASE64Decoder decoder = new BASE64Decoder(); byte[] FileByte = decoder.decodeBuffer(base64); writeByteArraysToFile(property + "_unsigned.pdf", FileByte); // Creating the reader and the stamper PdfReader reader = new PdfReader(property + "_unsigned.pdf"); FileOutputStream os = new FileOutputStream(property + "_signed.pdf"); PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); // appearance.setReason(reason); // appearance.setLocation(location); appearance.setAcro6Layers(false); appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig1"); // Creating the signature ExternalSignature pks = new PrivateKeySignature((PrivateKey) privateKey, DigestAlgorithms.SHA256, providerMSCAPI.getName()); ExternalDigest digest = new BouncyCastleDigest(); MakeSignature.signDetached(appearance, digest, pks, certificateChain, crlList, ocspClient, tsaClient, 0, MakeSignature.CryptoStandard.CMS); InputStream docStream = new FileInputStream(property + "_signed.pdf"); byte[] encodeBase64 = Base64.encodeBase64(IOUtils.toByteArray(docStream)); base64string = new String(encodeBase64); } catch (IOException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (DocumentException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (GeneralSecurityException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } return base64string; }
From source file:com.saltedge.sdk.network.SERestClient.java
private static AsyncHttpClient createHttpClient(HashMap<String, String> headers) { AsyncHttpClient client = isHttpsPrefixInRootUrl() ? new AsyncHttpClient(true, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT) : new AsyncHttpClient(SEConstants.HTTP_PORT); client.setMaxRetriesAndTimeout(DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT); for (HashMap.Entry<String, String> entry : headers.entrySet()) { client.addHeader(entry.getKey(), entry.getValue()); }//w ww .jav a2 s . c om return client; }
From source file:edu.indiana.lib.twinpeaks.util.StatusUtils.java
/** * Get an iterator into the system status map * @param sessionContext Active SessionContext * @return Status map Iterator/*w w w. j av a2 s. c o m*/ */ public static Iterator getStatusMapEntrySetIterator(SessionContext sessionContext) { HashMap statusMap = (HashMap) sessionContext.get("searchStatus"); Set entrySet = Collections.EMPTY_SET; if (statusMap != null) { entrySet = statusMap.entrySet(); } return entrySet.iterator(); }