List of usage examples for java.util Map get
V get(Object key);
From source file:Main.java
public static void add(Map<String, Integer> statMap, String key) { Integer counter = statMap.get(key); if (counter == null) { statMap.put(key, Integer.valueOf(1)); } else {/*w w w . j av a 2s. c o m*/ statMap.put(key, Integer.valueOf(counter.intValue() + 1)); } }
From source file:Main.java
/** * Utility method that returns the named boolean value form the given map. * * @param properties map of properties (String -> Object) * @param name property name/*from w w w.ja va 2s .c o m*/ * @return property value, or false */ private static boolean getBoolean(Map<String, Object> properties, String name) { Object value = properties.get(name); if (value instanceof Boolean) { return ((Boolean) value).booleanValue(); } return false; }
From source file:Main.java
public static List<Map<String, Object>> setFirstMapFromList(List<Map<String, Object>> list, String field, String value) {/* w w w.j a v a 2s . c o m*/ List<Map<String, Object>> collection = new ArrayList<Map<String, Object>>(); for (Iterator<Map<String, Object>> iter = list.iterator(); iter.hasNext();) { Map<String, Object> map = iter.next(); String deField = map.get(field).toString(); if (deField.equalsIgnoreCase(value)) { collection.add(map); collection.addAll(list); list.clear(); list.addAll(collection); break; } } return list; }
From source file:Main.java
public static String getValue(String key, String defaultKey, Map<String, String> map) { String value = map.get(key); if (value == null) value = map.get(defaultKey);/* ww w. ja v a2 s . c om*/ return value; }
From source file:Main.java
/** * Utility method that returns the named short value form the given map. * * @param properties map of named properties (String -> Object) * @param name property name/*from w ww .j ava2 s .c o m*/ * @return property value, or zero */ private static short getShort(Map<String, Object> properties, String name) { Object value = properties.get(name); if (value instanceof Short) { return ((Short) value).shortValue(); } return 0; }
From source file:Main.java
public static <K, V> void add(Map<K, List<V>> map, K key, V value) { if (map.containsKey(key)) { map.get(key).add(value); } else {/* w w w. jav a 2 s . co m*/ List<V> list = new ArrayList<>(); list.add(value); map.put(key, list); } }
From source file:dmh.kuebiko.model.DaoParameter.java
/** * Retrieve a string parameter value from a parameter map. * @param paramMap The map containing the desired value. * @param paramKey The key of the desired value. * @return The requested value, or null if it does not exist. *///w w w.jav a2 s. c om static String getParameter(Map<String, String> paramMap, DaoParameter paramKey) { return trimToNull(paramMap.get(paramKey.toString())); }
From source file:Main.java
public static <K, V> void putOrCreateList(Map<K, List<V>> map, K key, V value) { List<V> list;//from w w w . ja va 2 s.c om list = map.get(key); if (list == null) { list = new ArrayList<>(); list.add(value); map.put(key, list); } else { list.add(value); } }
From source file:Main.java
public static <K, V> V getIfNotNull(final Map<? super K, ? extends V> map, final K key) { return (map != null) && (key != null) ? map.get(key) : null; }
From source file:Main.java
public static Color getColorProperty(Map p, Object key, Color defaultValue) { Object value = p.get(key); if (value instanceof Color) return (Color) value; else if (value instanceof String) { try {/*from w w w . ja v a 2s . c om*/ return Color.decode((String) value); } catch (NumberFormatException e) { } } return defaultValue; }