List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:Main.java
public static Object get(Class c, Map map) { if (map.keySet().contains(c)) { return map.get(c); }/*from www .ja v a2 s. c om*/ for (Iterator i = map.keySet().iterator(); i.hasNext();) { Class candidateClass = (Class) i.next(); if (candidateClass.isAssignableFrom(c)) { return map.get(candidateClass); } } return null; }
From source file:Main.java
private static boolean isList(Map temp) { Set s = new TreeSet(temp.keySet()); Object[] keyArray = s.toArray(new Object[] {}); for (int i = 0; i < keyArray.length; i++) { if (keyArray[i] instanceof Number) { if (((Number) keyArray[i]).intValue() != i) { return false; }// w w w.j a v a 2 s.c o m } else { return false; } } return true; }
From source file:Main.java
public static <T> void addAllKeys(Collection<T> c, Map<T, ?> map) { c.addAll(map.keySet()); }
From source file:Main.java
/** Merge two map counters. */ public static <K> void mergeMapCounters(Map<K, Integer> counter1, Map<K, Integer> counter2) { for (K key : counter2.keySet()) { increaseMapCounter(counter1, key, counter2.get(key)); }//from ww w . j a v a2s .c o m }
From source file:Main.java
public static <Key> void removeFromMapThatKeyNotExistInList(Map<Key, ?> map, List<Key> list) { Object[] keys = map.keySet().toArray(); for (Object key : keys) { if (!list.contains(key)) { map.remove(key);/*from w w w . j av a 2s. com*/ } } }
From source file:Main.java
private static String getStrInMapIgnoreCase(String key, Map<String, Object> map) { Set<String> keySet = map.keySet(); for (String keyInMap : keySet) { if (key.equalsIgnoreCase(keyInMap)) { return keyInMap; }//from ww w .j ava 2 s. c o m } return null; }
From source file:Main.java
public static String assignDynamicValues(String inputXML, Map<String, String> dynamicValues) { for (String key : dynamicValues.keySet()) { if (inputXML.contains("{" + key + "}")) { inputXML = inputXML.replaceAll("\\{" + key + "\\}", dynamicValues.get(key)); }// www . j ava 2 s . c om } return inputXML; }
From source file:Main.java
public static boolean isEmpty(Map<?, ?> map) { return map == null || map.keySet().isEmpty(); }
From source file:Main.java
public static void reverse(Map source, Map target) { for (Iterator it = source.keySet().iterator(); it.hasNext();) { Object key = it.next();/*from w ww . j a va 2 s . com*/ target.put(source.get(key), key); } }
From source file:Main.java
/** * Normalize all values so the sum is 1 * @param <K>/*from w ww. j av a 2 s .c o m*/ * @param map */ public static <K> void normalizeMap(Map<K, Double> map) { Set<K> keys = map.keySet(); double sum = 0.0 + map.values().stream().mapToDouble(Double::doubleValue).sum(); for (K key : keys) { map.put(key, map.get(key) / sum); } }