List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:io.github.moosbusch.lumpi.util.FormUtil.java
public static boolean isExcludedProperty(Class<?> type, String propertyName, Map<String, Set<Class<?>>> excludedProperties) { Map<String, Set<Class<?>>> excludedProps = excludedProperties; if (excludedProps != null) { if (excludedProps.containsKey(propertyName)) { Set<Class<?>> ignoredPropertyTypes = excludedProps.get(propertyName); Set<Class<?>> superTypes = LumpiUtil.getSuperTypes(type, true, true, true); if (!ignoredPropertyTypes.contains(type)) { if (superTypes.stream().anyMatch((superType) -> (!ignoredPropertyTypes.contains(superType)))) { return true; }//from w w w. j av a 2 s. c o m } } } return false; }
From source file:net.itransformers.idiscover.v2.core.CvsConnectionDetailsFactory.java
@SuppressWarnings("unchecked") public static Map<String, ConnectionDetails> createConnectionDetail(File file) throws IOException { List<String> lines = FileUtils.readLines(file); Map<String, ConnectionDetails> result = new LinkedHashMap<String, ConnectionDetails>(); for (String line : lines) { if (line.trim().equals("")) continue; if (line.startsWith("#")) continue; int headerSeparatorIndex = line.indexOf(":"); if (headerSeparatorIndex == -1) { throw new RuntimeException( "Can not find header separator ':', for connection details line: " + line); }/* w w w. j av a2 s .c o m*/ String header = line.substring(0, headerSeparatorIndex); String body = line.substring(headerSeparatorIndex + 1); Map<String, String> headerAttributes = parse(line, header); Map<String, String> attributes = parse(line, body); if (!headerAttributes.containsKey("type")) { throw new RuntimeException( "Can not find 'type' attribute in header, for connection details line: " + line); } if (!headerAttributes.containsKey("name")) { throw new RuntimeException( "Can not find 'name' attribute in header, for connection details line: " + line); } ConnectionDetails details = new ConnectionDetails(headerAttributes.get("type"), attributes); result.put(headerAttributes.get("name"), details); } return result; }
From source file:Main.java
/** * Given an Object, and a key (index), returns the value associated with * that key in the Object. The following checks are made: * <ul>//from www . j av a 2 s . c o m * <li>If obj is a Map, use the index as a key to get a value. If no match continue. * <li>Check key is an Integer. If not, return the object passed in. * <li>If obj is a Map, get the nth value from the <b>keySet</b> iterator. * If the Map has fewer than n entries, return an empty Iterator. * <li>If obj is a List or an array, get the nth value, throwing IndexOutOfBoundsException, * ArrayIndexOutOfBoundsException, resp. if the nth value does not exist. * <li>If obj is an iterator, enumeration or Collection, get the nth value from the iterator, * returning an empty Iterator (resp. Enumeration) if the nth value does not exist. * <li>Return the original obj. * </ul> * * @param obj the object to get an index of * @param index the index to get * @return the object at the specified index * @throws IndexOutOfBoundsException * @throws ArrayIndexOutOfBoundsException * * @deprecated use {@link #get(Object, int)} instead. Will be removed in v4.0 */ public static Object index(Object obj, Object index) { if (obj instanceof Map) { Map map = (Map) obj; if (map.containsKey(index)) { return map.get(index); } } int idx = -1; if (index instanceof Integer) { idx = ((Integer) index).intValue(); } if (idx < 0) { return obj; } else if (obj instanceof Map) { Map map = (Map) obj; Iterator iterator = map.keySet().iterator(); return index(iterator, idx); } else if (obj instanceof List) { return ((List) obj).get(idx); } else if (obj instanceof Object[]) { return ((Object[]) obj)[idx]; } else if (obj instanceof Enumeration) { Enumeration it = (Enumeration) obj; while (it.hasMoreElements()) { idx--; if (idx == -1) { return it.nextElement(); } else { it.nextElement(); } } } else if (obj instanceof Iterator) { return index((Iterator) obj, idx); } else if (obj instanceof Collection) { Iterator iterator = ((Collection) obj).iterator(); return index(iterator, idx); } return obj; }
From source file:de.uniko.west.winter.core.serializing.JSONResultProcessor.java
public static Iterator<Object> processResultsSingleVar(String results, String var) { try {//from w w w .j ava 2 s .c o m System.out.println("RESULT: " + results); JSONObject jsonResultObject = new JSONObject(results); System.out.println("JSONRESULT: " + jsonResultObject); Map<String, Set<Object>> resultsMap = convertJson2Map(jsonResultObject); if (resultsMap.containsKey(var)) { return resultsMap.get(var).iterator(); } else { throw new WinterException("Exception while updateprocess. Variable not in query result."); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void printDetails(Map<String, String> map) { String usage = map.get("CSS"); System.out.println("Map: " + map); System.out.println("Map Size: " + map.size()); System.out.println("Map is empty: " + map.isEmpty()); System.out.println("Map contains CSS key: " + map.containsKey("CSS")); System.out.println("Usage: " + usage); System.out.println("removed: " + map.remove("CSS")); }
From source file:Main.java
public static <K, V> Map<K, V> conditionalPutAndCreateTreeMapIfAbsent(Map<K, V> map, boolean cond, K key, V value) {/* w w w . j a v a 2 s . c o m*/ if (cond) { if (map == null) { map = new TreeMap<K, V>(); map.put(key, value); } else if (!map.containsKey(key)) { map.put(key, value); } } return map; }
From source file:json.YetiJson.java
@SuppressWarnings("rawtypes") static private void convertField(Struct expected, Struct result, Map values, String name) { if (values.containsKey(name)) { result.set(name, convertValue(expected.get(name), values.get(name))); } else {/*from w w w . j a v a2 s . c o m*/ failWith(String.format("No entry with name `%s`", name)); } }
From source file:kafka.benchmark.AdvertisingTopology.java
private static String getKafkaTopic(Map<?, ?> conf) { if (!conf.containsKey("kafka.topic")) { throw new IllegalArgumentException("No kafka topic found!"); }// ww w . j a v a2s.c om return (String) conf.get("kafka.topic"); }
From source file:kafka.benchmark.AdvertisingTopology.java
private static String getRedisHost(Map<?, ?> conf) { if (!conf.containsKey("redis.host")) { throw new IllegalArgumentException("No redis host found!"); }//from w w w . j a va2 s . c o m return (String) conf.get("redis.host"); }
From source file:jease.cmf.service.Nodes.java
/** * Returns node from root by given path. *///from ww w .jav a 2 s. c o m public static Node getByPath(String path) { if (root == null) { return null; } Map<String, Node> cache = Database.query(nodesByPath); if (!cache.containsKey(path)) { Node node = root.getChild(path); if (node != null) { cache.put(path, node); } } return cache.get(path); }