List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:Main.java
public static Map<String, Integer> countOccurencesOfWords(String str) { String[] words = str.split(("[\\p{IsPunctuation}\\p{IsWhite_Space}]+")); Map<String, Integer> map = new HashMap<String, Integer>(); for (String s : words) { System.out.println(s);//from w w w . j a v a2s .c om if (map.containsKey(s)) { map.put(s, map.get(s) + 1); } else { map.put(s, 1); } } return map; }
From source file:Main.java
public static void rename(Collection<Map<String, Object>> collection, Map<String, String> renames) { for (Map<String, Object> map : collection) { Object obj;/*from w ww . j a va 2 s.co m*/ for (String originalName : renames.keySet()) { if (map.containsKey(originalName)) { obj = map.get(originalName); //Must remove first then added after map.remove(originalName); map.put(renames.get(originalName), obj); } } } }
From source file:Main.java
/** * Returns a map of all values in <b>a</b> who's value is not a * key in <b>b</b>./*from w w w. j ava 2s . co m*/ * * @param a The source map of key value pairs used to populate * the resulting map. * * @param b The exclusion map, who's keys are the exclusions * matching map <b>a</b>'s values. * * @return a map of all values in <b>a</b> who's value is not a * key in <b>b</b>. */ public static <K, V> Map<K, V> outerJoin(Map<K, V> a, Map<V, ?> b) { Map<K, V> buffer = new HashMap<K, V>(); for (Map.Entry<K, V> entry : a.entrySet()) { if (!b.containsKey(entry.getValue())) { buffer.put(entry.getKey(), entry.getValue()); } } return buffer; }
From source file:Main.java
public static String getValueFromJson(String json, String key) { String value = "null"; try {/*from w w w.ja v a 2s . c o m*/ ObjectMapper mapper = new ObjectMapper(); Map<String, Object> values = mapper.readValue(json, new TypeReference<Map<String, String>>() { }); if (values.containsKey(key)) { value = values.get(key).toString(); } } catch (IOException e) { System.out.println("Could not parse json: " + json); } return value; }
From source file:de.hybris.platform.acceleratorstorefrontcommons.controllers.util.GlobalMessages.java
public static void addFlashMessage(final RedirectAttributes model, final String messageHolder, final String messageKey, final Object[] attributes) { final GlobalMessage message = new GlobalMessage(); message.setCode(messageKey);/*w w w . j a v a2 s. co m*/ message.setAttributes(attributes != null ? Arrays.asList(attributes) : Collections.emptyList()); final Map<String, ?> flashModelMap = model.getFlashAttributes(); if (flashModelMap.containsKey(messageHolder)) { final List<GlobalMessage> messages = new ArrayList<>( (List<GlobalMessage>) flashModelMap.get(messageHolder)); messages.add(message); model.addFlashAttribute(messageHolder, messages); } else { model.addFlashAttribute(messageHolder, Collections.singletonList(message)); } }
From source file:com.basho.riak.client.raw.JSONErrorParser.java
/** * Does the map of exception data represent an m/r timeout exception? * /*from w ww .j a v a 2s . c om*/ * @param exceptionData * @return true if <code>exceptionData</code> contains key "error" with * value "timeout". False otherwise. */ private static boolean isTimeoutError(final Map<String, String> exceptionData) { return (exceptionData.containsKey(ERROR_KEY) && TIMEOUT_VALUE.equals(exceptionData.get(ERROR_KEY))); }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.util.GlobalMessages.java
public static void addFlashMessage(final RedirectAttributes model, final String messageHolder, final String messageKey, final Object[] attributes) { final GlobalMessage message = new GlobalMessage(); message.setCode(messageKey);/*from w w w . j a v a 2s. c o m*/ message.setAttributes(attributes != null ? Arrays.asList(attributes) : Collections.emptyList()); final Map<String, ?> flashModelMap = model.getFlashAttributes(); if (flashModelMap.containsKey(messageHolder)) { final List<GlobalMessage> messages = new ArrayList<GlobalMessage>( (List<GlobalMessage>) flashModelMap.get(messageHolder)); messages.add(message); model.addFlashAttribute(messageHolder, messages); } else { model.addFlashAttribute(messageHolder, Collections.singletonList(message)); } }
From source file:org.logger.event.web.utils.ServerValidationUtils.java
public static void rejectIfInvalidType(Errors errors, String data, String field, String errorCode, String errorMsg, Map<String, String> typeParam) { if (!typeParam.containsKey(data)) { errors.rejectValue(field, errorCode, errorMsg); }//from www . java 2 s . c o m }
From source file:org.springframework.cloud.vault.VaultErrorMessage.java
/** * Obtain the error message from a JSON response. * //from www.j a v a2s .c o m * @param json * @return */ static String getError(String json) { if (json.contains("\"errors\":")) { try { Map<String, Object> map = OBJECT_MAPPER.readValue(json.getBytes(), Map.class); if (map.containsKey("errors")) { Collection<String> errors = (Collection<String>) map.get("errors"); if (errors.size() == 1) { return errors.iterator().next(); } return errors.toString(); } } catch (IOException o_O) { // ignore } } return json; }
From source file:com.simplymeasured.prognosticator.HiveUtils.java
/** * Get the HBase table name from an HCatalog table, which can be different from the underlying HBase table name * * @param table table instance to retrieve name from * @return the HBase table name/*from w ww . java 2s . com*/ */ public static String getTableName(HCatTable table) { final String result; Map<String, String> tableProperties = table.getTblProps(); if (tableProperties.containsKey(HBASE_TABLE_NAME)) { result = tableProperties.get(HBASE_TABLE_NAME); } else { result = table.getTableName(); } return result; }