List of usage examples for java.util SortedMap put
V put(K key, V value);
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); SortedMap<String, Integer> map = sortedMap.subMap("B", "E"); System.out.println(map);//from ww w . j a v a 2 s . com }
From source file:Main.java
public static void main(String[] args) { Comparator<String> keyComparator = Comparator.comparing(String::length) .thenComparing(String::compareToIgnoreCase); SortedMap<String, String> sMap = new TreeMap<>(keyComparator); sMap.put("CSS", "style"); sMap.put("HTML", "mark up"); sMap.put("Oracle", "database"); sMap.put("XML", "data"); SortedMap<String, String> subMap = sMap.subMap("CSS", "XML"); System.out.println(subMap);//w ww .j a va 2s . c o m // Get the first and last keys String firstKey = sMap.firstKey(); String lastKey = sMap.lastKey(); System.out.println("First Key: " + firstKey); System.out.println("Last key: " + lastKey); }
From source file:Main.java
public static void main(String[] args) { // create map SortedMap<String, String> map = new TreeMap<String, String>(); // populate the map map.put("1", "A"); map.put("2", "B"); map.put("3", "from java2s.com"); // create a sorted map SortedMap<String, String> sortedmap = (SortedMap<String, String>) Collections.synchronizedSortedMap(map); System.out.println("Synchronized sorted map is :" + sortedmap); }
From source file:Main.java
public static void main(String[] s) { // create sorted map SortedMap<String, String> map = new TreeMap<String, String>(); // populate the set map.put("1", "New"); map.put("2", "to"); map.put("3", "java2s.com"); System.out.println("Initial sorted map value: " + map); // create unmodifiable sorted map Map<String, String> unmodsortmap = Collections.unmodifiableSortedMap(map); // try to modify the sorted map unmodsortmap.put("4", "Modify"); }
From source file:CollectionAll.java
public static void main(String[] args) { List list1 = new LinkedList(); list1.add("list"); list1.add("dup"); list1.add("x"); list1.add("dup"); traverse(list1);/*from w w w . j av a2s . c o m*/ List list2 = new ArrayList(); list2.add("list"); list2.add("dup"); list2.add("x"); list2.add("dup"); traverse(list2); Set set1 = new HashSet(); set1.add("set"); set1.add("dup"); set1.add("x"); set1.add("dup"); traverse(set1); SortedSet set2 = new TreeSet(); set2.add("set"); set2.add("dup"); set2.add("x"); set2.add("dup"); traverse(set2); LinkedHashSet set3 = new LinkedHashSet(); set3.add("set"); set3.add("dup"); set3.add("x"); set3.add("dup"); traverse(set3); Map m1 = new HashMap(); m1.put("map", "Java2s"); m1.put("dup", "Kava2s"); m1.put("x", "Mava2s"); m1.put("dup", "Lava2s"); traverse(m1.keySet()); traverse(m1.values()); SortedMap m2 = new TreeMap(); m2.put("map", "Java2s"); m2.put("dup", "Kava2s"); m2.put("x", "Mava2s"); m2.put("dup", "Lava2s"); traverse(m2.keySet()); traverse(m2.values()); LinkedHashMap /* from String to String */ m3 = new LinkedHashMap(); m3.put("map", "Java2s"); m3.put("dup", "Kava2s"); m3.put("x", "Mava2s"); m3.put("dup", "Lava2s"); traverse(m3.keySet()); traverse(m3.values()); }
From source file:com.renren.ntc.sg.util.wxpay.https.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileInputStream instream = new FileInputStream( new File("/Users/allenz/Downloads/wx_cert/apiclient_cert.p12")); try {//from ww w . j a v a2s . c om keyStore.load(instream, Constants.mch_id.toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, Constants.mch_id.toCharArray()) .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpPost post = new HttpPost("https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"); System.out.println("executing request" + post.getRequestLine()); String openid = "oQfDLjmZD7Lgynv6vuoBlWXUY_ic"; String nonce_str = Sha1Util.getNonceStr(); String orderId = SUtils.getOrderId(); String re_user_name = "?"; String amount = "1"; String desc = ""; String spbill_create_ip = "123.56.102.224"; String txt = TXT.replace("{mch_appid}", Constants.mch_appid); txt = txt.replace("{mchid}", Constants.mch_id); txt = txt.replace("{openid}", openid); txt = txt.replace("{nonce_str}", nonce_str); txt = txt.replace("{partner_trade_no}", orderId); txt = txt.replace("{check_name}", "FORCE_CHECK"); txt = txt.replace("{re_user_name}", re_user_name); txt = txt.replace("{amount}", amount); txt = txt.replace("{desc}", desc); txt = txt.replace("{spbill_create_ip}", spbill_create_ip); SortedMap<String, String> map = new TreeMap<String, String>(); map.put("mch_appid", Constants.mch_appid); map.put("mchid", Constants.mch_id); map.put("openid", openid); map.put("nonce_str", nonce_str); map.put("partner_trade_no", orderId); //FORCE_CHECK| OPTION_CHECK | NO_CHECK map.put("check_name", "OPTION_CHECK"); map.put("re_user_name", re_user_name); map.put("amount", amount); map.put("desc", desc); map.put("spbill_create_ip", spbill_create_ip); String sign = SUtils.createSign(map).toUpperCase(); txt = txt.replace("{sign}", sign); post.setEntity(new StringEntity(txt, "utf-8")); CloseableHttpResponse response = httpclient.execute(post); try { HttpEntity entity = response.getEntity(); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); String text; StringBuffer sb = new StringBuffer(); while ((text = bufferedReader.readLine()) != null) { sb.append(text); } String resp = sb.toString(); LoggerUtils.getInstance().log(String.format("req %s rec %s", txt, resp)); if (isOk(resp)) { String payment_no = getValue(resp, "payment_no"); LoggerUtils.getInstance() .log(String.format("order %s pay OK payment_no %s", orderId, payment_no)); } } EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bAgreementMeasures.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { String inputDir = args[0];//from w w w. j ava2 s .co m // all annotations List<AnnotatedArgumentPair> allArgumentPairs = new ArrayList<>(); Collection<File> files = IOHelper.listXmlFiles(new File(inputDir)); for (File file : files) { allArgumentPairs.addAll((List<AnnotatedArgumentPair>) XStreamTools.getXStream().fromXML(file)); } // for collecting the rank of n-th best worker per HIT SortedMap<Integer, DescriptiveStatistics> nThWorkerOnHITRank = new TreeMap<>(); // confusion matrix wrt. gold data for each n-th best worker on HIT SortedMap<Integer, ConfusionMatrix> nThWorkerOnHITConfusionMatrix = new TreeMap<>(); // initialize maps for (int i = 0; i < TOP_K_VOTES; i++) { nThWorkerOnHITRank.put(i, new DescriptiveStatistics()); nThWorkerOnHITConfusionMatrix.put(i, new ConfusionMatrix()); } for (AnnotatedArgumentPair argumentPair : allArgumentPairs) { // sort turker rank and their vote SortedMap<Integer, String> rankAndVote = new TreeMap<>(); System.out.println(argumentPair.mTurkAssignments.size()); for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) { rankAndVote.put(assignment.getTurkRank(), assignment.getValue()); } String goldLabel = argumentPair.getGoldLabel(); System.out.println(rankAndVote); // top K workers for the HIT List<String> topKVotes = new ArrayList<>(rankAndVote.values()).subList(0, TOP_K_VOTES); // rank of top K workers List<Integer> topKRanks = new ArrayList<>(rankAndVote.keySet()).subList(0, TOP_K_VOTES); System.out.println("Top K votes: " + topKVotes); System.out.println("Top K ranks: " + topKRanks); // extract only category (a1, a2, or equal) List<String> topKVotesOnlyCategory = new ArrayList<>(); for (String vote : topKVotes) { String category = vote.split("_")[2]; topKVotesOnlyCategory.add(category); } System.out.println("Top " + TOP_K_VOTES + " workers' decisions: " + topKVotesOnlyCategory); if (goldLabel == null) { System.out.println("No gold label estimate for " + argumentPair.getId()); } else { // update statistics for (int i = 0; i < TOP_K_VOTES; i++) { nThWorkerOnHITConfusionMatrix.get(i).increaseValue(goldLabel, topKVotesOnlyCategory.get(i)); // rank is +1 (we don't start ranking from zero) nThWorkerOnHITRank.get(i).addValue(topKRanks.get(i) + 1); } } } for (int i = 0; i < TOP_K_VOTES; i++) { System.out.println("n-th worker : " + (i + 1) + " -----------"); System.out.println(nThWorkerOnHITConfusionMatrix.get(i).printNiceResults()); System.out.println(nThWorkerOnHITConfusionMatrix.get(i)); System.out.println("Average rank: " + nThWorkerOnHITRank.get(i).getMean() + ", stddev " + nThWorkerOnHITRank.get(i).getStandardDeviation()); } }
From source file:Main.java
public static <T extends Comparable, U> SortedMap<T, U> putObjectSortedMap(SortedMap<T, U> map, T key, U value) {/*from w ww. jav a 2 s . com*/ if (map == null) { map = new TreeMap<T, U>(); } map.put(key, value); return map; }
From source file:org.smigo.user.Language.java
public static Map<String, String> getLanguagesForDisplay(Enumeration<Locale> locales, Locale additionalLocale) { SortedMap<String, String> ret = new TreeMap<>(); for (Language t : Language.values()) { ret.put(t.locale.toString(), StringUtils.capitalize(t.locale.getDisplayName(t.locale))); }/*from ww w . j ava2s . c o m*/ while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); ret.put(locale.toString(), StringUtils.capitalize(locale.getDisplayName(locale))); } ret.put(additionalLocale.toString(), StringUtils.capitalize(additionalLocale.getDisplayName(additionalLocale))); return ret; }
From source file:com.ai.smart.bottom.helper.MacUtils.java
public static JSONObject sort(JSONObject json) { Set<String> iteratorKeys = json.keySet(); SortedMap<String, Object> map = new TreeMap<String, Object>(); for (String str : iteratorKeys) { map.put(str, json.get(str)); }//from w ww . ja va 2s.c o m Set<String> mapkeys = map.keySet(); JSONObject json2 = new JSONObject(); for (String s : mapkeys) { json2.put(s, map.get(s)); } return json2; }