List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:Main.java
private static boolean processSubstituteChars(char currentChar, HashMap<?, ?> substituteChars, StringBuffer buffer) {/* w w w .j a va2s .co m*/ Character character = new Character(currentChar); if (substituteChars.containsKey(character)) { String value = (String) substituteChars.get(character); if (isDefined(value)) { // Append the value if defined buffer.append(value); } // If the value was not defined, then we will strip the character return true; } return false; }
From source file:Main.java
/** substitutes the linearDistributions according to the substitution list */ public static String substitute(String currentQIESL, HashMap<Integer, String> substitutionList) { StringBuffer result = new StringBuffer(); int i = 0;/*from w ww.j a v a2 s . co m*/ Matcher m = LINEAR_DISTRIUBTIONS.matcher(currentQIESL); while (m.find()) { if (substitutionList.containsKey(i)) { m.appendReplacement(result, substitutionList.get(i)); } i++; } m.appendTail(result); return result.toString(); }
From source file:Main.java
public static SpannableStringBuilder getSpannableStringFromList(List<HashMap<String, Object>> list) { SpannableStringBuilder ssb = new SpannableStringBuilder(""); int position = 0; for (int i = 0; i < list.size(); i++) { HashMap<String, Object> map = list.get(i); try {//ww w .ja va 2 s.c o m String st = (String) map.get(RICHTEXT_STRING); ssb.append(st); int len = st.length(); if (map.containsKey(RICHTEXT_COLOR)) { int color = ((Integer) map.get(RICHTEXT_COLOR)).intValue(); ssb.setSpan(new ForegroundColorSpan(color), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (map.containsKey(RICHTEXT_SIZE)) { int size = ((Integer) map.get(RICHTEXT_SIZE)).intValue(); ssb.setSpan(new AbsoluteSizeSpan(size), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (map.containsKey(RICHTEXT_RSIZE)) { float size = ((Float) map.get(RICHTEXT_RSIZE)).floatValue(); ssb.setSpan(new RelativeSizeSpan(size), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (map.containsKey(RICHTEXT_DELETE)) { ssb.setSpan(new StrikethroughSpan(), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } // android.text.style.RelativeSizeSpan position = position + len; } catch (Exception e) { return null; } } return ssb; }
From source file:de.hbz.lobid.helper.CompareJsonMaps.java
private static void handleOrderedValues(final HashMap<String, String> actualMap, final Entry<String, String> e) { CompareJsonMaps.logger.debug("Test if proper order for: " + e.getKey()); if (actualMap.containsKey(e.getKey())) { CompareJsonMaps.logger.trace("Existing as expected: " + e.getKey()); if (e.getValue().equals(actualMap.get(e.getKey()))) { CompareJsonMaps.logger.trace("Equality:\n" + e.getValue() + "\n" + actualMap.get(e.getKey())); actualMap.remove(e.getKey()); } else/*from w w w. j a v a2s .c o m*/ CompareJsonMaps.logger.debug("...but not equal! Will fail"); } else { CompareJsonMaps.logger.warn("Missing: " + e.getKey() + " , will fail"); } }
From source file:com.caris.oscarexchange4j.proxy.PreviewCoverage.java
/** * Verify some expected parameters are present, set them if not so we will * have a happy request./*from w w w . j av a2 s . com*/ * * @param parameterMap * The parameter map. */ private static void verifyParameters(HashMap<String, String> parameterMap) { if (!parameterMap.containsKey(PreviewCoverage.REQUEST)) { parameterMap.put(PreviewCoverage.REQUEST, "GetCoverage"); } parameterMap.put(STORE, STORE_VALUE); parameterMap.put(GRIDTYPE, EXPECTED_GRIDTYPE); parameterMap.put(SERVICE, SERVICE_VALUE); parameterMap.put(FORMAT, EXPECTED_FORMAT); if (parameterMap.containsKey(BOUNDINGBOX) && parameterMap.containsKey(GRIDBASECRS)) { if (!parameterMap.get(BOUNDINGBOX).endsWith("," + parameterMap.get(GRIDBASECRS))) { String bbox = parameterMap.get(BOUNDINGBOX) + "," + parameterMap.get(GRIDBASECRS); parameterMap.put(BOUNDINGBOX, bbox); } } }
From source file:Main.java
public static ArrayList<Integer> getRandomNumbers(int range, int count, Random rnd) { if (count > range) { return null; }//from w w w . ja v a 2 s.c o m if (count < 0 || range < 0) { return null; } HashMap<Integer, Integer> used = new HashMap<Integer, Integer>(); ArrayList<Integer> indices = new ArrayList<Integer>(); int n = range; while (indices.size() < count) { Integer r = Integer.valueOf(rnd.nextInt(n)); if (used.containsKey(r)) { indices.add(used.get(r)); } else { indices.add(r); } addToUsed(used, r, n - 1); n--; } return indices; }
From source file:Main.java
/** * Finds the difference between two HashMaps a and b. * Returns a HashMap containing elements in b that are not in a * * @return the difference as a HashMap// ww w. ja va 2 s . com */ public static HashMap hashMapDifference(HashMap a, HashMap b) { Iterator bKeyIterator = b.keySet().iterator(); Object key; Object value; HashMap difference = new HashMap(); while (bKeyIterator.hasNext()) { key = bKeyIterator.next(); if (!a.containsKey(key)) { value = b.get(key); difference.put(key, value); } } return difference; }
From source file:com.microsoft.alm.plugin.idea.common.ui.workitem.WorkItemHelper.java
public static String getFieldValue(@NotNull final WorkItem item, @NotNull final String fieldName) { final HashMap<String, Object> fieldMap = item.getFields(); if (fieldMap != null) { // Try a case sensitive search using the Map, // but if that doesn't work, loop through all the fields if (fieldMap.containsKey(fieldName)) { Object value = fieldMap.get(fieldName); if (value != null) { return value.toString(); }/* ww w .j a v a2 s . c om*/ } else { for (final Map.Entry<String, Object> entry : fieldMap.entrySet()) { if (fieldName.equalsIgnoreCase(entry.getKey())) { if (entry.getValue() != null) { return entry.getValue().toString(); } } } } } return StringUtils.EMPTY; }
From source file:eu.lod2.ConfigurationTab.java
private static List<String> parse_graph_api_result(String result) throws Exception { ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { };//from w w w .j a v a 2 s . com HashMap<String, Object> userData = mapper.readValue(result, typeRef); List<String> graphs = null; if (userData.containsKey("graphs")) { Object ographs = userData.get("graphs"); try { HashMap<String, Object> oographs = (HashMap<String, Object>) ographs; if (oographs.containsKey("resultList")) { Object graphsList = oographs.get("resultList"); graphs = (List<String>) graphsList; } ; } catch (Exception e) { System.err.println(e.getMessage()); } ; } ; return graphs; }
From source file:org.droidparts.http.worker.HttpClientWorker.java
private static Map<String, List<String>> getHeaders(HttpResponse resp) { HashMap<String, List<String>> headers = new HashMap<String, List<String>>(); for (Header header : resp.getAllHeaders()) { String name = header.getName(); if (!headers.containsKey(name)) { headers.put(name, new ArrayList<String>()); }/*ww w . j a v a2 s .c om*/ headers.get(name).add(header.getValue()); } return headers; }