List of usage examples for java.util Map get
V get(Object key);
From source file:Main.java
private static int getInt(Map<String, Object> data, String key) { return (int) (long) (Long) data.get(key); }
From source file:org.grails.datastore.mapping.config.utils.ConfigUtils.java
public static <T> T read(Class<T> type, String key, Map<String, String> config, T defaultValue) { String value = config.get(key); return value == null ? defaultValue : converter.convertIfNecessary(value, type); }
From source file:Main.java
public static final Object get(Object key) { Map<Object, Object> cache = LOCAL_CACHE.get(); return cache == null ? null : cache.get(key); }
From source file:Main.java
/** * Adds the value to map. If the key does not exists new value list is created and the value is * added to it/* www. j a va2 s.c om*/ * * @param <K> * the key type * @param <V> * the value type * @param map * the map * @param key * the key * @param newValue * the new value */ public static <K, V> void addValueToMap(Map<K, List<V>> map, K key, V newValue) { List<V> list = map.get(key); if (list == null) { list = new LinkedList<V>(); map.put(key, list); } list.add(newValue); }
From source file:Main.java
public static <K1, K2, V> Map<K2, V> mkMap(Map<K1, Map<K2, V>> multiMap, K1 key) { Map<K2, V> map = multiMap.get(key); if (map == null) { map = new HashMap<>(); multiMap.put(key, map);//from w w w. ja va 2s . c o m } return map; }
From source file:Main.java
public static List<Map<String, String>> searchFromAccNumber(List<Map<String, String>> orders, String acc) { List<Map<String, String>> result = new ArrayList<Map<String, String>>(); if (acc != null) { for (Map<String, String> o : orders) { if (acc.equalsIgnoreCase(o.get("accountNumber"))) { result.add(o);//www .ja v a 2s. c o m } } } return result; }
From source file:Main.java
public static void addIntPair(Map map, Object key, int value1, int value2) { Object o = map.get(key); List pair;/*from w w w . ja v a 2 s . c o m*/ if (o == null) { pair = new ArrayList(); pair.add(new Integer(value1)); pair.add(new Integer(value2)); map.put(key, pair); } else { pair = (List) o; List newPair = new ArrayList(); int new1 = ((Integer) pair.get(0)).intValue() + value1; int new2 = ((Integer) pair.get(1)).intValue() + value2; newPair.add(new Integer(new1)); newPair.add(new Integer(new2)); map.put(key, newPair); } }
From source file:Main.java
/** * @param <K>//w ww . ja v a2s .co m * @param <V> * @param aMap * @param aKey * @param aValue * @return {@link List} to which value was added */ public static <K, V> List<V> addToValueList(Map<K, List<V>> aMap, K aKey, V aValue) { List<V> valueList = aMap.get(aKey); if (valueList == null) { valueList = new ArrayList<>(); aMap.put(aKey, valueList); } valueList.add(aValue); return valueList; }
From source file:Main.java
public static <K, V> V getOrAdd(Map<K, V> map, K key, Supplier<V> constructor) { V value = map.get(key); if (value == null) { value = constructor.get();//w ww .j av a2s.c om map.put(key, value); } return value; }
From source file:Main.java
/** * Returns String from a map of string of set of string. * * @param map Map of string of set of string. * @param name Key of the map entry./*from ww w . j a v a 2s. co m*/ * @return String from a map of string of set of string */ public static String getMapAttr(Map map, String name) { Set s = (Set) map.get(name); String retVal = ((s == null) || s.isEmpty()) ? null : ((String) s.iterator().next()); return (retVal != null) ? retVal.trim() : null; }