List of usage examples for java.util HashMap get
public V get(Object key)
From source file:org.samjoey.graphing.GraphUtility.java
public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (int j = 0; j < games.size(); j++) { Game game = games.get(j);// w ww . ja va2 s . co m if (game == null) { continue; } for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { } } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } HashMap<String, ChartPanel> chartPanels = new HashMap<>(); for (String key : datasets.keySet()) { JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); chartPanels.put(key, chartPanel); } return chartPanels; }
From source file:fredboat.audio.MusicPersistenceHandler.java
public static void handlePreShutdown(int code) { File dir = new File("music_persistence"); if (!dir.exists()) { dir.mkdir();//from ww w .j av a 2s . c o m } HashMap<String, GuildPlayer> reg = PlayerRegistry.getRegistry(); boolean isUpdate = code == ExitCodes.EXIT_CODE_UPDATE; boolean isRestart = code == ExitCodes.EXIT_CODE_RESTART; for (String gId : reg.keySet()) { try { GuildPlayer player = reg.get(gId); if (!player.isPlaying()) { continue;//Nothing to see here } String msg; if (isUpdate) { msg = I18n.get(player.getGuild()).getString("shutdownUpdating"); } else if (isRestart) { msg = I18n.get(player.getGuild()).getString("shutdownRestarting"); } else { msg = I18n.get(player.getGuild()).getString("shutdownIndef"); } player.getActiveTextChannel().sendMessage(msg).queue(); JSONObject data = new JSONObject(); data.put("vc", player.getUserCurrentVoiceChannel(player.getGuild().getSelfMember()).getId()); data.put("tc", player.getActiveTextChannel().getId()); data.put("isPaused", player.isPaused()); data.put("volume", Float.toString(player.getVolume())); data.put("repeatMode", player.getRepeatMode()); data.put("shuffle", player.isShuffle()); if (player.getPlayingTrack() != null) { data.put("position", player.getPlayingTrack().getEffectivePosition()); } ArrayList<JSONObject> identifiers = new ArrayList<>(); for (AudioTrackContext atc : player.getRemainingTracks()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); AbstractPlayer.getPlayerManager().encodeTrack(new MessageOutput(baos), atc.getTrack()); JSONObject ident = new JSONObject() .put("message", Base64.encodeBase64String(baos.toByteArray())) .put("user", atc.getMember().getUser().getId()); if (atc instanceof SplitAudioTrackContext) { JSONObject split = new JSONObject(); SplitAudioTrackContext c = (SplitAudioTrackContext) atc; split.put("title", c.getEffectiveTitle()).put("startPos", c.getStartPosition()) .put("endPos", c.getStartPosition() + c.getEffectiveDuration()); ident.put("split", split); } identifiers.add(ident); } data.put("sources", identifiers); try { FileUtils.writeStringToFile(new File(dir, gId), data.toString(), Charset.forName("UTF-8")); } catch (IOException ex) { player.getActiveTextChannel() .sendMessage(MessageFormat.format( I18n.get(player.getGuild()).getString("shutdownPersistenceFail"), ex.getMessage())) .queue(); } } catch (Exception ex) { log.error("Error when saving persistence file", ex); } } }
From source file:com.zimbra.cs.util.yauth.TokenAuthenticateV1.java
private static void parseResponseBody(String responseBody, HashMap<String, String> map) { String[] lines = responseBody.split("\n"); for (String line : lines) { int eqIdx = line.indexOf('='); if (eqIdx > 0) { String[] cols = new String[2]; line = line.trim();//from w w w . ja v a 2s.c o m cols[0] = line.substring(0, eqIdx); cols[1] = ""; if (eqIdx < line.length() - 1) { cols[1] = line.substring(eqIdx + 1); if (map.containsKey(cols[0]) && map.get(cols[0]) == null) // only pay attention to the first instance of a value map.put(cols[0], cols[1]); } } } }
From source file:com.nuance.expertassistant.HTTPConnection.java
public static String sendPost(String postURL, HashMap<String, String> paramMap) throws Exception { String url = postURL;/*from ww w. j a va 2 s .c o m*/ HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setHeader("User-Agent", USER_AGENT); if (paramMap != null) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); System.out.println(" Printing Parameters "); for (String key : paramMap.keySet()) { System.out.println(key + " :: " + paramMap.get(key)); urlParameters.add(new BasicNameValuePair(key, paramMap.get(key))); } post.setEntity(new UrlEncodedFormEntity(urlParameters)); } HttpResponse response = client.execute(post); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + post.getEntity()); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder builder = new StringBuilder(); for (String line = null; (line = rd.readLine()) != null;) { builder.append(line).append("\n"); } /* System.out.print("JSON TEXT : " + builder.toString()); String jsonText = builder.toString(); jsonText = "{\"response\":" + jsonText + "}"; JSONObject object = new JSONObject(jsonText); */ System.out.println(" The response code is :" + response.getStatusLine().getStatusCode()); System.out.println(" The string returned is :" + builder.toString()); return builder.toString(); }
From source file:coolmapplugin.util.CMCyCommunicationUtil.java
public static boolean addColumnToNodeTable(String networkSUID, HashMap<String, Double> selectedElements, String columnName) {// w w w . j av a 2s . c o m try { JSONObject jsonBody = new JSONObject(); JSONArray jsonNodesToBeUpdated = new JSONArray(); for (String nodeName : selectedElements.keySet()) { JSONObject jsonNode = new JSONObject(); jsonNode.put("name", nodeName); jsonNode.put(columnName, selectedElements.get(nodeName)); jsonNodesToBeUpdated.put(jsonNode); } jsonBody.put("data", jsonNodesToBeUpdated); jsonBody.put("dataKey", "name"); jsonBody.put("key", "name"); return CyRESTAPI.updateTableData(networkSUID, TABLETYPE_NODE, jsonBody.toString()); } catch (JSONException e) { return false; } }
From source file:eu.europa.ec.fisheries.uvms.exchange.search.SearchFieldMapper.java
/** * Takes all the search values and categorizes them in lists to a key * according to the SearchField/*from w w w . java2 s .c om*/ * * @param searchValues * @return */ public static HashMap<ExchangeSearchField, List<SearchValue>> combineSearchFields( List<SearchValue> searchValues) { HashMap<ExchangeSearchField, List<SearchValue>> values = new HashMap<>(); for (SearchValue search : searchValues) { if (values.containsKey(search.getField())) { values.get(search.getField()).add(search); } else { values.put(search.getField(), new ArrayList<SearchValue>(Arrays.asList(search))); } } return values; }
From source file:com.projity.configuration.FieldDictionary.java
public static void setAliasMap(HashMap aliasMap) { if (aliasMap == null) return;// w w w. j a va 2 s. co m Iterator i = aliasMap.keySet().iterator(); while (i.hasNext()) { String fieldId = (String) i.next(); Field f = Configuration.getFieldFromId(fieldId); if (f != null) f.setAlias((String) aliasMap.get(fieldId)); } }
From source file:net.triptech.buildulator.model.Person.java
/** * Gets the user role.//w ww. j ava2 s.c om * * @param value the value * @param context the context * @return the user role */ public static UserRole getUserRole(final String value, final ApplicationContext context) { UserRole pUserRole = UserRole.ROLE_USER; HashMap<String, UserRole> roles = new HashMap<String, UserRole>(); for (UserRole role : UserRole.values()) { roles.put(getMessage(role.getMessageKey(), context), role); } if (roles.containsKey(value)) { pUserRole = roles.get(value); } return pUserRole; }
From source file:Main.java
private static void __toColoredHtmlLine(String line, HashMap<String, String> tagColorScheme, Writer writer) throws IOException { if (line.trim().length() == 0) return;/*from www. ja v a 2 s . co m*/ line = line.replace("\t", " "); line = line.replace("<", "|<|"); line = line.replace(">", "|>|"); while (true) { int pos = line.indexOf("|<|"); if (pos < 0) break; String tagName = __getNextWord(line, pos + 3); String color = null; if (tagName != null) { color = tagColorScheme.get(tagName); } if (color != null) { line = line.substring(0, pos) + "<span style=\"color: " + color + "; font-weight: bold;\"><" + line.substring(pos + 3); } else { line = line.substring(0, pos) + "<span style=\"color: #808080;\"><" + line.substring(pos + 3); } } line = line.replace("|>|", "></span>"); int n = line.length(); line = line.trim(); n -= line.length(); StringBuilder sb = new StringBuilder(); for (int j = 0; j < n; j++) { sb.append(" "); } writer.append(sb.toString()); writer.append(line); writer.append("<br />\r\n"); }
From source file:playground.wrashid.parkingSearch.ppSim.jdepSim.searchStrategies.analysis.ComparisonGarageCounts.java
private static void init() { String filePath = ZHScenarioGlobal.loadStringParam("ComparisonGarageCounts.garageParkingCountsFile"); Double countsScalingFactor = ZHScenarioGlobal.loadDoubleParam("ComparisonGarageCounts.countsScalingFactor"); countsMatrix = GeneralLib.readStringMatrix(filePath, "\t"); HashMap<String, Double[]> occupancyOfAllSelectedParkings = SingleDayGarageParkingsCount .getOccupancyOfAllSelectedParkings(countsMatrix); selectedParkings = occupancyOfAllSelectedParkings.keySet(); sumOfOccupancyCountsOfSelectedParkings = new double[96]; for (String parkingName : selectedParkings) { Double[] occupancyBins = occupancyOfAllSelectedParkings.get(parkingName); if (occupancyBins == null) { DebugLib.stopSystemAndReportInconsistency(); }// w ww.j av a2 s . c om for (int i = 0; i < 96; i++) { sumOfOccupancyCountsOfSelectedParkings[i] += countsScalingFactor * occupancyBins[i]; } } mappingOfParkingNameToParkingId = SingleDayGarageParkingsCount.getMappingOfParkingNameToParkingId(); }