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> void addMapSet(Map<K, Set<V>> map, Map<K, Set<V>> toAdd) {
    for (Map.Entry<K, Set<V>> entry : toAdd.entrySet()) {
        Set<V> values = map.get(entry.getKey());
        if (values == null) {
            values = Sets.newHashSet();/*  w ww .  j  av  a 2 s  .co  m*/
            map.put(entry.getKey(), values);
        }
        for (V value : entry.getValue()) {
            values.add(value);
        }
    }
}

From source file:Main.java

private static String getStringOfClassList(Map<String, Integer> classes) {
    String result = "";
    for (String className : classes.keySet()) {
        Integer occurences = classes.get(className);
        if (!result.isEmpty())
            result += ", ";
        result += className + ": " + occurences;
    }/*from  w  ww  .  jav  a  2  s  .  co m*/

    return result;

}

From source file:HttpHeaderHelper.java

public static List getHeader(Map<String, List<String>> headerMap, String key) {
    return headerMap.get(getHeaderKey(key));
}

From source file:org.apache.nifi.processors.standard.util.HTTPUtils.java

public static String getURI(Map<String, String> map) {
    final String client = map.get(HTTP_REMOTE_HOST);
    final String server = map.get(HTTP_LOCAL_NAME);
    final String port = map.get(HTTP_PORT);
    final String uri = map.get(HTTP_REQUEST_URI);
    if (map.get(HTTP_SSL_CERT) == null) {
        return "http://" + client + "@" + server + ":" + port + uri;
    } else {/*from   w  w w.  j  a va  2s.c  o m*/
        return "https://" + client + "@" + server + ":" + port + uri;
    }
}

From source file:Main.java

/**
 * Finds the value that belongs to the given key in the given map.
 * If the key is null or no value is found, an {@link IllegalStateException} is thrown.
 *//*from w  w w.  j  ava 2 s  .  c  o  m*/
public static <T1, T2> T2 find(T1 key, Map<T1, T2> map) throws IllegalStateException {
    if (key == null)
        throw new IllegalStateException("Key is null");
    T2 ret = map.get(key);
    if (ret == null)
        throw new IllegalStateException("No value for key " + key);
    return ret;
}

From source file:org.apache.synapse.transport.nhttp.util.MessageFormatterDecoratorFactory.java

public static MessageFormatter createMessageFormatterDecorator(MessageContext msgContext) {

    if (msgContext == null) {
        throw new IllegalArgumentException("Message Context cannot be null");
    }//from   www. j  a va2s  .  com

    try {
        // Get message formatter based on the content type
        MessageFormatter formatter = MessageProcessorSelector.getMessageFormatter(msgContext);

        Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
        if (o != null && o instanceof Map) {
            Map headers = (Map) o;

            String encode = (String) headers.get(HTTP.CONTENT_ENCODING);
            if (encode != null) {

                //If message  contains 'Accept-Encoding' header and  if it's value is 'qzip'
                if (GZIP_CODEC.equals(encode)) {
                    formatter = new GzipMessageFormatterDecorator(formatter);
                }
                //if there are any type for 'Accept-Encoding' , those should go here

            }
        }
        return formatter;

    } catch (AxisFault axisFault) {
        String msg = "Cannot find a suitable MessageFormatter : " + axisFault.getMessage();
        log.error(msg, axisFault);
    }

    return null;

}

From source file:io.apiman.common.config.options.AbstractOptions.java

protected static boolean parseBool(Map<String, String> optionsMap, String key, boolean defaultValue) {
    String value = optionsMap.get(key);
    if (value == null) {
        return defaultValue;
    } else {//from  w ww.  j a va2  s .  co  m
        return BooleanUtils.toBoolean(value);
    }
}

From source file:Main.java

public static void setTextViewEx(Map<String, Object> m, TextView v, String key, String format, String... en) {
    try {/*w  ww .  j av a 2s  .  c  om*/
        int i = Integer.parseInt(toString(m.get(key)));
        String s = en[i];
        v.setText(String.format(format, s));
    } catch (Exception e) {
        v.setText("");
    }
}

From source file:Main.java

public static <K, V> void putMapList(Map<K, List<V>> map, K key, V val) {
    if (!map.containsKey(key)) {
        map.put(key, new ArrayList<V>());
    }/*  ww w  . j a va2 s.  c o m*/

    List<V> list = map.get(key);
    list.add(val);
}