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 String parseValue(Map<String, List<String>> responseHeader, String parentKey, String valueKey) {
    List<String> contentTypes = responseHeader.get(parentKey);
    if (contentTypes != null && contentTypes.size() > 0) {
        String contentType = contentTypes.get(0);
        StringTokenizer stringTokenizer = new StringTokenizer(contentType, ";");
        while (stringTokenizer.hasMoreTokens()) {
            String token = stringTokenizer.nextToken();
            if (token.contains(valueKey)) {
                String[] values = token.split("=");
                if (values.length > 1) {
                    return values[1];
                }//from w  ww  .jav a2  s .co  m
            }
        }
    }
    return null;
}

From source file:com.common.server.AppLicenceUtil.java

public static int videoCount() throws Exception {

    Map map = getLicence();
    String videoCount = (String) map.get("videoCount");
    if (videoCount != null) {

        int count = Integer.valueOf(videoCount).intValue();
        return count;

    } else// ww w .jav a  2 s . c om
        return 0;
}

From source file:com.github.ipaas.ifw.front.directive.DirectiveUtils.java

static String getParam(Map params, String key, String defaultValue) throws TemplateException {
    Object value = params.get(key);
    return value == null ? defaultValue : value.toString();
}

From source file:com.griddynamics.genesis.notification.utils.ConfigReaderUtils.java

public static Integer getIntParameter(java.util.Map<String, String> config, String paramName, int maxValue) {
    String paramValue = config.get(paramName);
    if (StringUtils.isNotEmpty(paramValue) && StringUtils.isNumeric(paramValue)) {
        try {/*from   w  ww  .j av  a2s.c o m*/
            int i = Integer.parseInt(paramValue);
            if (i > maxValue) {
                throw new IllegalArgumentException(String.format("%s is too big: %s", paramName, paramValue));
            }
            return i;
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(String.format("%s is is too big: %s", paramName, paramValue));
        }
    } else {
        throw new IllegalArgumentException(
                paramName + String.format("%s is not a number: '%s'", paramName, paramValue));
    }
}

From source file:com.salesmanager.core.util.LanguageUtil.java

public static int getLanguageNumberCode(String lang) {
    if (lang == null) {
        return 1;
    }/*from   www  . j  a  v  a2 s. co  m*/
    Map langmap = RefCache.getLanguageswithcode();
    Language l = (Language) langmap.get(lang.toLowerCase());
    if (l != null) {
        return l.getLanguageId();
    } else {
        return 1;
    }
}

From source file:drepcap.frontend.util.StatsHelper.java

public static double getValueAndAddToStats(Map<?, ?> statsDataMap, String key, DescriptiveStatistics stats) {
    double ret = 0;

    final Object obj = statsDataMap.get(key);

    if (obj != null && obj instanceof Double) {
        ret = ((Double) obj).doubleValue();
    }/* w  w w  . j a v  a2  s. c  o  m*/

    if (stats != null) {
        stats.addValue(ret);
    }

    return ret;
}

From source file:Main.java

private static <E> int getFreq(final E obj, final Map<E, Integer> freqMap) {
    try {//  w  w  w  .  j  av  a  2  s . com
        Integer o = freqMap.get(obj);
        if (o != null) // minimize NullPointerExceptions
        {
            return o;
        }
    } catch (NullPointerException ignore) {
    } catch (NoSuchElementException ignore) {
    }
    return 0;
}

From source file:Main.java

private static void frequenceyCount(String input) {
    Map<Character, Integer> hashCount = new HashMap<>();
    Character c;//from  w  ww .ja v  a 2 s . c  o  m
    for (int i = 0; i < input.length(); i++) {
        c = input.charAt(i);
        if (hashCount.get(c) != null) {
            hashCount.put(c, hashCount.get(c) + 1);
        } else {
            hashCount.put(c, 1);
        }
    }
    Iterator it = hashCount.entrySet().iterator();
    System.out.println("char : frequency");
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        System.out.println(pairs.getKey() + " : " + pairs.getValue());
        it.remove();
    }
}

From source file:Main.java

private static void print(String text, Map<String, Double> map) {
    System.out.println(text);/*from  www  . j a  v a 2 s  .c om*/

    for (String key : map.keySet()) {
        System.out.println("key/value: " + key + "/" + map.get(key));
    }
}

From source file:Main.java

/**
 * add a value to a value list in a Map.
 * //from ww w  . ja v a 2  s .com
 * @param map
 *            the map.
 * @param key
 *            the key.
 * @param value
 *            the value to be added to the list.
 * @since 0.1
 */
public static void addValue(final Map map, final Object key, final Object value) {
    List values;

    if ((values = (List) map.get(key)) == null) {
        values = new ArrayList();
    }

    values.add(value);
    map.put(key, values);
}