List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:gate.termraider.util.Utilities.java
/** * Forces the ultimate value to be Integer. *//*w ww. j ava 2 s . c o m*/ public static void incrementScoreTermValue(Map<ScoreType, Map<Term, Number>> map, ScoreType type, Term term, Integer increment) { Map<Term, Number> submap; if (map.containsKey(type)) { submap = map.get(type); } else { submap = new HashMap<Term, Number>(); } int count; if (submap.containsKey(term)) { count = submap.get(term).intValue(); } else { count = 0; } count += increment.intValue(); submap.put(term, count); map.put(type, submap); }
From source file:io.apicurio.studio.tools.release.ReleaseTool.java
/** * Returns all issues (as JSON nodes) that were closed since the given date. * @param since// w w w . j a v a2 s. co m * @param githubPAT */ private static List<JSONObject> getIssuesForRelease(String since, String githubPAT) throws Exception { List<JSONObject> rval = new ArrayList<>(); String currentPageUrl = "https://api.github.com/repos/apicurio/apicurio-studio/issues?state=closed"; int pageNum = 1; while (currentPageUrl != null) { System.out.println("Querying page " + pageNum + " of issues."); HttpResponse<JsonNode> response = Unirest.get(currentPageUrl).header("Accept", "application/json") .header("Authorization", "token " + githubPAT).asJson(); if (response.getStatus() != 200) { throw new Exception("Failed to list Issues: " + response.getStatusText()); } JSONArray issueNodes = response.getBody().getArray(); issueNodes.forEach(issueNode -> { JSONObject issue = (JSONObject) issueNode; String closedOn = issue.getString("closed_at"); if (since.compareTo(closedOn) < 0) { rval.add(issue); } }); System.out.println("Processing page " + pageNum + " of issues."); System.out.println(" Found " + issueNodes.length() + " issues on page."); String allLinks = response.getHeaders().getFirst("Link"); Map<String, Link> links = Link.parseAll(allLinks); if (links.containsKey("next")) { currentPageUrl = links.get("next").getUrl(); } else { currentPageUrl = null; } pageNum++; } return rval; }
From source file:com.softwarementors.extjs.djn.router.processor.standard.form.FormPostRequestProcessorBase.java
private static void addParameterIfMissing(Map<String, String> parameters, String parameterName, List<String> missingParameters) { assert parameters != null; assert !StringUtils.isEmpty(parameterName); assert missingParameters != null; if (!parameters.containsKey(parameterName)) { missingParameters.add(parameterName); }//from www . ja va 2 s .co m }
From source file:com.kibana.multitenancy.plugin.kibana.KibanaSeed.java
private static String getDefaultIndex(String username, Client esClient, String kibanaIndex, String kibanaVersion) {/*from ww w . j a v a 2 s.co m*/ GetRequest request = esClient .prepareGet(getKibanaIndex(username, kibanaIndex), DEFAULT_INDEX_TYPE, kibanaVersion).request(); try { GetResponse response = esClient.get(request).get(); Map<String, Object> source = response.getSource(); if (source.containsKey(DEFAULT_INDEX_FIELD)) { logger.debug("Received response with 'defaultIndex' = {}", source.get(DEFAULT_INDEX_FIELD)); String index = (String) source.get(DEFAULT_INDEX_FIELD); return getProjectFromIndex(index); } else { logger.debug("Received response without 'defaultIndex'"); } } catch (InterruptedException | ExecutionException e) { if (e.getCause() instanceof org.elasticsearch.index.IndexNotFoundException) { logger.debug("No index found"); } else { logger.error("Error getting default index for {}", e, username); } } return ""; }
From source file:Main.java
/** * Method checks if one map contain at least the same entries like the * other. The third parameter are used to enable a mapping the the keys of * the first and the second map.//from ww w .ja v a 2 s. c o m * * @param map * the map to check * @param containment * the entries which has to contain * @param mapping * the key-mapping between the both maps * @return <code>true</code> if the first map contain at least the same * entries like the other, <code>false</code> otherwise. */ public static final boolean containsAll(Map<String, Object> map, Map<String, Object> containment, final Map<String, String> mapping) { /* * iterate over entries, which should be contained */ for (Entry<String, Object> entry : containment.entrySet()) { String key = entry.getKey(); /* * check if key has to map */ if (mapping.containsKey(key)) { key = mapping.get(key); } /* * check if key is contained or if key is fn:count */ if (map.containsKey(key) || entry.getKey().equalsIgnoreCase("fn:count")) { if (map.get(key).equals(entry.getValue())) { continue; } } return false; } return true; }
From source file:com.screenslicer.core.scrape.ProcessPage.java
private static Results createResults(Element body, int page, Node nodeExtract, int pos, Results.Leniency leniency, String query, boolean trim, Map<String, Object> cache) { if (nodeExtract == null) { return Results.resultsNull; }/*from ww w . j ava2 s . co m*/ try { if (!cache.containsKey("createResults")) { cache.put("createResults", new HashMap<String, Object>()); } return new Results(body, page, nodeExtract, pos, leniency, query, trim, (Map<String, Object>) cache.get("createResults")); } catch (Exception e) { Log.exception(e); } return Results.resultsNull; }
From source file:com.github.ipaas.ideploy.plugin.core.Comparetor.java
@SuppressWarnings("unchecked") private static TreeNode getTargetTree(UserInfo userInfo, PathInfo pathInfo) { ConsoleHandler.info("????..."); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("userName", userInfo.getEmail())); params.add(new BasicNameValuePair("password", userInfo.getPassword())); params.add(new BasicNameValuePair("id", pathInfo.getGroupId())); String json = RequestAcion.post(userInfo.getUrl() + "/crs_code/code_info", params, true); System.out.println(json);/*ww w . j av a2 s . c o m*/ try { if (json != null && !json.equals("")) { Map<String, String> result = JsonUtil.toBean(json, Map.class); if (result.get("status") != null && result.get("status").equals("success")) { if (result.containsKey("treeNode")) { String treeNodStr = result.get("treeNode"); TreeNode targetNode = JsonUtil.toBean(treeNodStr, TreeNode.class); return targetNode; } else { return new TreeNode(); } } else { ConsoleHandler.error("???:" + result.get("info")); } } } catch (Exception e) { ConsoleHandler.error("???:" + json); } return null; }
From source file:com.bigdata.rockstor.console.RockStorSender.java
private static HttpResp buildHttpResponse(HttpResponse response) { HttpResp resp = new HttpResp(); resp.setStatus(response.getStatusLine().getStatusCode()); Map<String, String> head = new HashMap<String, String>(); for (Header header : response.getAllHeaders()) { head.put(header.getName(), header.getValue()); }// w w w . java 2 s . co m resp.setHead(head); if ("chunked".equals(head.get("Transfer-Encoding")) || (head.containsKey("Content-Length") && !head.get("Content-Length").equals("0"))) { try { InputStream is = response.getEntity().getContent(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] b = new byte[4096]; while ((len = is.read(b)) > 0) { baos.write(b, 0, len); } baos.flush(); resp.setBody(new String(baos.toByteArray())); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NullPointerException e) { // HEAD ? } } return resp; }
From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java
/** * Return oracle style argument to java list * //from w w w. j av a 2 s.co m * @param mapIndex * @param strArgument * @return * @throws RESTFulArgumentNotMatchException * @throws UnsupportedEncodingException */ public static List<Object> makeArgumentToOracleList(Map<Integer, String> mapIndex, String strArgument) throws RESTFulArgumentNotMatchException, RESTFULUnsupportedEncodingException { List<Object> listParam = new ArrayList<Object>(); Map<String, String> params = maekArgumentTOMap(strArgument); for (int i = 1; i <= mapIndex.size(); i++) { String strKey = mapIndex.get(i); if (!params.containsKey(strKey)) { throw new RESTFulArgumentNotMatchException( "SQL Parameter not found. Must have to key name is " + strKey); } else { listParam.add(params.get(strKey)); } } return listParam; }
From source file:android.databinding.tool.reflection.java.JavaAnalyzer.java
private static String loadAndroidHome() { Map<String, String> env = System.getenv(); for (Map.Entry<String, String> entry : env.entrySet()) { L.d("%s %s", entry.getKey(), entry.getValue()); }/* w w w . j a va 2 s. c o m*/ if (env.containsKey("ANDROID_HOME")) { return env.get("ANDROID_HOME"); } // check for local.properties file File folder = new File(".").getAbsoluteFile(); while (folder != null && folder.exists()) { File f = new File(folder, "local.properties"); if (f.exists() && f.canRead()) { try { for (String line : FileUtils.readLines(f)) { List<String> keyValue = Splitter.on('=').splitToList(line); if (keyValue.size() == 2) { String key = keyValue.get(0).trim(); if (key.equals("sdk.dir")) { return keyValue.get(1).trim(); } } } } catch (IOException ignored) { } } folder = folder.getParentFile(); } return null; }