List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:Main.java
public static Map<String, String> takeFromSetMap(final Map<String, Set<String>> pMap, final String glue) { final Map<String, String> resMap = new HashMap<String, String>(100); final Iterator<String> iter = pMap.keySet().iterator(); String key;//from w ww .j av a2 s . c o m while (iter.hasNext()) { key = iter.next(); resMap.put(key, implode(pMap.get(key), glue)); } return resMap; }
From source file:Main.java
public static <KeyT, ValueT> boolean mapsEquals(Map<KeyT, ValueT> map1, Map<KeyT, ValueT> map2) { if (map1 == null) { return map2 == null || map2.isEmpty(); }//from w w w . jav a 2 s. c o m if (map1.size() != map2.size() || !map1.keySet().containsAll(map2.keySet())) { return false; } for (KeyT key : map1.keySet()) { final ValueT value1 = map1.get(key); final ValueT value2 = map2.get(key); if (!equals(value1, value2)) { return false; } } return true; }
From source file:Main.java
/** * Build a List from the entry set of a map. * //from www . j ava2 s . c o m * <p> * NOTE: This should not be necessary but there are bugs * when you iterate using map.entrySet().iterator(). * </p> * * @param map the map to use as the source * @param sortedByValue whether or not to sort the values * of the created list * @return a list containing all values of the given * map */ public static List mapToEntryList(Map map, boolean sortedByValue) { List retList = new ArrayList(); if (map.isEmpty()) { return Collections.EMPTY_LIST; } Iterator it = map.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); Object obj = map.get(key); retList.add(obj); } // Sort if (sortedByValue) Collections.sort(retList); return retList; }
From source file:Main.java
public static boolean getProperty(String filePath, String fileName, Map<String, String> propertyMap) { try {/* ww w . j av a 2 s . c om*/ Properties p = loadPropertyInstance(filePath, fileName); for (String name : propertyMap.keySet()) { propertyMap.put(name, p.getProperty(name, propertyMap.get(name))); } return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
public static void checkFutures(Map<? extends Object, Future<Void>> futures, int maxSize) throws InterruptedException, ExecutionException { while (futures.size() > maxSize) { for (Iterator<? extends Object> i = futures.keySet().iterator(); i.hasNext();) { Object key = i.next(); futures.get(key).get();//from w w w . ja va 2 s.c o m i.remove(); } } }
From source file:Main.java
public static String encodeUrl(Map<String, String> param) { if (param == null) { return ""; }/*from ww w . j a va 2 s . c om*/ StringBuilder sb = new StringBuilder(); Set<String> keys = param.keySet(); boolean first = true; for (String key : keys) { String value = param.get(key); //pain...EditMyProfileDao params' values can be empty if (!TextUtils.isEmpty(value) || key.equals("description") || key.equals("url")) { if (first) { first = false; } else { sb.append("&"); } try { sb.append(URLEncoder.encode(key, "UTF-8")).append("=") .append(URLEncoder.encode(param.get(key), "UTF-8")); } catch (UnsupportedEncodingException e) { } } } return sb.toString(); }
From source file:Main.java
public static String dump(Map in) { if (in == null) return "null"; StringBuilder sb = new StringBuilder("{"); for (Iterator it = in.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); sb.append(key).append(":").append(in.get(key)); if (it.hasNext()) sb.append(", "); }/*from w ww. jav a2 s .c om*/ sb.append("}"); return sb.toString(); }
From source file:com.vk.sdk.util.VKJsonHelper.java
/** * Converts object to JSON object, if possible * * @param object object to serialize to json * @return Completed json object/* ww w . ja v a 2s. c om*/ * @throws JSONException */ public static Object toJSON(Object object) throws JSONException { if (object instanceof Map) { JSONObject json = new JSONObject(); Map map = (Map) object; for (Object key : map.keySet()) { json.put(key.toString(), toJSON(map.get(key))); } return json; } else if (object instanceof Iterable) { JSONArray json = new JSONArray(); for (Object value : ((Iterable) object)) { json.put(value); } return json; } else { return object; } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.comments.pipeline.ExtendedMalletTopicModelEstimator.java
/** * Loads serialized vocabulary ({@code HashMap<String, Integer>}) from file * * @return vocabulary entries (key set)/*from ww w.j a v a2 s. com*/ * @throws IOException * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") public static Set<String> readVocabulary(File vocabularyFile) throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(vocabularyFile)); Map<String, Integer> map = (Map<String, Integer>) ois.readObject(); IOUtils.closeQuietly(ois); return map.keySet(); }
From source file:Main.java
public static String encodeParam(Map<String, String> params) { if (params == null) return ""; StringBuilder sb = new StringBuilder(); for (String key : params.keySet()) { Object val = params.get(key); if (sb.length() != 0) sb.append("&"); if (val instanceof Long[]) { Long[] longval = (Long[]) val; try { for (int i = 0; i < longval.length; i++) { String valStr = (val == null) ? "" : URLEncoder.encode(longval[i].toString(), "utf-8"); if (i != longval.length - 1) sb.append(key + "=" + valStr + "&"); else sb.append(key + "=" + valStr); }//from www . ja v a 2 s . com } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else { try { String valStr = (val == null) ? "" : URLEncoder.encode(val.toString(), "utf-8"); sb.append(key + "=" + valStr); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return sb.toString(); }