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.owasp.benchmark.score.report.Scatter.java
private Entry<Point2D, String> getMatch(HashMap<Point2D, String> map, Entry<Point2D, String> e1) { for (Entry<Point2D, String> e2 : map.entrySet()) { Double xd = Math.abs(e1.getKey().getX() - e2.getKey().getX()); Double yd = Math.abs(e1.getKey().getY() - e2.getKey().getY()); boolean close = xd < 1 && yd < 3; if (e1 != e2 && e1.getValue() != null && e2.getValue() != null && close) { return e2; }/* w w w . j a va 2 s . c o m*/ } return null; }
From source file:com.skilrock.lms.web.roleMgmt.common.PrivsInterceptor.java
/** * Determines if the request should be allowed for the action * /* w w w .j ava 2s. co m*/ * @param request * The request * @param action * The action object * @return True if allowed, false otherwise * @throws SQLException */ protected boolean isAllowed(HttpServletRequest request, Object action) throws SQLException { String json = request.getParameter("json"); HttpSession session = null; String userName = null; if (json != null) { JSONObject requestData = (JSONObject) JSONSerializer.toJSON(json); userName = (String) requestData.get("userName"); } if (userName == null) { session = request.getSession(); } else { Map currentUserSessionMap = (Map) LMSUtility.sc.getAttribute("LOGGED_IN_USERS"); session = (HttpSession) currentUserSessionMap.get(userName); } // logger.debug("allowedRoles::" + allowedRoles); // logger.debug("i am inside priv interceptor"); String actionName = ActionContext.getContext().getName(); logger.debug("Action Name - " + actionName); boolean result = false; ArrayList<String> userActionList = new ArrayList<String>(); userActionList = (ArrayList<String>) session.getAttribute("ACTION_LIST"); logger.debug("userActionList: " + userActionList); List<String> disableTabs; UserInfoBean userBean = (UserInfoBean) session.getAttribute("USER_INFO"); ServletContext sc = ServletActionContext.getServletContext(); if (userBean.getUserType().equals("RETAILER") && !isSaleDuration(userBean)) { disableTabs = Arrays.asList(((String) sc.getAttribute("RET_SALE_BOUND")).split(",")); for (int i = 0; i < disableTabs.size(); i++) { if (actionName.contains(disableTabs.get(i))) { saleStatus = "SALE_STOP"; return false; } } } if (!userBean.getLoginChannel().equalsIgnoreCase("WEB")) { return false; } if (userActionList.contains(actionName)) { HashMap actionServiceMap = (HashMap) session.getAttribute("PRIV_MAP"); Iterator itrMap = actionServiceMap.entrySet().iterator(); while (itrMap.hasNext()) { Map.Entry pairs = (Map.Entry) itrMap.next(); List privList = (List) pairs.getValue(); for (int i = 0; i < privList.size(); i++) { if (((PriviledgeBean) privList.get(i)).getActionMapping().equals(actionName)) { refreshSession(session); } } } result = true; } return result; }
From source file:com.amazonaws.service.apigateway.importer.impl.SchemaTransformer.java
private void replaceRefs(JsonNode root, HashMap<String, String> schemaMap) { ObjectNode definitionsNode = new ObjectNode(JsonNodeFactory.instance); for (Map.Entry<String, String> entry : schemaMap.entrySet()) { JsonNode schemaNode = deserialize(entry.getValue()); definitionsNode.set(entry.getKey(), schemaNode); }//from ww w. j a v a 2 s . c o m ((ObjectNode) root).set("definitions", definitionsNode); }
From source file:aptgraph.server.JsonRpcServer.java
/** * Start the server, blocking. This method will only return if the server * crashed...//from w ww .j av a 2s . c o m * @throws java.io.IOException if the graph file cannot be read * @throws java.lang.ClassNotFoundException if the Graph class is not found * @throws java.lang.Exception if the server cannot start... */ public final void start() throws IOException, ClassNotFoundException, Exception { LOGGER.info("Reading graphs from disk..."); ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(input_file)); HashMap<String, LinkedList<Graph<Request>>> user_graphs = (HashMap<String, LinkedList<Graph<Request>>>) input .readObject(); input.close(); Map.Entry<String, LinkedList<Graph<Request>>> entry_set = user_graphs.entrySet().iterator().next(); String first_key = entry_set.getKey(); LOGGER.log(Level.INFO, "Graph has {0} features", user_graphs.get(first_key).size()); LOGGER.log(Level.INFO, "k-NN Graph : k = {0}", user_graphs.get(first_key).getFirst().getK()); LOGGER.log(Level.INFO, "Starting JSON-RPC server at http://{0}:{1}", new Object[] { config.getServerHost(), config.getServerPort() }); RequestHandler request_handler = new RequestHandler(user_graphs); ObjectMapper object_mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addSerializer(Graph.class, new GraphSerializer()); module.addSerializer(Domain.class, new DomainSerializer()); module.addSerializer(Neighbor.class, new NeighborSerializer()); object_mapper.registerModule(module); com.googlecode.jsonrpc4j.JsonRpcServer jsonrpc_server = new com.googlecode.jsonrpc4j.JsonRpcServer( object_mapper, request_handler); QueuedThreadPool thread_pool = new QueuedThreadPool(config.getMaxThreads(), config.getMinThreads(), config.getIdleTimeout(), new ArrayBlockingQueue<Runnable>(config.getMaxPendingRequests())); http_server = new org.eclipse.jetty.server.Server(thread_pool); //http_server = new org.eclipse.jetty.server.Server(); ServerConnector http_connector = new ServerConnector(http_server); http_connector.setHost(config.getServerHost()); http_connector.setPort(config.getServerPort()); http_server.setConnectors(new Connector[] { http_connector }); http_server.setHandler(new JettyHandler(jsonrpc_server)); http_server.start(); }
From source file:com.chingo247.structureapi.persistence.service.ValidationService.java
public void validate() { deleteInvalidState();/* www . java2 s . c o m*/ HashMap<String, Timestamp> worlddata = getWorldData(); for (Entry<String, Timestamp> entry : worlddata.entrySet()) { removeCreatedBefore(entry.getKey(), entry.getValue()); setRemovedAfter(Bukkit.getWorld(entry.getKey()), entry.getValue()); } }
From source file:feedme.controller.UpdateCategoryServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from www . j av a 2s . c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); String city = request.getParameter("city"); HashMap<String, Integer> cat = new DbHPOnLoad().getCategoriesByCity(city); try { JSONObject catObj = new JSONObject(); catObj.put("categorys", new JSONArray()); JSONArray cate = catObj.getJSONArray("categorys"); for (Map.Entry<String, Integer> entry : cat.entrySet()) { cate.put(new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey())); } response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(catObj); response.getWriter().flush(); } catch (JSONException ex) { Logger.getLogger(OrderCompleteServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.safegees.safegees.util.HttpUrlConnection.java
private String getDataString(HashMap<String, String> params) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; for (Map.Entry<String, String> entry : params.entrySet()) { if (first) first = false;/*from www. j av a 2 s .c o m*/ else result.append("&"); result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); result.append("="); result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } return result.toString(); }
From source file:info.aamulumi.sharedshopping.network.RequestSender.java
/** * Create a string formatted with parameters * * @param params - HashMap containing all parameters * @return formatted string//w w w. j av a 2 s .com * @throws UnsupportedEncodingException */ private String getFormattedParameters(HashMap<String, String> params) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; // Add each entry to String for (Map.Entry<String, String> entry : params.entrySet()) { if (first) first = false; else result.append("&"); result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); result.append("="); result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } return result.toString(); }
From source file:com.esri.geoportal.geoportal.commons.geometry.GeometryService.java
/** * Calls the projection service with the given parameters * /* w w w . j a v a 2 s . co m*/ * @param params the parameters for the projection call * * @return the reprojected points */ private MultiPoint callProjectService(HashMap<String, String> params) throws IOException, URISyntaxException { HttpPost request = new HttpPost(createProjectUrl().toURI()); HttpEntity entrity = new UrlEncodedFormEntity(params.entrySet().stream() .map(e -> new BasicNameValuePair(e.getKey(), e.getValue())).collect(Collectors.toList()), "UTF-8"); request.setEntity(entrity); try (CloseableHttpResponse httpResponse = httpClient.execute(request); InputStream contentStream = httpResponse.getEntity().getContent();) { if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } MultiPointGeometry geom = mapper.readValue(contentStream, MultiPointGeometry.class); MultiPoint result = new MultiPoint(); geom.geometries[0].points.forEach(pt -> result.add(pt[0], pt[1])); return result; } }
From source file:org.elasticsearch.test.rest.yaml.ClientYamlTestExecutionContext.java
/** * Calls an elasticsearch api with the parameters and request body provided as arguments. * Saves the obtained response in the execution context. *//*from w ww .j a v a 2 s . c om*/ public ClientYamlTestResponse callApi(String apiName, Map<String, String> params, List<Map<String, Object>> bodies, Map<String, String> headers) throws IOException { //makes a copy of the parameters before modifying them for this specific request HashMap<String, String> requestParams = new HashMap<>(params); requestParams.putIfAbsent("error_trace", "true"); // By default ask for error traces, this my be overridden by params for (Map.Entry<String, String> entry : requestParams.entrySet()) { if (stash.containsStashedValue(entry.getValue())) { entry.setValue(stash.getValue(entry.getValue()).toString()); } } HttpEntity entity = createEntity(bodies, headers); try { response = callApiInternal(apiName, requestParams, entity, headers); return response; } catch (ClientYamlTestResponseException e) { response = e.getRestTestResponse(); throw e; } finally { // if we hit a bad exception the response is null Object responseBody = response != null ? response.getBody() : null; //we always stash the last response body stash.stashValue("body", responseBody); } }