List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:Main.java
public static void main(String[] args) { SortedMap<String, Integer> sortedMap = new TreeMap<String, Integer>(); sortedMap.put("A", 1); sortedMap.put("B", 2); sortedMap.put("C", 3); sortedMap.put("D", 4); sortedMap.put("E", 5); sortedMap.put("java2s", 6); System.out.println(sortedMap.entrySet()); }
From source file:joshelser.as2015.query.Query.java
public static void main(String[] args) throws Exception { JCommander commander = new JCommander(); final Opts options = new Opts(); commander.addObject(options);/*from w w w . j av a2 s. c om*/ commander.setProgramName("Query"); try { commander.parse(args); } catch (ParameterException ex) { commander.usage(); System.err.println(ex.getMessage()); System.exit(1); } ClientConfiguration conf = ClientConfiguration.loadDefault(); if (null != options.clientConfFile) { conf = new ClientConfiguration(new PropertiesConfiguration(options.clientConfFile)); } conf.withInstance(options.instanceName).withZkHosts(options.zookeepers); ZooKeeperInstance inst = new ZooKeeperInstance(conf); Connector conn = inst.getConnector(options.user, new PasswordToken(options.password)); BatchScanner bs = conn.createBatchScanner(options.table, Authorizations.EMPTY, 16); try { bs.setRanges(Collections.singleton(new Range())); final Text categoryText = new Text("category"); bs.fetchColumn(categoryText, new Text("name")); bs.fetchColumn(new Text("review"), new Text("score")); bs.fetchColumn(new Text("review"), new Text("userId")); bs.addScanIterator(new IteratorSetting(50, "wri", WholeRowIterator.class)); final Text colf = new Text(); Map<String, List<Integer>> scoresByUser = new HashMap<>(); for (Entry<Key, Value> entry : bs) { SortedMap<Key, Value> row = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue()); Iterator<Entry<Key, Value>> iter = row.entrySet().iterator(); if (!iter.hasNext()) { // row was empty continue; } Entry<Key, Value> categoryEntry = iter.next(); categoryEntry.getKey().getColumnFamily(colf); if (!colf.equals(categoryText)) { throw new IllegalArgumentException("Unknown!"); } if (!categoryEntry.getValue().toString().equals("books")) { // not a book review continue; } if (!iter.hasNext()) { continue; } Entry<Key, Value> reviewScore = iter.next(); if (!iter.hasNext()) { continue; } Entry<Key, Value> reviewUserId = iter.next(); String userId = reviewUserId.getValue().toString(); if (userId.equals("unknown")) { // filter unknow user id continue; } List<Integer> scores = scoresByUser.get(userId); if (null == scores) { scores = new ArrayList<>(); scoresByUser.put(userId, scores); } scores.add(Float.valueOf(reviewScore.getValue().toString()).intValue()); } for (Entry<String, List<Integer>> entry : scoresByUser.entrySet()) { int sum = 0; for (Integer val : entry.getValue()) { sum += val; } System.out.println(entry.getKey() + " => " + new Float(sum) / entry.getValue().size()); } } finally { bs.close(); } }
From source file:org.soaplab.admin.ExploreConfig.java
/************************************************************************* * * An entry point//from w w w . jav a 2s. c o m * *************************************************************************/ @SuppressWarnings("unchecked") public static void main(String[] args) { try { BaseCmdLine cmd = getCmdLine(args, ExploreConfig.class); String param = null; // remember System properties before we initialize // Soaplab's Config Properties sysProps = System.getProperties(); // for testing: adding property files if ((param = cmd.getParam("-f")) != null) { title("Adding config property files:"); String[] files = param.split(","); for (String filename : files) { if (Config.addConfigPropertyFile(filename)) msgln("Added: " + filename); else msgln("Failed: " + filename); } msgln(""); } if ((param = cmd.getParam("-xml")) != null) { title("Adding config XML files:"); String[] files = param.split(","); for (String filename : files) { if (Config.addConfigXMLFile(filename)) msgln("Added: " + filename); else msgln("Failed: " + filename); } msgln(""); } // list of configurations if (cmd.hasOption("-lf")) { title("Using property resources (in this order):"); int i = 0; while (true) { Configuration cfg = null; int count = 0; try { cfg = Config.get().getConfiguration(i++); for (Iterator<String> it = cfg.getKeys(); it.hasNext(); count++) it.next(); } catch (IndexOutOfBoundsException e) { break; } if (count == 0) msg(i + ": (empty) "); else msg(i + ": (" + String.format("%1$5d", count) + ") "); if (cfg instanceof FileConfiguration) { msgln(((FileConfiguration) cfg).getFile().getAbsolutePath()); } else if (cfg instanceof SystemConfiguration) { msgln("Java System Properties"); } else if (cfg instanceof BaseConfiguration) { msgln("Directly added properties (no config file)"); } else { msgln(cfg.getClass().getName()); } } msgln(""); } // list of properties boolean listProps = cmd.hasOption("-l"); boolean listAllProps = cmd.hasOption("-la"); if (listProps || listAllProps) { title("Available properties" + (listProps ? " (except System properties):" : ":")); SortedMap<String, String> allProps = new TreeMap<String, String>(); int maxLen = 0; for (Iterator<String> it = Config.get().getKeys(); it.hasNext();) { String key = it.next(); if (listAllProps || !sysProps.containsKey(key)) { if (key.length() > maxLen) maxLen = key.length(); String[] values = Config.get().getStringArray(key); if (values.length != 0) allProps.put(key, StringUtils.join(values, ",")); } } for (Iterator<Map.Entry<String, String>> it = allProps.entrySet().iterator(); it.hasNext();) { Map.Entry<String, String> entry = it.next(); msgln(String.format("%1$-" + maxLen + "s", entry.getKey()) + " => " + entry.getValue()); } msgln(""); } // get properties by prefix if ((param = cmd.getParam("-prefix")) != null) { String serviceName = cmd.getParam("-service"); if (serviceName == null) title("Properties matching prefix:"); else title("Properties matching service name and prefix:"); SortedSet<String> selectedKeys = new TreeSet<String>(); int maxLen = 0; Properties props = Config.getMatchingProperties(param, serviceName, null); for (Enumeration en = props.propertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); if (key.length() > maxLen) maxLen = key.length(); selectedKeys.add(key); } for (Iterator<String> it = selectedKeys.iterator(); it.hasNext();) { String key = it.next(); msgln(String.format("%1$-" + maxLen + "s", key) + " => " + props.getProperty(key)); } msgln(""); } // show individual properties value if (cmd.params.length > 0) { int maxLen = 0; for (int i = 0; i < cmd.params.length; i++) { int len = cmd.params[i].length(); if (len > maxLen) maxLen = len; } title("Selected properties:"); for (int i = 0; i < cmd.params.length; i++) { String value = Config.get().getString(cmd.params[i]); msgln(String.format("%1$-" + maxLen + "s", cmd.params[i]) + " => " + (value == null ? "<null>" : value)); } } } catch (Throwable e) { processErrorAndExit(e); } }
From source file:nu.validator.svgresearch.SvgDownloader.java
/** * @param args/*from w w w. ja v a2s .c o m*/ * @throws IOException * @throws NoSuchAlgorithmException */ public static void main(String[] args) throws IOException, NoSuchAlgorithmException { SortedMap<String, String> theMap = new TreeMap<String, String>(); MessageDigest md = MessageDigest.getInstance("MD5"); IRIFactory fac = new IRIFactory(); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]), "utf-8")); String line; while ((line = in.readLine()) != null) { byte[] md5 = md.digest(line.getBytes("utf-8")); String md5str = toHexString(md5); IRI iri = fac.create("http://upload.wikimedia.org/wikipedia/commons/" + md5str.substring(0, 1) + '/' + md5str.substring(0, 2) + '/' + line); String uri = iri.toASCIIString(); theMap.put(md5str, uri); } Writer out = new OutputStreamWriter(new FileOutputStream(args[1]), "utf-8"); for (Map.Entry<String, String> entry : theMap.entrySet()) { out.write(entry.getKey()); out.write('\t'); out.write(entry.getValue()); out.write('\n'); } out.flush(); out.close(); File dir = new File(args[2]); int total = theMap.size(); int count = 0; for (Map.Entry<String, String> entry : theMap.entrySet()) { File target = new File(dir, entry.getKey() + ".svg"); retrieve(entry.getValue(), target); count++; System.out.println(((double) count) / ((double) total)); } }
From source file:Main.java
public static String createXML(SortedMap<String, Object> parameters) { StringBuilder buffer = new StringBuilder(); buffer.append("<xml>"); for (Entry<String, Object> entry : parameters.entrySet()) { String k = (String) entry.getKey(); String v = String.valueOf(entry.getValue()); if (!"null".equals(v) && !"".equals(v)) { buffer.append("<" + k + ">" + v + "</" + k + ">" + "\r\n"); }/*from w w w .j a va2 s .co m*/ } buffer.append("</xml>"); return buffer.toString(); }
From source file:Main.java
public static String createXml(SortedMap<String, String> sm, String sign) { StringBuilder sb = new StringBuilder(); sb.append("<xml>"); Set<Map.Entry<String, String>> set = sm.entrySet(); for (Iterator<Map.Entry<String, String>> it = set.iterator(); it.hasNext();) { Map.Entry<String, String> entry = it.next(); sb.append("<").append(entry.getKey()).append(">"); sb.append(entry.getValue());/*from www . j av a 2s . c o m*/ sb.append("</").append(entry.getKey()).append(">"); } sb.append("<sign>").append(sign).append("</sign>"); sb.append("</xml>"); return sb.toString(); }
From source file:Main.java
public static String toXml(SortedMap<String, String> params) { StringBuilder sb = new StringBuilder(); sb.append("<xml>"); for (SortedMap.Entry<String, String> entry : params.entrySet()) { sb.append("<").append(entry.getKey()).append(">"); sb.append(entry.getValue());// w w w.j av a 2 s .c om sb.append("</").append(entry.getKey()).append(">"); } sb.append("</xml>"); return sb.toString(); }
From source file:Main.java
public static String toXml(SortedMap<String, String> params, String sign) { StringBuilder sb = new StringBuilder(); sb.append("<xml>"); for (SortedMap.Entry<String, String> entry : params.entrySet()) { sb.append("<").append(entry.getKey()).append(">"); sb.append(entry.getValue());// w w w. j a v a2 s.c o m sb.append("</").append(entry.getKey()).append(">"); } sb.append("<").append("sign").append(">"); sb.append(sign); sb.append("</").append("sign").append(">"); sb.append("</xml>"); return sb.toString(); }
From source file:no.digipost.api.useragreements.client.filters.request.RequestMessageSignatureUtil.java
private static String getCanonicalHeaderRepresentation(final RequestToSign request) { SortedMap<String, String> headers = request.getHeaders(); StringBuilder headersString = new StringBuilder(); for (Entry<String, String> entry : headers.entrySet()) { String key = entry.getKey(); if (isHeaderForSignature(key)) { headersString.append(key.toLowerCase() + ": " + entry.getValue() + "\n"); }/*www . j a va 2 s . c om*/ } return headersString.toString(); }
From source file:org.jenkinsci.plugins.karotz.KarotzUtil.java
/** * Builds query string.//from ww w. j av a2 s . com * * @param params key and value pairs. * @return query string. */ public static String buildQuery(Map<String, String> params) { if (params == null) { return ""; } SortedMap<String, String> sortedParams = new TreeMap<String, String>(params); Iterator<Map.Entry<String, String>> iter = sortedParams.entrySet().iterator(); StringBuilder buffer = new StringBuilder(); Map.Entry<String, String> next = iter.next(); buffer.append(next.getKey()).append("=").append(Util.rawEncode(next.getValue())); while (iter.hasNext()) { next = iter.next(); buffer.append("&").append(next.getKey()).append("=").append(Util.rawEncode(next.getValue())); } return buffer.toString(); }