List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:com.bazaarvoice.jolt.JsonUtils.java
/** * Removes a key recursively from anywhere in a JSON document. * NOTE: mutates its input./*from w w w .ja va 2 s . c om*/ * * Deprecated: use JoltUtils instead * * @param json the Jackson Object version of the JSON document * (contents changed by this call) * @param keyToRemove the key to remove from the document */ @Deprecated public static void removeRecursive(Object json, String keyToRemove) { if ((json == null) || (keyToRemove == null)) { return; } if (json instanceof Map) { Map<String, Object> jsonMap = (Map<String, Object>) json; // If this level of the tree has the key we are looking for, remove it if (jsonMap.containsKey(keyToRemove)) { jsonMap.remove(keyToRemove); } // regardless, recurse down the tree for (String subKey : jsonMap.keySet()) { Object value = jsonMap.get(subKey); removeRecursive(value, keyToRemove); } } if (json instanceof List) { for (Object value : (List) json) { removeRecursive(value, keyToRemove); } } }
From source file:com.saba.CalendarDemo.java
private static void prepareProductDetailsTableData(Map<String, Object> data, XSSFSheet sheet, Map<String, CellStyle> styles, int awardDetailsRow) { if (data.containsKey(awardHeaders[2]) && null != data.get(awardHeaders[2])) { @SuppressWarnings("unchecked") Map<String, Object[]> productDetailsMap = (Map<String, Object[]>) data.get(awardHeaders[2]); Set<String> keyset = productDetailsMap.keySet(); int rownum = awardDetailsRow + 2; for (String key : keyset) { try { XSSFRow pDetailsRow = sheet.createRow(rownum++); pDetailsRow.setHeightInPoints(12.75f); Object[] objArr = productDetailsMap.get(key); int cellnum = 0; for (Object obj : objArr) { XSSFCell cell = pDetailsRow.createCell(cellnum); cell.setCellStyle(styles.get("item_right")); //find and populate dynamic variable from object populateDynamicObject(cell, obj); //increment the cell size cellnum++;/*from w ww . j a v a2 s .co m*/ } } catch (Exception e) { //logger.error("Error while preparing the product Details table in xls :" + e); continue; } } } }
From source file:com.github.gdfm.shobaidogu.StatsUtils.java
/** * Inner (dot) product between two vectors. * /* w w w. ja v a2s . c om*/ * @param smallVector * @param largeVector * @return */ public static <K, V extends Number> double dotProduct(Map<K, V> smallVector, Map<K, V> largeVector) { double similarity = 0.0; for (Map.Entry<K, V> entry : smallVector.entrySet()) if (largeVector.containsKey(entry.getKey())) similarity += entry.getValue().doubleValue() * largeVector.get(entry.getKey()).doubleValue(); return similarity; }
From source file:com.footprint.cordova.plugin.localnotification.LocalNotification.java
/** * Checks wether a notification with an ID is scheduled. * * @param id// w w w .j a va 2 s .co m * The notification ID to be check. * @param callbackContext */ public static void isScheduled(String id, CallbackContext command) { SharedPreferences settings = getSharedPreferences(); Map<String, ?> alarms = settings.getAll(); boolean isScheduled = alarms.containsKey(id); PluginResult result = new PluginResult(PluginResult.Status.OK, isScheduled); command.sendPluginResult(result); }
From source file:com.turt2live.xmail.mail.attachment.ItemAttachment.java
private static Map<String, Object> recursiveDeserialization(Map<String, Object> map) { Map<String, Object> map2 = new HashMap<String, Object>(); for (String key : map.keySet()) { Object o = map.get(key);//from w w w . j a va2 s.c o m map2.put(key, o); if (o instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map3 = (Map<String, Object>) o; if (map3.containsKey(CLASS_KEY)) { String alias = (String) map3.get(CLASS_KEY); Object deserialed = ConfigurationSerialization.deserializeObject(map3, ConfigurationSerialization.getClassByAlias(alias)); map2.put(key, deserialed); } // else: ignore } } return map2; }
From source file:cn.edu.zju.acm.onlinejudge.util.ProblemManager.java
private static String getFileType(String code, String name, Map<String, byte[]> files) { if (files.containsKey(code + "/" + name + ".cc")) { return "cc"; } else if (files.containsKey(code + "/" + name + ".cpp")) { return "cpp"; } else if (files.containsKey(code + "/" + name + ".c")) { return "c"; } else if (files.containsKey(code + "/" + name + ".pas")) { return "pas"; } else if (files.containsKey(code + "/" + name + ".fpc")) { return "fpc"; } else if (files.containsKey(code + "/" + name + ".java")) { return "java"; } else {//from w w w . j a v a 2s. c om return null; } }
From source file:com.google.cloud.genomics.dockerflow.args.ArgsTableBuilder.java
public static ArgsTableBuilder fromArgs(String[] args) throws IOException { Map<String, String> m = StringUtils.parseArgs(args); ArgsTableBuilder b;//from ww w. j a v a 2 s . c o m WorkflowArgs wa = ArgsBuilder.fromArgs(args).build(); if (m.containsKey(ARGS_FILE)) { Map<String, String> globals = null; if (m.containsKey(GLOBALS)) { globals = StringUtils.parseParameters(m.get(GLOBALS), false); } b = ArgsTableBuilder.fromFile(m.get(ARGS_FILE)).globals(globals); b.parameters(wa); // apply command-line settings } else { b = ArgsTableBuilder.of(wa); } return b; }
From source file:com.netflix.astyanax.thrift.ThriftUtils.java
/** * Convert a Properties object into a tree * @param props/*w ww . j a v a 2 s . c o m*/ * @return */ public static Map<String, Object> propertiesToMap(Properties props) { Map<String, Object> root = Maps.newTreeMap(); for (Entry<Object, Object> prop : props.entrySet()) { String[] parts = StringUtils.split((String) prop.getKey(), "."); Map<String, Object> node = root; for (int i = 0; i < parts.length - 1; i++) { if (!node.containsKey(parts[i])) { node.put(parts[i], new LinkedHashMap<String, Object>()); } node = (Map<String, Object>) node.get(parts[i]); } node.put(parts[parts.length - 1], (String) prop.getValue()); } return root; }
From source file:org.elasticsearch.rest.action.admin.indices.upgrade.UpgradeTest.java
static List<UpgradeStatus> getUpgradeStatus(HttpRequestBuilder httpClient, String path) throws Exception { HttpResponse rsp = httpClient.method("GET").path(path).execute(); Map<String, Object> data = validateAndParse(rsp); List<UpgradeStatus> ret = new ArrayList<>(); for (String index : data.keySet()) { Map<String, Object> status = (Map<String, Object>) data.get(index); assertTrue("missing key size_in_bytes for index " + index, status.containsKey("size_in_bytes")); Object totalBytes = status.get("size_in_bytes"); assertTrue("size_in_bytes for index " + index + " is not an integer", totalBytes instanceof Integer); assertTrue("missing key size_to_upgrade_in_bytes for index " + index, status.containsKey("size_to_upgrade_in_bytes")); Object toUpgradeBytes = status.get("size_to_upgrade_in_bytes"); assertTrue("size_to_upgrade_in_bytes for index " + index + " is not an integer", toUpgradeBytes instanceof Integer); ret.add(new UpgradeStatus(index, ((Integer) totalBytes).intValue(), ((Integer) toUpgradeBytes).intValue())); }//from w ww. ja va 2 s . co m return ret; }
From source file:de.hasait.clap.impl.AbstractCLAPNode.java
protected static final void addHelpNode(final Map<CLAPHelpCategoryImpl, Set<CLAPHelpNode>> pOptionNodes, final CLAPHelpCategoryImpl pCurrentCategory, final CLAPHelpNode pNode) { final CLAPHelpCategoryImpl currentCategory = pNode.getHelpCategory() != null ? pNode.getHelpCategory() : pCurrentCategory;/*w w w . j a va 2 s . c om*/ if (!pOptionNodes.containsKey(currentCategory)) { pOptionNodes.put(currentCategory, new TreeSet<CLAPHelpNode>(new Comparator<CLAPHelpNode>() { @Override public int compare(final CLAPHelpNode pO1, final CLAPHelpNode pO2) { return pO1.getHelpID().compareTo(pO2.getHelpID()); } })); } pOptionNodes.get(currentCategory).add(pNode); }