List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:Main.java
public static String parseFromMap(Map<String, String> mappy) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> e : mappy.entrySet()) { if (sb.length() > 0) { sb.append(LINE_SEP);/*from w ww .jav a 2 s . co m*/ } sb.append(e.getKey()).append(EQUALS).append(e.getValue()); } return sb.toString(); }
From source file:Main.java
public static <T, E> T getKeyByValue(Map<T, E> map, E value) { if (map == null) { return null; }// w w w . j a v a 2 s .c o m for (Entry<T, E> entry : map.entrySet()) { if (entry.getValue().equals(value)) { return entry.getKey(); } } return null; }
From source file:Main.java
public static void listEntries(Map<String, String> map) { System.out.println("Entry Set:"); // Get the entry Set Set<Map.Entry<String, String>> entries = map.entrySet(); entries.forEach((Map.Entry<String, String> entry) -> { String key = entry.getKey(); String value = entry.getValue(); System.out.println("key=" + key + ", value=" + value); });/*from ww w.j a va 2s .c om*/ }
From source file:Main.java
public static JSONObject parseToJSONObject(Map<String, Object> map) { JSONObject jsonObject = new JSONObject(); for (Entry<String, Object> entry : map.entrySet()) { try {/*from ww w . j a va2 s .c o m*/ jsonObject.put(entry.getKey(), entry.getValue()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return jsonObject; }
From source file:com.joliciel.frenchTreebank.util.DaoUtils.java
public static void LogParameters(Map<String, Object> paramMap) { if (LOG.isDebugEnabled()) { for (Object obj : paramMap.entrySet()) { @SuppressWarnings("rawtypes") Entry entry = (Entry) obj;// ww w . jav a2s.co m LOG.debug( entry.getKey() + ": " + (entry.getValue() == null ? "null" : entry.getValue().toString())); } } }
From source file:Main.java
/** * Formats HTTP headers./*from w ww. j a v a 2s . c om*/ * * @param headers * The headers. * @return Headers as a string */ private static String formatHttpHeaders(Map<String, String> headers) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> header : headers.entrySet()) { sb.append(String.format("%s : %s\n", header.getKey(), header.getValue())); } return sb.toString(); }
From source file:Main.java
/** * /*from w w w .j ava2s.co m*/ * @param <T> * @param <U> * @param map * @return */ public static <T, U extends Comparable<U>> T getGreatest(Map<T, U> map) { T max_key = null; U max_value = null; for (Entry<T, U> e : map.entrySet()) { T key = e.getKey(); U value = e.getValue(); if (max_value == null || value.compareTo(max_value) > 0) { max_value = value; max_key = key; } } // FOR return (max_key); }
From source file:MapUtils.java
/** * Sorts map by values in ascending order. * //from w w w. j a v a 2 s . c om * @param <K> * map keys type * @param <V> * map values type * @param map * @return */ public static <K, V extends Comparable<V>> LinkedHashMap<K, V> sortMapByValue(Map<K, V> map) { List<Entry<K, V>> sortedEntries = sortEntriesByValue(map.entrySet()); LinkedHashMap<K, V> sortedMap = new LinkedHashMap<K, V>(map.size()); for (Entry<K, V> entry : sortedEntries) { sortedMap.put(entry.getKey(), entry.getValue()); } return sortedMap; }
From source file:Main.java
/** * Returns a map of all values in <b>a</b> who's value is not a * key in <b>b</b>.//from w w w .j a va 2 s .co m * * @param a The source map of key value pairs used to populate * the resulting map. * * @param b The exclusion map, who's keys are the exclusions * matching map <b>a</b>'s values. * * @return a map of all values in <b>a</b> who's value is not a * key in <b>b</b>. */ public static <K, V> Map<K, V> outerJoin(Map<K, V> a, Map<V, ?> b) { Map<K, V> buffer = new HashMap<K, V>(); for (Map.Entry<K, V> entry : a.entrySet()) { if (!b.containsKey(entry.getValue())) { buffer.put(entry.getKey(), entry.getValue()); } } return buffer; }
From source file:org.eclipse.dirigible.cli.apis.ImportProjectAPI.java
private static void addHeaders(HttpPost postRequest, Map<String, String> headers) { for (Entry<String, String> header : headers.entrySet()) { postRequest.setHeader(header.getKey(), header.getValue()); }/* w ww . j a v a 2s .c o m*/ }