List of usage examples for java.util Map get
V get(Object key);
From source file:Main.java
/** * Remove an element from a map whose values are lists of elements. * @param <T> the type of the keys in the map. * @param <U> the type of the elements in the lists. * @param key the key for the value to remove. * @param value the value to remove.//from w w w .j a va 2 s . c om * @param map the map from which to remove the key/value pair. */ public static <T, U> void removeFromListMap(T key, U value, Map<T, List<U>> map) { List<U> list = map.get(key); if (list == null) return; list.remove(value); if (list.isEmpty()) map.remove(key); }
From source file:Main.java
public static ByteBuffer getServiceDataFromEnv(String serviceName, Map<String, String> env) { String meta = env.get(getPrefixServiceName(serviceName)); if (null == meta) { return null; }/*from w w w. j a va 2s . c om*/ byte[] metaData = Base64.decodeBase64(meta); return ByteBuffer.wrap(metaData); }
From source file:Main.java
public static String parseCharset(Map<String, String> headers) { String contentType = headers.get("Content-Type"); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; ++i) { String[] pair = params[i].trim().split("="); if (pair.length == 2 && pair[0].equals("charset")) { return pair[1]; }/* ww w . j av a 2s . c o m*/ } } return "UTF-8"; }
From source file:Main.java
/** * //from w w w . jav a2s . co m * Turns a column of the resultset's value into Set * * @param results * @param key * key to get the value from the result set * @return null if results is null */ public static Set<String> turnMapResultToSet(List<? extends Map<?, ?>> results, String key) { if (results == null) return null; Set<String> set = new HashSet<String>(results.size()); for (Map<?, ?> map : results) { set.add((String) map.get(key)); } return set; }
From source file:Main.java
private static int getSortNr(Map<String, Integer> components, String component) { int sortnr = components.get(component); if (sortnr == 0) { // unsorted new entries get to the bottom return MAX_SORTNR; }// ww w.j a v a 2 s .com return sortnr; }
From source file:Main.java
public static <K, V> Set<V> mkSet(Map<K, Set<V>> multiMap, K key) { Set<V> list = multiMap.get(key); if (list == null) { list = new HashSet<>(); multiMap.put(key, list);// w w w .ja v a 2s . co m } return list; }
From source file:Main.java
public static <K, V extends Comparable<V>> void addToValueSortedSet(Map<K, SortedSet<V>> map, K key, V value) { SortedSet<V> values = map.get(key); if (values == null) { values = new TreeSet<V>(); map.put(key, values);// ww w.java 2 s . c om } values.add(value); }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Map extractHitPointFromRect(Map rect) { Map hitPoint = new HashMap(); hitPoint.put("x", rect.get("center_x")); hitPoint.put("y", rect.get("center_y")); return hitPoint; }
From source file:Main.java
public static void addNode(Document doc, Node parent, String ns, String name, String text, Map NS_MAP) { Element child = doc.createElementNS((String) NS_MAP.get(ns), ns + ":" + name); child.appendChild(doc.createTextNode(text)); parent.appendChild(child);// www .j a v a 2 s . co m }
From source file:Main.java
public static <T> T getFirst(Map<String, List<T>> multiValutMap, String key) { List<T> values = multiValutMap.get(key); if (values != null && !values.isEmpty()) return values.get(0); return null;/* w w w. j ava 2 s. c om*/ }