List of usage examples for java.util Map get
V get(Object key);
From source file:Main.java
/** * //w w w .j a v a 2 s . c om * pre : resultSet must be a valid List<Map> <br> * post : a Map<keyValue, Map> * * @param resultSet * result set from sql. no need order by * @param key * the key to get the value to be the new key for the returned map * @return null if resultSet is null */ @SuppressWarnings("rawtypes") public static Map<Object, Map> sqlListToMapWithUniqueKey(List<Map> resultSet, String key) { if (resultSet == null) return null; Map<Object, Map> rs = new HashMap<Object, Map>(resultSet.size()); for (Map map : resultSet) { rs.put(map.get(key), map); } return rs; }
From source file:Main.java
public static <K, V> void addListInMap(Map<K, List<V>> map, K key, V value) { List<V> list = map.get(key); if (list == null) { list = new ArrayList<V>(); map.put(key, list);//from w w w .jav a2 s .co m } list.add(value); }
From source file:Main.java
public static Map<String, String> getFromFsNumber(String fsNumber, List<Map<String, String>> all) { for (Map<String, String> o : all) { if (o != null && o.get("fsNumber") != null && fsNumber != null) { if (o.get("fsNumber").equalsIgnoreCase(fsNumber)) { return o; }//from w w w.jav a 2s.c o m } } return null; }
From source file:Main.java
/** * Get the value from the map for the given key. It the value does not exist, return the given * defaultValue.//from w w w . j a v a2s . c o m * * @param <K> key type * @param <V> value type * @param map map * @param key key * @param defaultValue default value if the value is null. * @return value */ public static <K, V> V getValue(Map<K, V> map, K key, V defaultValue) { V v = map.get(key); if (v == null) { return defaultValue; } return v; }
From source file:Main.java
public static <K, V> void addToMapSet(K key, V value, Map<K, Set<V>> map) { Set<V> set = map.get(key); if (set == null) { set = new HashSet<V>(); map.put(key, set);/*from w w w . jav a 2 s . c om*/ } set.add(value); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <K, V> V getOrDefault(Map<K, ?> map, K key, V defaultValue) { final Object v = map.get(key); if (v == null) return defaultValue; else/*from w w w .j a v a2 s . com*/ return (V) v; }
From source file:Main.java
public static byte[] getPublicKey(Map<String, Object> keyMap) throws Exception { Key key = (Key) keyMap.get(PUBLIC_KEY); return key.getEncoded(); }
From source file:Main.java
public static <K, V> void findInMultimap(Map<K, List<V>> map, K key, List<V> result) { List<V> tmp = map.get(key); if (tmp != null) result.addAll(tmp);/*from w w w .java 2 s. c om*/ }
From source file:Main.java
public static <T> Integer changeValue(Map<T, Integer> map, T key, int value) { Integer integer = map.get(key); if (integer != null) { integer += value;/*from w w w .ja v a2s.c om*/ map.put(key, integer); } return integer; }
From source file:Main.java
private static int getFreq(final Object obj, final Map freqMap) { Integer count = (Integer) freqMap.get(obj); if (count != null) { return count; }/*w ww . j a v a 2 s . co m*/ return 0; }