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

@SuppressWarnings("unchecked")
public static void addToMapInMap(Object keyOuter, Object keyInner, Object value, Map theMap) {
    if (theMap == null)
        return;/*from  w w w . ja v  a  2s  . c o  m*/
    Map innerMap = (Map) theMap.get(keyOuter);
    if (innerMap == null) {
        innerMap = new LinkedHashMap();
        theMap.put(keyOuter, innerMap);
    }
    innerMap.put(keyInner, value);
}

From source file:Main.java

public static Object getChainThreadParamValue(String key) {
    Map<String, Object> paramMap = chainThreadParamMap.get();
    if (paramMap != null) {
        return paramMap.get(key);
    }/*  w w  w  .ja  v a 2  s .co m*/
    return null;
}

From source file:RandomGenTest.java

public static void display(Map<Object, Integer> map) {
    for (Object age : map.keySet()) {
        System.out.print(age + "," + map.get(age) + " ");
        int l = map.get(age) / 50;
        for (int i = 0; i < l; i++)
            System.out.print("*");

        System.out.println("");
    }/* w ww.j a v  a 2s .c  om*/
}

From source file:Main.java

/**
 * Returns the value for key in dictionary as an int or the given default
 * value if no value is defined for the key.
 * //from w  w w .j a v a2 s .  c  om
 * @param dict
 *            Dictionary that contains the key, value pairs.
 * @param key
 *            Key whose value should be returned.
 * @param defaultValue
 *            Default value to return if the key is undefined.
 * @return Returns the integer value for key in dict.
 */
public static int getInt(Map<String, Object> dict, String key, int defaultValue) {
    Object value = dict.get(key);

    if (value == null) {
        return defaultValue;
    } else {
        // Handles commas by casting them to an int
        return (int) Float.parseFloat(value.toString());
    }
}

From source file:Main.java

public static String getString(Map<String, Object> obj, String key) {
    try {//from w  w  w  .  ja v  a 2  s .  com
        Object resultObj = obj.get(key);
        if (resultObj != null) {
            String result = resultObj.toString();
            return result;
        } else {
            return new String("");
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

static <K, V> int getCollectionSize(final Map<K, ? extends Collection<V>> map, final K key) {
    final Collection<V> values = map.get(key);
    if (values == null) {
        return 0;
    } else {/* ww  w . j av a  2s .  c  o  m*/
        return values.size();
    }
}

From source file:Main.java

/**
 * Returns the value for key in dictionary as a float or the given default
 * value if no value is defined for the key.
 * /*  www.  j  a  v  a2  s  . co  m*/
 * @param dict
 *            Dictionary that contains the key, value pairs.
 * @param key
 *            Key whose value should be returned.
 * @param defaultValue
 *            Default value to return if the key is undefined.
 * @return Returns the float value for key in dict.
 */
public static float getFloat(Map<String, Object> dict, String key, float defaultValue) {
    Object value = dict.get(key);

    if (value == null) {
        return defaultValue;
    } else {
        return Float.parseFloat(value.toString());
    }
}

From source file:nu.yona.server.batch.quartz.jobs.PinResetConfirmationCodeSenderQuartzJob.java

private static Locale getLocale(Map<String, Object> parameterMap) {
    return Locale.forLanguageTag((String) parameterMap.get(LOCALE_STRING_KEY));
}

From source file:Main.java

/**
 * Puts the specified t-k-v triplet into the specified
 * <code>map</code>/*from  w w w .j a v a 2  s  .c om*/
 * @param map
 * @param t
 * @param k
 * @param v
 * @return
 */
public static <T, K, V> Map<T, Map<K, V>> put(Map<T, Map<K, V>> map, T t, K k, V v) {
    Map<K, V> subMap = map.get(t);
    if (subMap == null)
        subMap = new HashMap<K, V>();
    subMap.put(k, v);
    map.put(t, subMap);
    return map;
}

From source file:Main.java

/**
 * Returns the value for key in dictionary as a string or the given default
 * value if no value is defined for the key.
 * /* www.ja  va 2s .  c o  m*/
 * @param dict
 *            Dictionary that contains the key, value pairs.
 * @param key
 *            Key whose value should be returned.
 * @param defaultValue
 *            Default value to return if the key is undefined.
 * @return Returns the string value for key in dict.
 */
public static String getString(Map<String, Object> dict, String key, String defaultValue) {
    Object value = dict.get(key);

    if (value == null) {
        return defaultValue;
    } else {
        return value.toString();
    }
}