List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:Main.java
public static String getStringByMap(Map<String, Object> map) { StringBuffer sb = new StringBuffer(100); for (Map.Entry<String, Object> m : map.entrySet()) { String key = m.getKey();/*from w w w . j a v a 2 s . c o m*/ Object value = m.getValue(); if (value != null) { String clsName = value.getClass().getName(); if (value.getClass().isArray()) sb.append("[").append(key).append(":").append("ARRAY").append(":") .append(toStringByArray((Object[]) value)).append("]"); else if ((("java.lang.String".equals(clsName)) || ("java.lang.Integer".equals(clsName)) || ("java.lang.Long".equals(clsName)) || ("java.lang.Boolean".equals(clsName)) || ("java.util.Date".equals(clsName))) && (!"".equals(value.toString()))) { sb.append("[").append(key).append(":").append(value.getClass().getName()).append(":") .append(esc(value.toString())).append("]"); } } } return sb.toString(); }
From source file:io.fabric8.spring.cloud.kubernetes.archaius.ArchaiusConfigMapSourceConfiguration.java
private static Map<String, Object> asObjectMap(Map<String, String> source) { return source.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
From source file:Main.java
/** * Sanitizes the XML represented by {@code xml} by replacing dirty header XML * snippets in the {@code dirtyXmlMap} map with clean header XML snippets from * the {@code cleanXmlMap} map./*w ww. j a va 2 s .c om*/ * * @param xml the XML to sanitize * @param dirtyXmlMap a map of tag name to dirty XML header * @param cleanXmlMap a map of tag name to clean XML header * @return a sanitized copy of the XML with all sensitive tags masked */ private static String sanitizeXml(StringBuilder xml, Map<String, String> dirtyXmlMap, Map<String, String> cleanXmlMap) { for (Entry<String, String> cleanXml : cleanXmlMap.entrySet()) { String dirtyXml = dirtyXmlMap.get(cleanXml.getKey()); String endTag = cleanXml.getKey() + ">"; int startIndex = xml.indexOf(dirtyXml.split(" ")[0]); int endIndex = xml.lastIndexOf(endTag) + endTag.length(); xml = xml.replace(startIndex, endIndex, cleanXml.getValue()); } return xml.toString(); }
From source file:Main.java
public static <K, V> void forEach(Map<K, V> m, BiConsumer<K, V> consumer) { if (isNullOrEmpty(m)) { return;//from w ww .j av a 2 s . c o m } for (Map.Entry<K, V> entry : m.entrySet()) { consumer.accept(entry.getKey(), entry.getValue()); } }
From source file:Main.java
/** * Set bitmaps for map of imageViews./*from ww w .j a v a 2 s. c o m*/ * @param views * @param bitmaps * @param convert */ public static void setBitmaps(Map<Integer, ImageView> views, Map<String, Bitmap> bitmaps, Map<Integer, String> convert) { for (Entry<Integer, ImageView> entry : views.entrySet()) { Bitmap bm = bitmaps.get(convert.get(entry.getKey())); entry.getValue().setImageBitmap(bm); } }
From source file:Main.java
public static <E, V extends Comparable<? super V>, K> Map<K, V> sortByValueDesc(Map<K, V> map, int limit) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { return (o2.getValue()).compareTo(o1.getValue()); }/* w w w.ja v a2s . c o m*/ }); Map<K, V> result = new LinkedHashMap<K, V>(); int counter = 0; for (Map.Entry<K, V> entry : list) { if (limit > 0 && counter >= limit) { break; } result.put(entry.getKey(), entry.getValue()); counter++; } return result; }
From source file:Main.java
public static Integer getKeyByValue(Map<Integer, String> map, String value) { for (Entry<Integer, String> entry : map.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); }//from w w w. j av a2 s .c om } return null; }
From source file:Main.java
public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortMapByValue(Map<K, V> map, final boolean descending) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { int comp = (o1.getValue()).compareTo(o2.getValue()); if (descending) { comp = comp * (-1);// w w w .j a va2 s. co m } return comp; } }); LinkedHashMap<K, V> result = new LinkedHashMap<K, V>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
private static void addProperty(HttpURLConnection connection, Map<String, String> headers) { if (headers == null || headers.size() == 0) { return;//from ww w. ja v a 2s . c o m } for (Map.Entry<String, String> entry : headers.entrySet()) { connection.addRequestProperty(entry.getKey(), entry.getValue()); } }
From source file:Main.java
/** * This function takes the Map generated by the calculateEntityReplacements function, and uses those values to replace any * entities in the XML string with their unique random integer replacements. The end results is an XML string that contains * no entities, but contains identifiable strings that can be used to replace those entities at a later point. * * @param replacements The Map generated by the calculateEntityReplacements function * @param xml The XML string to modify * @return The modified XML/*from ww w . j a v a2s. co m*/ */ public static String replaceEntities(final Map<String, String> replacements, final String xml) { String retValue = xml; for (final Entry<String, String> entry : replacements.entrySet()) retValue = retValue.replaceAll("\\&" + entry.getKey() + ";", entry.getValue()); return retValue; }