List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:org.mobicents.servlet.restcomm.http.RestcommMultitenancyTool.java
public int post(String url, String credentialUsername, String credentialPassword, HashMap<String, String> params) throws ClientProtocolException, IOException { CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpResponse apiResponse = null; HttpPost post = new HttpPost(url); List<NameValuePair> values = new ArrayList<NameValuePair>(); Iterator it = params.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); values.add(new BasicNameValuePair(String.valueOf(pair.getKey()), String.valueOf(pair.getValue()))); }/*from www. j a v a2s .c o m*/ post.setEntity(new UrlEncodedFormEntity(values)); post.addHeader("Authorization", "Basic " + getAuthorizationToken(credentialUsername, credentialPassword)); apiResponse = client.execute(post); return apiResponse.getStatusLine().getStatusCode(); }
From source file:es.bsc.autonomic.powermodeller.tools.VariableParser.java
/** * Translates the value expressions of a HashMap into argument numbers and returns a new translated HashMap. * @param rawHM HashMap to be translated: its values will be translated into argument numbers. i.e. cpu-cycles -> a31 * @param varDictionary If not null, the function will treat rawHM as new metrics to be included in the columns list * @return// ww w .j a v a 2s . com */ private HashMap<String, String> processRawHM(HashMap<String, String> rawHM, HashMap<String, String> varDictionary) { HashMap<String, String> ret = new HashMap<String, String>(); Pattern regex = Pattern.compile("\\{([^}]*)\\}"); for (Map.Entry<String, String> entry : rawHM.entrySet()) { String name = entry.getKey(); String expression = entry.getValue(); Matcher regexMatcher = regex.matcher(expression); while (regexMatcher.find()) { String wrappedMetric = regexMatcher.group(); String metricName = wrappedMetric.substring(1, wrappedMetric.length() - 1); if (dataSetHeader.indexOf(metricName) >= 0) { //Operating on an existing metric int j = dataSetHeader.indexOf(metricName) + 1; expression = expression.replace(wrappedMetric, "a" + j); } /*else if(ret.containsKey(metricName)) { //Operating on a new var/metric that uses previously defined vars/metrics, respectively expression = expression.replace(wrappedMetric, ret.get(metricName)); }*/ else if (varDictionary != null && varDictionary.containsKey(metricName)) { //Operating on a new metric using variables previously defined expression = expression.replace(wrappedMetric, varDictionary.get(metricName)); } else { logger.error("Specified metric name " + metricName + " was not found neither in the available metrics neither on the variable dictionary"); logger.debug(columns); throw new VariableParserException("Specified metric name " + metricName + " was not found neither in the available metrics neither on the variable dictionary"); } } ret.put(name, expression); if (varDictionary != null) { columns.add(name); logger.debug("Added new metric '" + name + "', with expression: " + expression); } } return ret; }
From source file:com.netease.hearttouch.hthotfix.patch.PatchSoHelper.java
/** * ?CPU??so/* ww w . ja v a 2 s . com*/ */ public int collectSoFiles() { HashMap<String, String> hashMap = HashFileHelper .parse(Constants.getHotfixPath(project, Constants.HOTFIX_SO_HASH)); soFileMap = new HashMap<>(); for (HashMap.Entry<String, String> entry : hashMap.entrySet()) { String soPath = project.getProjectDir().toString() + entry.getKey(); File soFile = new File(soPath); if (!soFile.exists()) continue; String archName = soFile.getParentFile().getName(); if (onlyARM && !archName.equals("armeabi")) continue; String soHash = entry.getValue(); try { String sha1Hex = DigestUtils.shaHex(Files.readAllBytes(soFile.toPath())); if (!sha1Hex.equals(soHash)) { if (soFileMap.containsKey(archName)) { ArrayList<File> soFileList = soFileMap.get(archName); soFileList.add(soFile); } else { ArrayList<File> soFileList = new ArrayList<>(); soFileList.add(soFile); soFileMap.put(archName, soFileList); } } } catch (IOException ioe) { ioe.printStackTrace(); } } return soFileMap.size(); }
From source file:org.geoserver.monitor.web.ActivityChartBasePanel.java
BufferedDynamicImageResource queryAndRenderChart(Monitor monitor, Date[] range) { Query q = new Query(); q.properties("startTime").between(range[0], range[1]); DataGatherer gatherer = new DataGatherer(); monitor.query(q, gatherer);// w w w .j a v a 2 s . c o m HashMap<RegularTimePeriod, Integer> data = gatherer.getData(); Class timeUnitClass = getTimePeriod(range[0]).getClass(); TimeSeries series = new TimeSeries("foo", timeUnitClass); for (Map.Entry<RegularTimePeriod, Integer> d : data.entrySet()) { series.add(new TimeSeriesDataItem(d.getKey(), d.getValue())); } TimeSeriesCollection dataset = new TimeSeriesCollection(series); final JFreeChart chart = createTimeSeriesChart(getChartTitle(range), "Time (" + timeUnitClass.getSimpleName() + ")", "Requests", dataset); BufferedDynamicImageResource resource = new BufferedDynamicImageResource(); resource.setImage(chart.createBufferedImage(700, 500)); return resource; }
From source file:com.example.klaudia.myapplication.Searcher.java
public HashMap<String, Bitmap> complexSearch_Titles(HashMap<String, String> nameValue) { if (checkMapCorrectness(nameValue)) { String userInput = ""; Iterator it = nameValue.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); Object key = pair.getKey(); Object value = pair.getValue(); //nie zapisujemy do resulta 2 poczatkowych liter klucza, czyli litery oznaczej typ danej i '_'. Kropka sluzy do oddzielenia pary (klucz, wartosc) if (key.toString() != "s_query" && value != null) userInput += key.toString().substring(2, key.toString().length()) + "=" + value + "."; }/*from w ww .j ava2s . co m*/ if (userInput.length() > 0 && userInput.charAt(userInput.length() - 1) == '.') userInput = userInput.substring(0, userInput.length() - 1); userInput = userInput.replace('.', '&'); String request = "https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/searchComplex?limitLicense=false&number=10&offset=10&ranking=1&" + changeTextToRequest(userInput); recipesJSONArray = getJsonArrayFromRequest(request, "results"); return getRecipesTitlesmagesFromArray(recipesJSONArray); } else return null; }
From source file:org.owasp.benchmark.score.report.ScatterScores.java
private void makeDataLabels(List<Report> toolResults, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(toolResults); for (Entry<Point2D, String> e : map.entrySet()) { if (e.getValue() != null) { Point2D p = e.getKey(); String label = sort(e.getValue()); XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY()); annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER); annotation.setBackgroundPaint(Color.white); annotation.setPaint(Color.blue); annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); }/*w w w . j a v a 2s . co m*/ } }
From source file:org.apache.geode.geospatial.utils.CachingPutAllMap.java
@Override public Set<Entry> entrySet() { readLock.lock();//from www .j a v a2 s . co m try { HashMap map = new HashMap(wrappedMap); map.putAll(bulkMap); return map.entrySet(); } finally { readLock.unlock(); } }
From source file:org.obiba.onyx.print.impl.DefaultPdfTemplateEngine.java
private void setVariableDataFields(Participant participant, AcroFields form, Map<String, String> fieldToVariableMap) { HashMap<String, String> fieldList = form.getFields(); try {//w ww. jav a 2 s . co m // Iterate on each field of pdf template for (Entry<String, String> field : fieldList.entrySet()) { String[] keys = splitData(field.getKey()); // TEMPORARY FIX so that "NA" is displayed in a field if the data is not available. // This should be replaced by a default value for the field in the PDF template, // however this didn't seem to work when I tested it (default values were not getting printed) // We need to find a way to fix that (might be a bug in Acrobat forms). form.setField(field.getKey(), "N/A"); // Iterate on each key for one field of pdf template (for example when a variable depends on several // instruments) for (String variableKey : keys) { String variablePath = fieldToVariableMap.get(variableKey); if (variablePath != null) { String[] pathElements = extractPathElements(variablePath); ValueTable tableForVariable = resolveTable(pathElements[0], pathElements[1]); ValueSet valueSetInTable = getParticipantValueSet(tableForVariable); String variableName = pathElements[2]; String valueString = getStringValue(tableForVariable, valueSetInTable, field.getKey(), variableName); if (valueString != null && valueString.length() != 0) { form.setField(field.getKey(), valueString); break; } } } } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.kitodo.data.index.elasticsearch.RestClientImplementation.java
/** * Add list of documents to the index. This method will be used for add whole table to the index. * It performs asynchronous request./*from w w w. ja va 2s . c o m*/ * * @param documentsToIndex list of json documents to the index */ public String addType(HashMap<Integer, HttpEntity> documentsToIndex) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(documentsToIndex.size()); final StringBuilder output = new StringBuilder(); for (HashMap.Entry<Integer, HttpEntity> entry : documentsToIndex.entrySet()) { restClient.performRequestAsync("PUT", "/" + this.getIndex() + "/" + this.getType() + "/" + entry.getKey(), Collections.<String, String>emptyMap(), entry.getValue(), new ResponseListener() { @Override //problem with return type - it should be String //dirty hack private variable ArrayResult public void onSuccess(Response response) { output.append(response.toString()); latch.countDown(); } @Override public void onFailure(Exception exception) { latch.countDown(); } }); } latch.await(); return output.toString(); }
From source file:com.aliyun.openservices.odps.console.SelectCommand.java
public void run() throws OdpsException, ODPSConsoleException { try {//from w ww .ja va2 s . c o m if (getContext().isAsyncMode()) { getWriter().writeError("[asysc mode]: can't support select command."); return; } String project = getCurrentProject(); boolean isDryRun = getContext().isDryRun(); if (isDryRun) { String taskName = "console_select_sqlplan_task_" + Calendar.getInstance().getTimeInMillis(); Task dryRunTask = new SqlPlanTask(taskName, getCommandText()); runJob(dryRunTask); // dry run return; } String taskName = "console_select_query_task_" + Calendar.getInstance().getTimeInMillis(); SQLTask task = new SQLTask(); task.setName(taskName); task.setQuery(getCommandText()); HashMap<String, String> taskConfig = QueryUtil.getTaskConfig(); if (!getContext().isMachineReadable()) { addSetting(taskConfig, "odps.sql.select.output.format", "HumanReadable"); } for (Entry<String, String> property : taskConfig.entrySet()) { task.setProperty(property.getKey(), property.getValue()); } runJob(task); } catch (UserInterruptException e) { throw e; } catch (Exception e) { getWriter().writeDebug(e.getMessage(), e); throw new ODPSConsoleException(e.getMessage()); } }