List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.myfaces.tomahawk.util.ErrorPageWriter.java
private static void writeVariables(Writer writer, Map vars, String caption) throws IOException { writer.write("<table><caption>"); writer.write(caption);/*from w w w . j a va2 s . com*/ writer.write( "</caption><thead><tr><th style=\"width: 10%; \">Name</th><th style=\"width: 90%; \">Value</th></tr></thead><tbody>"); boolean written = false; if (!vars.isEmpty()) { SortedMap map = new TreeMap(vars); Map.Entry entry = null; String key = null; for (Iterator itr = map.entrySet().iterator(); itr.hasNext();) { entry = (Map.Entry) itr.next(); key = entry.getKey().toString(); if (key.indexOf('.') == -1) { writer.write("<tr><td>"); writer.write(key.replaceAll("<", TS)); writer.write("</td><td>"); writer.write(entry.getValue().toString().replaceAll("<", TS)); writer.write("</td></tr>"); written = true; } } } if (!written) { writer.write("<tr><td colspan=\"2\"><em>None</em></td></tr>"); } writer.write("</tbody></table>"); }
From source file:org.wso2.extension.siddhi.store.rdbms.util.RDBMSTableUtils.java
public static void resolveConditionForContainsCheck(PreparedStatement stmt, RDBMSCompiledCondition compiledCondition, Map<String, Object> conditionParameterMap, int seed) throws SQLException { SortedMap<Integer, Object> parameters = compiledCondition.getParameters(); for (Map.Entry<Integer, Object> entry : parameters.entrySet()) { Object parameter = entry.getValue(); if (parameter instanceof Constant) { Constant constant = (Constant) parameter; if (entry.getKey().equals(compiledCondition.getOrdinalOfContainPattern())) { populateStatementWithSingleElement(stmt, seed + entry.getKey(), constant.getType(), "%" + constant.getValue() + "%"); } else { populateStatementWithSingleElement(stmt, seed + entry.getKey(), constant.getType(), constant.getValue()); }//w w w . ja v a 2 s.c o m } else { Attribute variable = (Attribute) parameter; if (entry.getKey().equals(compiledCondition.getOrdinalOfContainPattern())) { populateStatementWithSingleElement(stmt, seed + entry.getKey(), variable.getType(), "%" + conditionParameterMap.get(variable.getName()) + "%"); } else { populateStatementWithSingleElement(stmt, seed + entry.getKey(), variable.getType(), conditionParameterMap.get(variable.getName())); } } } }
From source file:org.zaproxy.zap.spider.URLCanonicalizer.java
/** * Canonicalize the query string./*from w w w . j a v a2s .c o m*/ * * @param sortedParamMap Parameter name-value pairs in lexicographical order. * @return Canonical form of query string. */ private static String canonicalize(final SortedMap<String, String> sortedParamMap) { if (sortedParamMap == null || sortedParamMap.isEmpty()) { return ""; } final StringBuilder sb = new StringBuilder(100); for (Map.Entry<String, String> pair : sortedParamMap.entrySet()) { final String key = pair.getKey().toLowerCase(); // Ignore irrelevant parameters if (IRRELEVANT_PARAMETERS.contains(key) || key.startsWith("utm_")) { continue; } if (sb.length() > 0) { sb.append('&'); } sb.append(pair.getKey()); if (!pair.getValue().isEmpty()) { sb.append('='); sb.append(pair.getValue()); } } return sb.toString(); }
From source file:com.comcast.cmb.common.util.AuthUtil.java
private static String normalizeQueryString(Map<String, String> parameters) throws UnsupportedEncodingException { SortedMap<String, String> sorted = new TreeMap<String, String>(); sorted.putAll(parameters);// w w w . jav a 2 s. co m StringBuilder builder = new StringBuilder(); Iterator<Map.Entry<String, String>> pairs = sorted.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); String value = pair.getValue(); builder.append(urlEncode(key, false)); builder.append("="); builder.append(urlEncode(value, false)); if (pairs.hasNext()) { builder.append("&"); } } return builder.toString(); }
From source file:net.sourceforge.seqware.pipeline.plugins.WorkflowStatusChecker.java
private static String sgeConcat(SortedMap<Integer, File> idFiles) { StringBuilder sb = new StringBuilder(); for (Map.Entry<Integer, File> e : idFiles.entrySet()) { File f = e.getValue();//from w w w. j a va2 s.c o m Matcher m = SGE_FILE.matcher(f.getName()); m.find(); String jobName = m.group(1); sb.append("-----------------------------------------------------------------------"); sb.append("\nJob Name: "); sb.append(jobName); sb.append("\nJob ID: "); sb.append(e.getKey()); sb.append("\nFile: "); sb.append(f.getAbsolutePath()); sb.append("\nUpdated: "); sb.append(new Date(f.lastModified())); sb.append("\nContents:\n"); try { sb.append(stripInvalidXmlCharacters(FileUtils.readFileToString(f))); } catch (IOException ex) { sb.append(" *** ERROR READING FILE: "); sb.append(ex.getMessage()); sb.append(" ***"); } if (sb.charAt(sb.length() - 1) != '\n') { sb.append("\n"); } sb.append("-----------------------------------------------------------------------\n\n"); } return sb.toString(); }
From source file:org.dcm4che3.conf.core.misc.DeepEquals.java
/** * Deeply compare two SortedMap instances. This method walks the Maps in order, * taking advantage of the fact that they Maps are SortedMaps. * @param map1 SortedMap one// w ww. j a v a2s .c o m * @param map2 SortedMap two * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set containing items that have already been compared, to prevent cycles. * @return false if the Maps are for certain not equals. 'true' indicates that 'on the surface' the maps * are equal, however, it will place the contents of the Maps on the stack for further comparisons. */ private static boolean compareSortedMap(SortedMap map1, SortedMap map2, LinkedList stack, Set visited) { // Same instance check already performed... if (map1.size() != map2.size()) { return false; } Iterator i1 = map1.entrySet().iterator(); Iterator i2 = map2.entrySet().iterator(); while (i1.hasNext()) { Map.Entry entry1 = (Map.Entry) i1.next(); Map.Entry entry2 = (Map.Entry) i2.next(); // Must split the Key and Value so that Map.Entry's equals() method is not used. DualKey dk = new DualKey(entry1.getKey(), entry2.getKey()); if (!visited.contains(dk)) { // Push Keys for further comparison stack.addFirst(dk); } dk = new DualKey(entry1.getValue(), entry2.getValue()); if (!visited.contains(dk)) { // Push values for further comparison stack.addFirst(dk); } } return true; }
From source file:org.opennms.netmgt.mib2events.Mib2Events.java
private static List<Varbindsdecode> getTrapVarbindsDecode(MibValueSymbol trapValueSymbol) { Map<String, Varbindsdecode> decode = new LinkedHashMap<String, Varbindsdecode>(); int vbNum = 1; for (MibValue vb : getTrapVars(trapValueSymbol)) { String parmName = "parm[#" + vbNum + "]"; SnmpObjectType snmpObjectType = ((SnmpObjectType) ((ObjectIdentifierValue) vb).getSymbol().getType()); if (snmpObjectType.getSyntax().getClass().equals(IntegerType.class)) { IntegerType integerType = (IntegerType) snmpObjectType.getSyntax(); if (integerType.getAllSymbols().length > 0) { SortedMap<Integer, String> map = new TreeMap<Integer, String>(); for (MibValueSymbol sym : integerType.getAllSymbols()) { map.put(new Integer(sym.getValue().toString()), sym.getName()); }/*from w ww . java 2 s . c om*/ for (Entry<Integer, String> entry : map.entrySet()) { if (!decode.containsKey(parmName)) { Varbindsdecode newVarbind = new Varbindsdecode(); newVarbind.setParmid(parmName); decode.put(newVarbind.getParmid(), newVarbind); } Decode d = new Decode(); d.setVarbinddecodedstring(entry.getValue()); d.setVarbindvalue(entry.getKey().toString()); decode.get(parmName).addDecode(d); } } } vbNum++; } return new ArrayList<Varbindsdecode>(decode.values()); }
From source file:com.bytelightning.opensource.pokerface.ScriptHelperImpl.java
/** * Canonicalize the query string./* w w w . j a v a 2 s. co m*/ * * @param sortedParamMap Parameter name-value pairs in lexicographical order. * @return Canonical form of query string. */ private static String Canonicalize(final SortedMap<String, String> sortedParamMap) { if (sortedParamMap == null || sortedParamMap.isEmpty()) return ""; final StringBuffer sb = new StringBuffer(350); final Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<String, String> pair = iter.next(); sb.append(PercentEncodeRfc3986(pair.getKey())); sb.append('='); sb.append(PercentEncodeRfc3986(pair.getValue())); if (iter.hasNext()) sb.append('&'); } return sb.toString(); }
From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java
/** * Create a base 64 encoded SHA1 hash key for a given XML element. The key * is based on the element name, the attribute names and their values. Child * elements are ignored. Attributes named 'z' are not concluded since they * contain the hash key itself.//from w w w . ja v a 2 s . c o m * * @param element The element to create the base 64 encoded hash key for * @return the unique key */ public static String calculateUniqueKeyFor(Element element) { StringBuilder sb = new StringBuilder(); sb.append(element.getTagName()); NamedNodeMap attributes = element.getAttributes(); SortedMap<String, String> attrKVStore = Collections.synchronizedSortedMap(new TreeMap<String, String>()); for (int i = 0; i < attributes.getLength(); i++) { Node attr = attributes.item(i); if (!"z".equals(attr.getNodeName()) && !attr.getNodeName().startsWith("_")) { attrKVStore.put(attr.getNodeName(), attr.getNodeValue()); } } for (Entry<String, String> entry : attrKVStore.entrySet()) { sb.append(entry.getKey()).append(entry.getValue()); } return base64(sha1(sb.toString().getBytes())); }
From source file:com.griddynamics.jagger.engine.e1.scenario.DefaultWorkloadSuggestionMaker.java
private static Integer findClosestPoint(BigDecimal desiredTps, Map<Integer, Pair<Long, BigDecimal>> stats) { final int MAX_POINTS_FOR_REGRESSION = 10; SortedMap<Long, Integer> map = Maps.newTreeMap(new Comparator<Long>() { @Override// w w w. j a va 2 s . com public int compare(Long first, Long second) { return second.compareTo(first); } }); for (Map.Entry<Integer, Pair<Long, BigDecimal>> entry : stats.entrySet()) { map.put(entry.getValue().getFirst(), entry.getKey()); } if (map.size() < 2) { throw new IllegalArgumentException("Not enough stats to calculate point"); } // <time><number of threads> - sorted by time Iterator<Map.Entry<Long, Integer>> iterator = map.entrySet().iterator(); SimpleRegression regression = new SimpleRegression(); Integer tempIndex; double previousValue = -1.0; double value; double measuredTps; log.debug("Selecting next point for balancing"); int indx = 0; while (iterator.hasNext()) { tempIndex = iterator.next().getValue(); if (previousValue < 0.0) { previousValue = tempIndex.floatValue(); } value = tempIndex.floatValue(); measuredTps = stats.get(tempIndex).getSecond().floatValue(); regression.addData(value, measuredTps); log.debug(String.format(" %7.2f %7.2f", value, measuredTps)); indx++; if (indx > MAX_POINTS_FOR_REGRESSION) { break; } } double intercept = regression.getIntercept(); double slope = regression.getSlope(); double approxPoint; // if no slope => use previous number of threads if (Math.abs(slope) > 1e-12) { approxPoint = (desiredTps.doubleValue() - intercept) / slope; } else { approxPoint = previousValue; } // if approximation point is negative - ignore it if (approxPoint < 0) { approxPoint = previousValue; } log.debug(String.format("Next point %7d (target tps: %7.2f)", (int) Math.round(approxPoint), desiredTps.doubleValue())); return (int) Math.round(approxPoint); }