List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:com.networknt.utility.Util.java
public static String substituteVariables(String template, Map<String, String> variables) { Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}"); Matcher matcher = pattern.matcher(template); // StringBuilder cannot be used here because Matcher expects StringBuffer StringBuffer buffer = new StringBuffer(); while (matcher.find()) { if (variables.containsKey(matcher.group(1))) { String replacement = variables.get(matcher.group(1)); // quote to work properly with $ and {,} signs matcher.appendReplacement(buffer, replacement != null ? Matcher.quoteReplacement(replacement) : "null"); }/*from w ww . ja v a2s.c om*/ } matcher.appendTail(buffer); return buffer.toString(); }
From source file:com.plugin.am.LocalNotification.java
/** * Checks if a notification with an ID was triggered. * * @param id/*from w w w .jav a 2 s. c o m*/ * The notification ID to be check. * @param callbackContext */ public static void isTriggered(String id, CallbackContext command) { SharedPreferences settings = getSharedPreferences(); Map<String, ?> alarms = settings.getAll(); boolean isScheduled = alarms.containsKey(id); boolean isTriggered = isScheduled; if (isScheduled) { JSONObject arguments = (JSONObject) alarms.get(id); Options options = new Options(context).parse(arguments); Date fireDate = new Date(options.getDate()); isTriggered = new Date().after(fireDate); } PluginResult result = new PluginResult(PluginResult.Status.OK, isTriggered); command.sendPluginResult(result); }
From source file:jef.testbase.JefTester.java
private static void sampleAdd(Map<Integer, Integer> data, BufferedReader r) throws IOException { String line;// w ww .ja v a2 s . co m while ((line = r.readLine()) != null) { for (char c : line.toCharArray()) { total++; Integer i = (int) c; if (!CharUtils.isAscii((char) i.intValue())) { totalStat++; if (data.containsKey(i)) { data.put(i, data.get(i) + 1); } else { data.put(i, 1); } } } } }
From source file:io.fabric8.apiman.ApimanStarter.java
private static URL waitForDependency(URL url, String path, String serviceName, String key, String value, String username, String password) throws InterruptedException { boolean isFoundRunningService = false; ObjectMapper mapper = new ObjectMapper(); int counter = 0; URL endpoint = null;//from ww w . ja v a2 s. c o m while (!isFoundRunningService) { endpoint = resolveServiceEndpoint(url.getProtocol(), url.getHost(), String.valueOf(url.getPort())); if (endpoint != null) { String isLive = null; try { URL statusURL = new URL(endpoint.toExternalForm() + path); HttpURLConnection urlConnection = (HttpURLConnection) statusURL.openConnection(); urlConnection.setConnectTimeout(500); if (urlConnection instanceof HttpsURLConnection) { try { KeyStoreUtil.Info tPathInfo = new KeyStoreUtil().new Info(ApimanStarter.TRUSTSTORE_PATH, ApimanStarter.TRUSTSTORE_PASSWORD_PATH); TrustManager[] tms = KeyStoreUtil.getTrustManagers(tPathInfo); KeyStoreUtil.Info kPathInfo = new KeyStoreUtil().new Info( ApimanStarter.CLIENT_KEYSTORE_PATH, ApimanStarter.CLIENT_KEYSTORE_PASSWORD_PATH); KeyManager[] kms = KeyStoreUtil.getKeyManagers(kPathInfo); final SSLContext sc = SSLContext.getInstance("TLS"); sc.init(kms, tms, new java.security.SecureRandom()); final SSLSocketFactory socketFactory = sc.getSocketFactory(); HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory); HttpsURLConnection httpsConnection = (HttpsURLConnection) urlConnection; httpsConnection.setHostnameVerifier(new DefaultHostnameVerifier()); httpsConnection.setSSLSocketFactory(socketFactory); } catch (Exception e) { log.error(e.getMessage(), e); throw e; } } if (Utils.isNotNullOrEmpty(username)) { String encoded = Base64.getEncoder() .encodeToString((username + ":" + password).getBytes("UTF-8")); urlConnection.setRequestProperty("Authorization", "Basic " + encoded); log.info(username + ":" + "*****"); } isLive = IOUtils.toString(urlConnection.getInputStream()); Map<String, Object> esResponse = mapper.readValue(isLive, new TypeReference<Map<String, Object>>() { }); if (esResponse.containsKey(key) && value.equals(String.valueOf(esResponse.get(key)))) { isFoundRunningService = true; } else { if (counter % 10 == 0) log.info(endpoint.toExternalForm() + " not yet up. " + isLive); } } catch (Exception e) { if (counter % 10 == 0) log.info(endpoint.toExternalForm() + " not yet up. " + e.getMessage()); } } else { if (counter % 10 == 0) log.info("Could not find " + serviceName + " in namespace, waiting.."); } counter++; Thread.sleep(1000l); } return endpoint; }
From source file:com.flexive.faces.components.WriteWebletIncludes.java
/** * Add the given weblet resource for the current page. * * @param weblet the weblet to be added, e.g. "com.flexive.faces.web/css/components.css" * @return true if the weblet has not been included in the current request *///from ww w .j ava 2 s . co m private static boolean addWebletInclude(String weblet) { final Map<String, Boolean> requestWeblets = getRequestWebletMap(); if (requestWeblets == null) { throw new FxNotFoundException("ex.jsf.webletIncludes.noTagFound").asRuntimeException(); } if (!requestWeblets.containsKey(weblet)) { requestWeblets.put(weblet, false); return true; } return false; }
From source file:co.cask.cdap.metrics.query.MetricsRequestParser.java
/** * Gets a query string parameter by the given key. It will returns the first value if available or the default value * if it is absent.// w ww.j av a2s . c o m */ private static String getQueryParam(Map<String, List<String>> queries, String key, String defaultValue) { if (!queries.containsKey(key)) { return defaultValue; } List<String> values = queries.get(key); if (values.isEmpty()) { return defaultValue; } return values.get(0); }
From source file:com.etsy.arbiter.config.ConfigurationMerger.java
/** * Merge multiple configurations together * * @param configs The list of Config objects to merge * @return A Config object representing the merger of all given Configs *///ww w. ja va2 s .c om public static Config mergeConfiguration(List<Config> configs) throws ConfigurationException { Map<String, List<ActionType>> actions = new HashMap<>(); for (Config c : configs) { for (ActionType a : c.getActionTypes()) { String name = a.getName(); if (!actions.containsKey(name)) { actions.put(name, Lists.newArrayList(a)); } else { actions.get(name).add(a); } } } List<ActionType> actionTypes = new ArrayList<>(); for (Map.Entry<String, List<ActionType>> entry : actions.entrySet()) { if (entry.getValue().size() == 1) { actionTypes.addAll(entry.getValue()); } else { List<ActionType> value = entry.getValue(); Collections.sort(value, new ActionTypePrecedenceComparator()); ActionType merged = new ActionType(); merged.setName(entry.getKey()); // If the tag or xmlns differs, the configuration is invalid if (!areAllValuesEqual(value, new Function<ActionType, String>() { @Override public String apply(ActionType input) { return input.getTag(); } })) { throw new ConfigurationException("Tags do not match for ActionType " + entry.getKey()); } if (!areAllValuesEqual(value, new Function<ActionType, String>() { @Override public String apply(ActionType input) { return input.getXmlns(); } })) { throw new ConfigurationException("xmlns do not match for ActionType " + entry.getKey()); } merged.setTag(value.get(0).getTag()); merged.setXmlns(value.get(0).getXmlns()); merged.setProperties(mergeMaps(value, new Function<ActionType, Map<String, String>>() { @Override public Map<String, String> apply(ActionType input) { return input.getProperties(); } })); merged.setDefaultArgs( mergeCollectionMaps(value, new Function<ActionType, Map<String, List<String>>>() { @Override public Map<String, List<String>> apply(ActionType input) { return input.getDefaultArgs(); } })); actionTypes.add(merged); } } Config mergedConfig = new Config(); mergedConfig.setKillName(getFirstNonNull(configs, new Function<Config, String>() { @Override public String apply(Config input) { return input.getKillName(); } })); mergedConfig.setKillMessage(getFirstNonNull(configs, new Function<Config, String>() { @Override public String apply(Config input) { return input.getKillMessage(); } })); mergedConfig.setActionTypes(actionTypes); return mergedConfig; }
From source file:exm.stc.ic.ICUtil.java
public static <K> void replaceArgValsInMap(Map<Var, Arg> renames, Map<K, Arg> map) { for (Entry<K, Arg> e : map.entrySet()) { Arg val = e.getValue(); if (val.isVar() && renames.containsKey(val.getVar())) { Arg newVal = renames.get(val.getVar()); assert (newVal != null); e.setValue(newVal);//ww w . jav a2 s . com } } }
From source file:Main.java
/** * Splits the query parameters into key value pairs. * See: http://stackoverflow.com/a/13592567/534471. *//* www .j av a2 s .co m*/ private static Map<String, List<String>> splitQuery(Uri uri) throws UnsupportedEncodingException { final Map<String, List<String>> query_pairs = new LinkedHashMap<>(); String query = uri.getQuery(); if (query == null) return query_pairs; final String[] pairs = query.split("&"); for (String pair : pairs) { final int idx = pair.indexOf("="); final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair; if (!query_pairs.containsKey(key)) { query_pairs.put(key, new LinkedList<String>()); } final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : ""; query_pairs.get(key).add(value); } return query_pairs; }
From source file:org.openmrs.module.webservices.rest.resource.BaseRestDataResource.java
public static <E extends OpenmrsObject> void syncCollection(Collection<E> base, Collection<E> sync, Action2<Collection<E>, E> add, Action2<Collection<E>, E> remove) { Map<String, E> baseMap = new HashMap<String, E>(base.size()); Map<String, E> syncMap = new HashMap<String, E>(sync.size()); for (E item : base) { baseMap.put(item.getUuid(), item); }//from w w w .ja v a 2 s . co m for (E item : sync) { syncMap.put(item.getUuid(), item); } for (E item : baseMap.values()) { if (syncMap.containsKey(item.getUuid())) { // Update the existing item E syncItem = syncMap.get(item.getUuid()); syncItem.setId(item.getId()); BeanUtils.copyProperties(syncItem, item); } else { // Delete item that is not in the sync collection remove.apply(base, item); } } for (E item : syncMap.values()) { if (!baseMap.containsKey(item.getUuid())) { // Add the item not in the base collection add.apply(base, item); } } }