List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:Main.java
public static <T, U> void putIfAbsent(Map<T, U> destination, Map<T, U> source) { for (Entry<T, U> entry : source.entrySet()) { if (!destination.containsKey(entry.getKey())) { destination.put(entry.getKey(), entry.getValue()); }/*www . ja va 2 s . co m*/ } }
From source file:Main.java
public static <K> Map<K, Integer> uniomCounterMap(Map<K, Integer> first, Map<K, Integer> second) { Map<K, Integer> ret = new HashMap<K, Integer>(first); for (K key : second.keySet()) { if (ret.containsKey(key)) { ret.put(key, ret.get(key) + second.get(key)); } else {/*w w w . ja va2s .c o m*/ ret.put(key, second.get(key)); } } return ret; }
From source file:Main.java
public static <K, V> V safeGet(Map<K, V> map, K key) { if (map == null) { return null; } else {//from w w w .j a va 2s .c om return map.containsKey(key) ? map.get(key) : null; } }
From source file:Main.java
public static <K> Map<K, Integer> uniomCounterMap(Map<? extends K, Integer> first, Map<? extends K, Integer> second) { Map<K, Integer> ret = new HashMap<K, Integer>(first); for (K key : second.keySet()) { if (ret.containsKey(key)) { ret.put(key, ret.get(key) + second.get(key)); } else {//from w w w. java 2 s . c o m ret.put(key, second.get(key)); } } return ret; }
From source file:com.thoughtworks.go.plugin.access.configrepo.ExportedConfig.java
private static void mustContainHeader(Map<String, String> headers, String key) { if (!headers.containsKey(key)) { throw new IllegalArgumentException(format("You must provide the response header: `%s`", key)); }/* ww w . ja v a 2s.c om*/ if (StringUtils.isBlank(headers.get(key))) { throw new IllegalArgumentException(format("Response header `%s` cannot be blank", key)); } }
From source file:Main.java
/** * Returns the object in the {@link Map} specified by its key. If it doesn't * exist, returns its default value./*from www .jav a2 s .co m*/ * * @param map * - The map containing the elements to inspect. * @param key * - The key of the value to return. * @param defaultValue * - The default value to return in case the key doesn't match a * value in the map. * @return The value mapped to the specified key, or the default value. */ @SuppressWarnings("unchecked") public static <T> T getMapValue(Map<?, ?> map, Object key, T defaultValue) { if (!map.containsKey(key)) { return defaultValue; } else { return (T) map.get(key); } }
From source file:com.anrisoftware.sscontrol.scripts.unix.InstallPackages.java
private static Map<String, Object> setupTimeout(Map<String, Object> args) { if (!args.containsKey(TIMEOUT)) { args.put(TIMEOUT, TIMEOUT_DEFAULT); }/*w w w. j a va2 s. c o m*/ return args; }
From source file:Main.java
public static <T, U> void mapMergeAdd(Map<T, List<U>> map, Map<T, List<U>> mapToAdd) { for (Map.Entry<T, List<U>> e : mapToAdd.entrySet()) { if (!map.containsKey(e.getKey())) { map.put(e.getKey(), new ArrayList<U>()); }/*from www . j ava2 s .c o m*/ map.get(e.getKey()).addAll(e.getValue()); } }
From source file:Main.java
/** * XML to Object/* w w w . java 2 s . c o m*/ * @param <T> T * @param clazz clazz * @param reader reader * @return T */ @SuppressWarnings("unchecked") public static <T> T convertToObject(Class<T> clazz, Reader reader) { try { Map<Class<?>, Unmarshaller> uMap = uMapLocal.get(); if (!uMap.containsKey(clazz)) { JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); uMap.put(clazz, unmarshaller); } return (T) uMap.get(clazz).unmarshal(reader); } catch (JAXBException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String urlBuilderForGetMethod(Map<String, String> g_map) { StringBuilder sbr = new StringBuilder(); int i = 0;//from w w w . ja v a2s . co m if (g_map.containsKey("url")) { sbr.append(g_map.get("url")); g_map.remove("url"); } for (String key : g_map.keySet()) { if (i != 0) { sbr.append("&"); } sbr.append(key + "=" + g_map.get(key)); i++; } System.out.println("Builder url = " + sbr.toString()); return sbr.toString(); }