Example usage for java.util Map get

List of usage examples for java.util Map get

Introduction

In this page you can find the example usage for java.util Map get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:Main.java

public static <K, V, V2> Map<V, V2> getOrCreateMap(Map<K, Map<V, V2>> map, K key) {
    Map<V, V2> r = map.get(key);
    if (r == null)
        map.put(key, r = new HashMap<V, V2>());
    return r;//from   ww w . j a  v a2s . c om
}

From source file:Main.java

public static <K, E> Set<E> getSetInitIfEmpty(Map<K, Set<E>> map, K key) {
    Set<E> value = map.get(key);
    if (value == null) {
        value = new HashSet<E>();
        map.put(key, value);//from   w  w  w  .  ja  va2 s  . com
    }
    return value;
}

From source file:Main.java

public static <K, V, V2> Map<V, V2> getOrCreateMap(Map<K, Map<V, V2>> map, K key) {
    Map<V, V2> r = map.get(key);
    if (r == null) {
        map.put(key, r = new HashMap<V, V2>());
    }/*from w  ww . j a  v a2 s.  c o  m*/
    return r;
}

From source file:Main.java

private static final <T> int getFreq(final T obj, final Map<T, Integer> freqMap) {
    Integer count = freqMap.get(obj);
    if (count != null) {
        return count.intValue();
    }//w w  w .  j ava 2 s.c om
    return 0;
}

From source file:Main.java

private static <K, T> void add(Map<K, Set<T>> map, K key, T val) {
    Set<T> n = map.get(key);
    if (null == n) {
        n = new LinkedHashSet<T>();
        map.put(key, n);/*from w w w.ja  va2  s  . c  om*/
    }
    n.add(val);
}

From source file:Main.java

public static <K, E> List<E> getListInitIfEmpty(Map<K, List<E>> map, K key) {
    List<E> value = map.get(key);
    if (value == null) {
        value = new ArrayList<E>();
        map.put(key, value);//from   ww w.j av a2  s. c o  m
    }
    return value;
}

From source file:Main.java

public static String getExternalSDRoot() {

    Map<String, String> evn = System.getenv();

    return evn.get("SECONDARY_STORAGE");
}

From source file:Main.java

public static <K, V> V setDefault(Map<K, V> map, K key, V value) {

    V _value = map.get(key);
    if (_value != null)
        return _value;
    else {//w  w  w .j a  va2  s.  co  m
        map.put(key, value);
        return value;
    }

}

From source file:Main.java

public static <K, V> List<V> getValueList(Map<K, List<V>> map, K key) {
    List<V> valueList = map.get(key);
    if (valueList == null) {
        return Collections.emptyList();
    }/* w  ww . ja v a2 s .c om*/
    return valueList;
}

From source file:Main.java

public static <X> int plus(Map<X, Integer> counts, X key, int dx) {
    Integer x = counts.get(key);
    if (x == null)
        x = 0;//  w  ww  .  jav  a  2  s .c o  m
    x += dx;
    counts.put(key, x);
    return x;
}