Example usage for java.util Map containsKey

List of usage examples for java.util Map containsKey

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:com.thoughtworks.go.server.domain.user.FilterValidator.java

static void validateNameIsUnique(Map<String, DashboardFilter> current, String name) {
    if (current.containsKey(name.toLowerCase()))
        throw new FilterValidationException("Duplicate filter name: " + name);
}

From source file:Main.java

/**
 *//*from   w w  w . j a v  a2 s  .c o m*/
public static <A, B> boolean containsAnyKey(Map<A, B> map, List<A> keys) {
    boolean answer = false;
    for (A k : keys) {
        if (map.containsKey(k)) {
            answer = true;
            break;
        }
    }
    return answer;
}

From source file:Main.java

public static <K, V> V safeGet(Map<K, V> map, K key, V defaultValue) {
    if (map == null) {
        return null;
    } else {/*from w w w  . j av  a2  s . c om*/
        return map.containsKey(key) ? map.get(key) : defaultValue;
    }
}

From source file:org.xwiki.chart.internal.DefaultChartGenerator.java

/**
 * Sets up values in a map, unless they already exist.
 * /*  ww  w. ja  va  2s  .c o m*/
 * @param key the key
 * @param value the corresponding value
 * @param map the map in which the values are put
 */
private static void setParam(String key, String value, Map<String, String> map) {
    if (!map.containsKey(key)) {
        map.put(key, value);
    }
}

From source file:Main.java

public static <T, U> void mapMergeRemove(Map<T, List<U>> map, Map<T, List<U>> mapToRemove) {
    for (Map.Entry<T, List<U>> e : mapToRemove.entrySet()) {
        if (map.containsKey(e.getKey())) {
            map.get(e.getKey()).removeAll(e.getValue());
            if (map.get(e.getKey()).isEmpty()) {
                map.remove(e.getKey());//from   w  w w.  j  ava 2s.  com
            }
        }
    }
}

From source file:Main.java

public static <K, V> Map<K, V> subMap(Map<K, V> map, Collection<K> subKeys) {
    Map<K, V> newMap = new HashMap<K, V>();
    for (K k : subKeys) {
        if (map.containsKey(k))
            newMap.put(k, map.get(k));//from w w  w  .j  av a 2  s  .  c o  m
    }
    return newMap;
}

From source file:com.intbit.util.ServletUtil.java

public static boolean mapContainsKey(Map<String, Object> requestBodyMap, String key) {
    if (!requestBodyMap.containsKey(key) || requestBodyMap.get(key) == null
            || StringUtils.isEmpty(requestBodyMap.get(key).toString())) {
        return false;
    }//from w w  w .j  a  v a2  s  .  co  m
    return true;
}

From source file:Main.java

/**
 * Partition on the keys returned by mapper
 *///from  w w  w. j  a va2  s.c  om
public static <T1, T2> Map<T2, List<T1>> partition(List<T1> lst, Function<T1, T2> mapper) {
    Map<T2, List<T1>> map = new HashMap<>();
    for (T1 elem : lst) {
        T2 key = mapper.apply(elem);
        if (!map.containsKey(key))
            map.put(key, new ArrayList<T1>());
        map.get(key).add(elem);
    }
    return map;
}

From source file:de.innovationgate.wgaservices.xfire.XFireClientFactoryService.java

private static void addDefaultServiceProperties(Map<String, Object> props) {
    if (!props.containsKey("mtom-enabled")) {
        props.put("mtom-enabled", "true");
    }/*from w  ww .java2 s .  com*/

    if (!props.containsKey(HttpTransport.CHUNKING_ENABLED)) {
        props.put(HttpTransport.CHUNKING_ENABLED, "true");
    }

    if (!props.containsKey(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS)) {
        HttpClientParams params = new HttpClientParams();
        params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 1000 * 5);
        params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 1000 * 60);
        props.put(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS, params);
    }
}

From source file:Main.java

/**
 * get all values corresponding to the indices (if they exist in the map)
 * @param map/*from  w  w  w .j av a  2  s.  co  m*/
 * @param indices
 * @return
 */
public static <T, V> List<V> getAll(Map<T, V> map, Collection<T> indices) {
    List<V> result = new ArrayList<V>();
    for (T i : indices)
        if (map.containsKey(i)) {
            result.add(map.get(i));
        }
    return result;
}