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

/**
 * Returns the collection value for the given key, creating and associating
 * a new, empty {@link ArrayList} if the key's value is null.
 * /*from w w  w.  j  av  a 2 s.  co m*/
 * @param <K>
 *            The map's key type.
 * @param <V>
 *            The map's collection value type.
 * @param collectionMap
 *            The map to evaluate.
 * @param key
 *            The key to fetch.
 * @return A collection of values for the given key.
 */
public static <K, V> Collection<V> initCollectionValue(final Map<K, Collection<V>> collectionMap, final K key) {
    Collection<V> collection = collectionMap.get(key);
    if (collection == null) {
        collection = new ArrayList<V>();
        collectionMap.put(key, collection);
    }
    return collection;
}

From source file:Main.java

/**
 * getting value from current ThreadLocal map.
 * @param name//from  w  w w. ja v  a 2  s. c  o m
 * @return
 * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> 
 * @since Aug 18, 2015
 */
public static <T> T get(String name) {
    Map map = params.get();
    if (map == null) {
        return null;
    }
    return (T) map.get(name);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static boolean addToSetInMap(Object key, Object value, Map theMap) {
    if (theMap == null)
        return false;
    Set theSet = (Set) theMap.get(key);
    if (theSet == null) {
        theSet = new LinkedHashSet();
        theMap.put(key, theSet);/*from   ww  w . j  a va 2  s . c  o m*/
    }
    return theSet.add(value);
}

From source file:apps.count.appuser.UserProfile.java

public static void setParameter(Map appProp) {
    long seed = (Long) appProp.get(paramID.USER_SEED);
    userMode = (Integer) appProp.get(paramID.USER_MODE);

    if (seed != -1L) {
        rand.reSeed(seed);/*  ww  w . j a v a2  s  .c  om*/
    }
}

From source file:Main.java

public static <T> T getMapValue(Map<? extends Object, T> args, Object key, T defaultValue) {
    if (args.containsKey(key)) {
        return args.get(key);
    } else {/*from  ww w  .j  a v a2  s .  c o  m*/
        return defaultValue;
    }
}

From source file:Main.java

/**
 * calling this is not thread safe//ww  w.  j a v a 2s .c  om
 */
public static Rectangle getRectangleProperty(Map p, Object key, Rectangle defaultValue) {
    Object value = p.get(key);

    if (value instanceof Rectangle)
        return (Rectangle) value;
    else if (value instanceof String) {
        Rectangle r = parseRectangle((String) value);
        if (r != null)
            return r;
    }
    return defaultValue;
}

From source file:Main.java

/**
 * Copy values./*from  www .  j a  v a 2s .c  o  m*/
 * 
 * @param <K>
 *            the key type
 * @param <V>
 *            the value type
 * @param source
 *            the source
 * @param target
 *            the target
 * @param keys
 *            the keys
 */
public static <K, V> void copyValues(Map<K, V> source, Map<K, V> target, Set<K> keys) {
    for (K key : keys) {
        target.put(key, source.get(key));
    }
}

From source file:Main.java

/**
 * This method returns the prefix associated with the supplied namespace.
 * /*from   www .  ja va2 s. c  om*/
 * @param namespace The namespace
 * @param nsMap The existing namespace prefix mappings
 * @return The prefix
 */
public static String getPrefixForNamespace(String namespace, java.util.Map<String, String> nsMap) {
    String prefix = null;

    prefix = nsMap.get(namespace);

    if (prefix == null) {
        prefix = NS_LABEL + (nsMap.size() + 1);
        nsMap.put(namespace, prefix);
    }

    return (prefix);
}

From source file:Main.java

public static String mapGetValueIgnoringCase(java.util.Map<String, String> map, String key) {
    if (map.containsKey(key)) {
        return map.get(key);
    }/*w  ww .  j  av a2 s.  co  m*/
    for (String f : map.keySet()) {
        if (equalsIgnoreCase(f, key)) {
            return map.get(f);
        }
    }
    return null;
}

From source file:Main.java

/**
 * Copy value.//from  w  w w .  j  a v a 2s  . c om
 *
 * @param <K>
 *            the key type
 * @param <V>
 *            the value type
 * @param source
 *            the source
 * @param sourceKey
 *            the source key
 * @param target
 *            the target
 * @param targetKey
 *            the target key
 */
public static <K, V> void copyValue(Map<K, V> source, K sourceKey, Map<K, V> target, K targetKey) {
    target.put(targetKey, source.get(sourceKey));
}