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:com.marketcloud.marketcloud.Utilities.java
/** * Returns a list of objects that comply with the given query. * * @param baseURL endpoint of the database * @param m HashMap containing a list of filters * @return a JSONArray containing a list of objects that comply with the given filter *//*from w w w. j a v a 2 s . c om*/ public JSONObject list(final String baseURL, final HashMap<String, Object> m) throws ExecutionException, InterruptedException, JSONException { String url = baseURL; //Concatenate the filters to the base URL int index = 0; int max = m.size() - 1; for (Map.Entry<String, Object> entry : m.entrySet()) { url += entry.getKey() + "=" + entry.getValue(); if (index != max) url += "&"; index++; } return new Connect(context).run("get", url, publicKey); }
From source file:com.taobao.weex.devtools.inspector.protocol.module.CSS.java
private void mockStyleProperty(List<CSSComputedStyleProperty> computedStyle, HashMap<String, String> properties) { for (Map.Entry<String, String> entry : properties.entrySet()) { addStyleProperty(computedStyle, entry.getKey(), entry.getValue()); }/* www. ja va 2 s .co m*/ }
From source file:com.yahoo.ycsb.db.CouchbaseClient.java
/** * Decode the object from server into the storable result. * * @param source the loaded object.//from w w w .j ava 2 s .c om * @param fields the fields to check. * @param dest the result passed back to the ycsb core. */ private void decode(final Object source, final Set<String> fields, final HashMap<String, ByteIterator> dest) { if (useJson) { try { JsonNode json = JSON_MAPPER.readTree((String) source); boolean checkFields = fields != null && fields.size() > 0; for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.fields(); jsonFields.hasNext();) { Map.Entry<String, JsonNode> jsonField = jsonFields.next(); String name = jsonField.getKey(); if (checkFields && fields.contains(name)) { continue; } JsonNode jsonValue = jsonField.getValue(); if (jsonValue != null && !jsonValue.isNull()) { dest.put(name, new StringByteIterator(jsonValue.asText())); } } } catch (Exception e) { throw new RuntimeException("Could not decode JSON"); } } else { HashMap<String, String> converted = (HashMap<String, String>) source; for (Map.Entry<String, String> entry : converted.entrySet()) { dest.put(entry.getKey(), new StringByteIterator(entry.getValue())); } } }
From source file:com.shareplaylearn.OauthPasswordFlow.java
public static LoginInfo googleLogin(String username, String password, String clientId, String callbackUri) throws URISyntaxException, IOException, AuthorizationException, UnauthorizedException { CloseableHttpClient httpClient = HttpClients.custom().build(); String oAuthQuery = "client_id=" + clientId + "&"; oAuthQuery += "response_type=code&"; oAuthQuery += "scope=openid email&"; oAuthQuery += "redirect_uri=" + callbackUri; URI oAuthUrl = new URI("https", null, "accounts.google.com", 443, "/o/oauth2/auth", oAuthQuery, null); Connection oauthGetCoonnection = Jsoup.connect(oAuthUrl.toString()); Connection.Response oauthResponse = oauthGetCoonnection.method(Connection.Method.GET).execute(); if (oauthResponse.statusCode() != 200) { String errorMessage = "Error contacting Google's oauth endpoint: " + oauthResponse.statusCode() + " / " + oauthResponse.statusMessage(); if (oauthResponse.body() != null) { errorMessage += oauthResponse.body(); }// www . j av a 2s .c o m throw new AuthorizationException(errorMessage); } Map<String, String> oauthCookies = oauthResponse.cookies(); Document oauthPage = oauthResponse.parse(); Element oauthForm = oauthPage.getElementById("gaia_loginform"); System.out.println(oauthForm.toString()); Connection oauthPostConnection = Jsoup.connect("https://accounts.google.com/ServiceLoginAuth"); HashMap<String, String> formParams = new HashMap<>(); for (Element child : oauthForm.children()) { System.out.println("Tag name: " + child.tagName()); System.out.println("attrs: " + Arrays.toString(child.attributes().asList().toArray())); if (child.tagName().equals("input") && child.hasAttr("name")) { String keyName = child.attr("name"); String keyValue = null; if (child.hasAttr("value")) { keyValue = child.attr("value"); } if (keyName != null && keyName.trim().length() != 0 && keyValue != null && keyValue.trim().length() != 0) { oauthPostConnection.data(keyName, keyValue); formParams.put(keyName, keyValue); } } } oauthPostConnection.cookies(oauthCookies); formParams.put("Email", username); formParams.put("Passwd-hidden", password); //oauthPostConnection.followRedirects(false); System.out.println("form post params were: "); for (Map.Entry<String, String> kvp : formParams.entrySet()) { //DO NOT let passwords end up in the logs ;) if (kvp.getKey().equals("Passwd")) { continue; } System.out.println(kvp.getKey() + "," + kvp.getValue()); } System.out.println("form cookies were: "); for (Map.Entry<String, String> cookie : oauthCookies.entrySet()) { System.out.println(cookie.getKey() + "," + cookie.getValue()); } //System.exit(0); Connection.Response postResponse = null; try { postResponse = oauthPostConnection.method(Connection.Method.POST).timeout(5000).execute(); } catch (Throwable t) { System.out.println("Failed to post login information to googles endpoint :/ " + t.getMessage()); System.out.println("This usually means the connection is bad, shareplaylearn.com is down, or " + " google is being a punk - login manually and check."); assertTrue(false); } if (postResponse.statusCode() != 200) { String errorMessage = "Failed to validate credentials: " + oauthResponse.statusCode() + " / " + oauthResponse.statusMessage(); if (oauthResponse.body() != null) { errorMessage += oauthResponse.body(); } throw new UnauthorizedException(errorMessage); } System.out.println("Response headers (after post to google form & following redirect):"); for (Map.Entry<String, String> header : postResponse.headers().entrySet()) { System.out.println(header.getKey() + "," + header.getValue()); } System.out.println("Final response url was: " + postResponse.url().toString()); String[] args = postResponse.url().toString().split("&"); LoginInfo loginInfo = new LoginInfo(); for (String arg : args) { if (arg.startsWith("access_token")) { loginInfo.accessToken = arg.split("=")[1].trim(); } else if (arg.startsWith("id_token")) { loginInfo.idToken = arg.split("=")[1].trim(); } else if (arg.startsWith("expires_in")) { loginInfo.expiry = arg.split("=")[1].trim(); } } //Google doesn't actually throw a 401 or anything - it just doesn't redirect //and sends you back to it's login page to try again. //So this is what happens with an invalid password. if (loginInfo.accessToken == null || loginInfo.idToken == null) { //Document oauthPostResponse = postResponse.parse(); //System.out.println("*** Oauth response from google *** "); //System.out.println(oauthPostResponse.toString()); throw new UnauthorizedException( "Error retrieving authorization: did you use the correct username/password?"); } String[] idTokenFields = loginInfo.idToken.split("\\."); if (idTokenFields.length < 3) { throw new AuthorizationException("Error parsing id token " + loginInfo.idToken + "\n" + "it only had " + idTokenFields.length + " field!"); } String jwtBody = new String(Base64.decodeBase64(idTokenFields[1]), StandardCharsets.UTF_8); loginInfo.idTokenBody = new Gson().fromJson(jwtBody, OauthJwt.class); loginInfo.id = loginInfo.idTokenBody.sub; return loginInfo; }
From source file:jsonbroker.library.client.http.HttpDispatcher.java
private HttpRequestBase buildGetRequest(HttpRequestAdapter requestAdapter, Authenticator authenticator) { String requestUri = requestAdapter.getRequestUri(); String host = _networkAddress.getHostAddress(); int port = _networkAddress.getPort(); String uri = String.format("http://%s:%d%s", host, port, requestUri); log.debug(uri, "uri"); HttpGet answer = new HttpGet(uri); // extra headers ... {/* www .j a v a2 s.c o m*/ HashMap<String, String> requestHeaders = requestAdapter.getRequestHeaders(); for (Map.Entry<String, String> item : requestHeaders.entrySet()) { answer.setHeader(item.getKey(), item.getValue()); } } if (null != authenticator) { String authorization = authenticator.getRequestAuthorization(answer.getMethod(), requestUri, null); log.debug(authorization, "authorization"); if (null != authorization) { answer.addHeader("Authorization", authorization); } } return answer; }
From source file:com.acmeair.wxs.utils.MapPutAllAgent.java
@Override public Object process(Session arg0, ObjectMap arg1, Object arg2) { // The key is the partition key, can be either the PK or when partition field is defined the partition field value try {/*from w w w . java 2 s.c o m*/ Object key; // I need to find the real key as the hashmap is using the real key... if (arg2 instanceof SerializedKey) key = ((SerializedKey) arg2).getObject(); else key = arg2; HashMap<Object, Object> objectsForThePartition = this.objectsToSave.get(key); if (objectsForThePartition == null) log.info("ERROR!!! Can not get the objects for partiton key:" + arg2); else { Entry<Object, Object> entry; Object value; for (Iterator<Map.Entry<Object, Object>> itr = objectsForThePartition.entrySet().iterator(); itr .hasNext();) { entry = itr.next(); key = entry.getKey(); value = entry.getValue(); log.debug("Save using agent:" + key + ",value:" + value); arg1.upsert(key, value); } } } catch (ObjectGridException e) { log.info("Getting exception:" + e); } return arg2; }
From source file:com.dh.perfectoffer.event.framework.net.network.NetworkConnection.java
/** * Set the parameters to add to the request. This is meant to be a "key" => "value" Map. * <p>/*ww w.j ava 2s.c o m*/ * The POSTDATA text will be reset as they cannot be used at the same time. * * @see #setPostText(String) * @see #setParameters(ArrayList) * @param parameterMap The parameters to add to the request. * @return The networkConnection. */ public NetworkConnection setParameters(HashMap<String, String> parameterMap) { ArrayList<BasicNameValuePair> parameterList = new ArrayList<BasicNameValuePair>(); for (Map.Entry<String, String> entry : parameterMap.entrySet()) { parameterList.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } return setParameters(parameterList); }
From source file:jsonbroker.library.client.http.HttpDispatcher.java
private HttpRequestBase buildPostRequest(HttpRequestAdapter requestAdapter, Authenticator authenticator) { String requestUri = requestAdapter.getRequestUri(); Entity entity = requestAdapter.getRequestEntity(); String host = _networkAddress.getHostAddress(); int port = _networkAddress.getPort(); String uri = String.format("http://%s:%d%s", host, port, requestUri); // log.debug( uri, "uri" ); HttpPost answer = new HttpPost(uri); // extra headers ... {// ww w . j av a2 s . co m HashMap<String, String> requestHeaders = requestAdapter.getRequestHeaders(); for (Map.Entry<String, String> item : requestHeaders.entrySet()) { answer.setHeader(item.getKey(), item.getValue()); } } // auth headers ... if (null != authenticator) { String authorization = authenticator.getRequestAuthorization(answer.getMethod(), requestUri, entity); log.debug(authorization, "authorization"); if (null != authorization) { answer.addHeader("Authorization", authorization); } } InputStreamEntity inputStreamEntity = new InputStreamEntity(entity.getContent(), entity.getContentLength()); answer.setEntity(inputStreamEntity); return answer; }
From source file:uniko.west.topology.bolts.InteractionGraphBolt.java
private Object flattenGraph(HashMap<String, HashMap<String, ArrayList<Interaction>>> interactionGraph) { HashMap<String, HashMap<String, HashSet<String>>> result = new HashMap<>(); for (Entry<String, HashMap<String, ArrayList<Interaction>>> userEntry : interactionGraph.entrySet()) { HashMap<String, ArrayList<Interaction>> interactions = userEntry.getValue(); String userId = userEntry.getKey(); HashMap<String, HashSet<String>> userResult = new HashMap<>(); for (Entry<String, ArrayList<Interaction>> actionEntry : interactions.entrySet()) { HashSet<String> interactionPartners = new HashSet<>(); String action = actionEntry.getKey(); for (Interaction interAction : actionEntry.getValue()) { interactionPartners.add(interAction.getUserId()); }//from ww w . j a v a2 s . co m userResult.put(action, interactionPartners); } result.put(userId, userResult); } return result; }
From source file:inventory.Inventory.java
/** * Dump all inventory information to the console and returns JSON with the * dump as well//from ww w . j av a 2s. com */ public String dump() { // loop through all possible entires in inventory for (Entry<CabinetType, HashMap<Integer, InventoryShelf>> entry : inventory.entrySet()) { CabinetType cabinet = entry.getKey(); HashMap<Integer, InventoryShelf> shelves = entry.getValue(); System.out.println("Inventory on cabinet " + cabinet.toString()); // response.add(new KVObj("cabinet", cabinet.toString())); for (Entry<Integer, InventoryShelf> shelf : shelves.entrySet()) { Integer shelfId = shelf.getKey(); InventoryShelf is = shelf.getValue(); System.out.println("* " + shelfId + ": " + is.count + " units of " + is.originalShelf); // response.add(new KVObj("shelf", shelfId.toString())); // response.add(new KVObj("count", Integer.toString(is.count))); // response.add(new KVObj("originalShelf", Integer.toString(is.originalShelf))); } } // return Utils.buildJSON(response); return JSONValue.toJSONString(inventory); }