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.tencent.tinker.server.model.request.BaseReport.java
private String getPostDataString(HashMap<String, String> params) { StringBuilder result = new StringBuilder(); try {/* w ww . j av a2s . c o m*/ boolean first = true; for (Map.Entry<String, String> entry : params.entrySet()) { if (first) { first = false; } else { result.append('&'); } result.append(URLEncoder.encode(entry.getKey(), ServerUtils.CHARSET)); result.append('='); result.append(URLEncoder.encode(entry.getValue(), ServerUtils.CHARSET)); } } catch (Exception e) { TinkerLog.e(TAG, "getPostDataString fail" + e.getMessage()); } return result.toString(); }
From source file:scheduler.benchmarker.manager.CreateCombinedCategoryPlot.java
private LegendItemCollection createCustomLegend() { LegendItemCollection legend = new LegendItemCollection(); Shape shape = new Rectangle(10, 10); Stroke stroke = new BasicStroke(1F); HashMap<String, Color> pColors = pluginColors.getPlugins(); Iterator it = pColors.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); legend.add(new LegendItem(String.valueOf(pairs.getKey()), null, null, null, shape, (Color) pairs.getValue(), stroke, Color.BLACK)); }/* w ww . jav a 2s. co m*/ return legend; }
From source file:com.yahoo.ycsb.db.RadosClient.java
@Override public Status insert(String table, String key, HashMap<String, ByteIterator> values) { JSONObject json = new JSONObject(); for (final Entry<String, ByteIterator> e : values.entrySet()) { json.put(e.getKey(), e.getValue().toString()); }//from w w w .j av a2 s .co m try { ioctx.write(key, json.toString()); } catch (RadosException e) { return new Status("ERROR-" + e.getReturnValue(), e.getMessage()); } return Status.OK; }
From source file:org.owasp.benchmark.score.report.ScatterTools.java
private void makeDataLabels(OverallResults or, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(or); 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); // set color of average to black and everything else to blue if (averageLabel == label.toCharArray()[0]) { annotation.setPaint(Color.magenta); } else { annotation.setPaint(Color.blue); }/* www.j a va2 s. co m*/ annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); } } }
From source file:net.malisis.ddb.BlockPack.java
/** * Read and load all lang files in this {@link BlockPack}. *//*w ww .j a va 2s. c o m*/ private void readLangFiles() { HashMap<String, String> files = listLangFiles(); for (Entry<String, String> entry : files.entrySet()) { String lang = entry.getKey(); String file = entry.getValue(); try { LanguageRegistry.instance().injectLanguage(lang, StringTranslate.parseLangFile(getInputStream(file))); } catch (IOException e) { DDB.log.error("Failed to read lang file {} : \n{}", name, e.getMessage()); } } }
From source file:org.bpmscript.exec.js.scope.hibernate.HibernateScopeStore.java
/** * @see org.bpmscript.exec.js.scope.IScopeStore#findScope(java.lang.String) */// w w w. j a v a 2s . co m @SuppressWarnings("unchecked") public Scriptable findScope(final Context cx, final String definitionId) throws BpmScriptException { try { return (Scriptable) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { try { Criteria criteria = session.createCriteria(HibernateScope.class); criteria.add(Expression.eq("definitionId", definitionId)); criteria.setProjection(Projections.property("scope")); List list = criteria.list(); if (list.size() == 0) { return null; } byte[] bytes = (byte[]) list.get(0); Scriptable scope = new Global(cx); ScriptableInputStream in = new ScriptableInputStream(new ByteArrayInputStream(bytes), scope); HashMap<String, Object> serialisedDiff = (HashMap<String, Object>) in.readObject(); in.close(); for (Map.Entry<String, Object> entry : serialisedDiff.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); ScriptableObject.putProperty(scope, key, value); } return scope; } catch (Exception e) { throw new HibernateException(e); } } }); } catch (Exception e) { throw new BpmScriptException(e); } }
From source file:com.shareplaylearn.utilities.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(); }/* w w w. j a v a2 s .c om*/ 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()) { if (child.tagName().equals("input") && child.hasAttr("name")) { String keyName = child.attr("name"); String keyValue = null; if (keyName.equals("Email")) { keyValue = username; } else if (keyName.equals("Passwd")) { keyValue = password; } else if (child.hasAttr("value")) { keyValue = child.attr("value"); } if (keyValue != null) { oauthPostConnection.data(keyName, keyValue); formParams.put(keyName, keyValue); } } } oauthPostConnection.cookies(oauthCookies); //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()); } 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:indexer.DocClusterer.java
public List<CentroidCluster<WordVec>> clusterWords(HashMap<String, WordVec> wvecMap, int numClusters) throws Exception { System.out.println("Clustering document: " + dvec.getDocId()); List<WordVec> wordList = new ArrayList<>(wvecMap.size()); for (Map.Entry<String, WordVec> e : wvecMap.entrySet()) { wordList.add(e.getValue());/* w ww .j ava 2 s. c om*/ } KMeansPlusPlusClusterer<WordVec> clusterer = new KMeansPlusPlusClusterer<>( Math.min(numClusters, wordList.size())); if (wordList.size() == 0) return null; List<CentroidCluster<WordVec>> clusters = clusterer.cluster(wordList); return clusters; }
From source file:com.polyvi.xface.exceptionReporter.XCrashInfo.java
/** * ??,?mDeviceInfo//from w w w. j a v a 2s . c o m * @return ? */ private JSONObject getDeviceInfo(Context context) { JSONObject deviceInfo = new JSONObject(); HashMap<String, Object> basedeviceInfo = new XDeviceInfo().getBaseDeviceInfo(context); try { if (null != basedeviceInfo) { Iterator<Entry<String, Object>> iter = basedeviceInfo.entrySet().iterator(); while (iter.hasNext()) { Entry<String, Object> entry = iter.next(); deviceInfo.put(entry.getKey(), (String) entry.getValue()); } } } catch (JSONException e) { XLog.e(CLASS_NAME, "JSONException:", e); return null; } return deviceInfo; }
From source file:com.mobage.air.extension.social.common.Appdata_getEntries.java
@Override public FREObject call(final FREContext context, FREObject[] args) { try {//from w w w . ja v a 2 s . c o m ArgsParser a = new ArgsParser(args); ArrayList<String> keys = a.nextStringArrayList(); final String onSuccessId = a.nextString(); final String onErrorId = a.nextString(); a.finish(); Appdata.OnGetEntriesComplete cb = new Appdata.OnGetEntriesComplete() { @Override public void onSuccess(HashMap<String, String> entries) { try { JSONArray args = new JSONArray(); JSONObject map = new JSONObject(); for (Entry<String, String> ent : entries.entrySet()) { map.put(ent.getKey(), ent.getValue()); } args.put(map); Dispatcher.dispatch(context, onSuccessId, args); } catch (Exception e) { Dispatcher.exception(context, e); } } @Override public void onError(Error error) { Dispatcher.dispatch(context, onErrorId, error); } }; Appdata.getEntries(keys, cb); } catch (Exception e) { Dispatcher.exception(context, e); } return null; }