List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:com.opengamma.analytics.util.amount.CubeValue.java
/** * Create a new object containing the point of the initial object and the new point. If the point is not in the existing points of the object, it is put in the map. * If a point is already in the existing point of the object, the value is added to the existing value. * @param surfaceValue The surface value. * @param point The surface point./* w w w .jav a2 s . co m*/ * @param value The associated value. * @return The combined/sum surface value. */ public static CubeValue plus(final CubeValue surfaceValue, final Triple<Double, Double, Double> point, final Double value) { ArgumentChecker.notNull(surfaceValue, "Surface value"); ArgumentChecker.notNull(point, "Point"); final HashMap<Triple<Double, Double, Double>, Double> plus = new HashMap<>(surfaceValue._data); if (surfaceValue._data.containsKey(point)) { plus.put(point, value + surfaceValue._data.get(point)); } else { plus.put(point, value); } return new CubeValue(plus); }
From source file:de.fhg.fokus.odp.portal.managedatasets.utils.HashMapUtils.java
/** * Meta data to map./*from w w w. j a v a 2 s . c om*/ * * @param metaData * the meta data * @return the hash map */ public static HashMap<String, String> metaDataToMap(MetaDataBean metaData) { HashMap<String, String> metaDataMap = new HashMap<String, String>(); HashMap<String, String> extrasMap = new HashMap<String, String>(); List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>(); extrasMap.put("temporal_coverage_from", metaData.getTemporal_coverage_from()); extrasMap.put("temporal_coverage_to", metaData.getTemporal_coverage_to()); extrasMap.put("temporal_granularity", metaData.getTemporal_granularity()); extrasMap.put("geographical_coverage", metaData.getGeographical_coverage()); extrasMap.put("geographical_granularity", metaData.getGeographical_granularity()); extrasMap.put("date_released", DateUtils.dateToStringTemporalCoverage(metaData.getDate_released())); extrasMap.put("others", metaData.getOthers()); for (Resource resource : metaData.getResources()) { Map<String, String> resourceMap = new HashMap<String, String>(); if (!resource.getUrl().isEmpty() && !resource.getFormat().isEmpty()) { resourceMap.put("url", resource.getUrl()); resourceMap.put("format", resource.getFormat().toUpperCase()); resourceMap.put("description", resource.getDescription()); resourceMap.put("language", resource.getLanguage()); resourcesList.add(resourceMap); } } metaDataMap.put("extras", JSONValue.toJSONString(extrasMap)); metaDataMap.put("resources", JSONValue.toJSONString(resourcesList)); if (metaData.getTags().isEmpty()) { metaDataMap.put("tags", "[]"); } else { StringBuilder tagsBuilder = new StringBuilder(); for (String tag : metaData.getTags().split(",")) { tagsBuilder.append("\"" + tag.trim() + "\","); } // remove trailing comma tagsBuilder = tagsBuilder.deleteCharAt(tagsBuilder.length() - 1); metaDataMap.put("tags", "[" + tagsBuilder.toString().trim() + "]"); } metaDataMap.put("groups", JSONValue.toJSONString(metaData.getGroups())); metaDataMap.put("title", "\"" + metaData.getTitle() + "\""); metaDataMap.put("name", "\"" + metaData.getName() + "\""); metaDataMap.put("author", "\"" + metaData.getAuthor() + "\""); metaDataMap.put("author_email", "\"" + metaData.getAuthor_email() + "\""); metaDataMap.put("url", "\"" + metaData.getUrl() + "\""); metaDataMap.put("notes", "\"" + metaData.getNotes() + "\""); metaDataMap.put("license_id", "\"" + metaData.getLicense_id() + "\""); metaDataMap.put("version", "\"" + metaData.getVersion() + "\""); metaDataMap.put("maintainer", "\"" + metaData.getMaintainer() + "\""); metaDataMap.put("maintainer_email", "\"" + metaData.getMaintainer_email() + "\""); metaDataMap.put("metadata_created", "\"" + DateUtils.dateToStringMetaDate(metaData.getMetadata_created()) + "\""); metaDataMap.put("metadata_modified", "\"" + metaData.getMetadata_modified() + "\""); log.info("JSON String for create metadata: " + metaDataMap.toString()); return metaDataMap; }
From source file:com.gst.integrationtests.common.CenterHelper.java
public static int[] associateGroups(final int id, final int[] groupMembers, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { final String ASSOCIATE_GROUP_CENTER_URL = CENTERS_URL + "/" + id + "?command=associateGroups&" + Utils.TENANT_IDENTIFIER;//ww w. j a v a2 s. c om HashMap groupMemberHashMap = new HashMap(); groupMemberHashMap.put("groupMembers", groupMembers); System.out.println("---------------------------------ASSOCIATING GROUPS AT " + id + "--------------------------------------------"); HashMap hash = Utils.performServerPost(requestSpec, responseSpec, ASSOCIATE_GROUP_CENTER_URL, new Gson().toJson(groupMemberHashMap), "changes"); System.out.println(hash); ArrayList<String> arr = (ArrayList<String>) hash.get("groupMembers"); int[] ret = new int[arr.size()]; for (int i = 0; i < ret.length; i++) { ret[i] = Integer.parseInt(arr.get(i)); } return ret; }
From source file:info.unyttig.helladroid.newzbin.NewzBinController.java
/** * Fetches a report from Newzbin based on a given id. * However if the report is already cached, its just fetched from the hashmap. * @param id/*from www. j av a 2s. c o m*/ */ public static NewzBinReport getReportInfo(int id) { if (detailedReports.containsKey(id)) return detailedReports.get(id); String url = NBAPIURL + "reportinfo/"; HashMap<String, String> searchOptions = new HashMap<String, String>(); searchOptions.put("id", "" + id); try { HttpResponse response = doPost(url, searchOptions); checkReturnCode(response.getStatusLine().getStatusCode(), false); InputStream is = response.getEntity().getContent(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); NewzBinDRHandler handler = new NewzBinDRHandler(); if (reports.containsKey(id)) handler.nbdr = reports.get(id); xr.setContentHandler(handler); xr.parse(new InputSource(is)); detailedReports.put(id, handler.getParsedData()); // Temp ArrayList<NewzBinReportComment> comments = handler.nbdr.getComments(); Log.i(LOG_NAME, "Comments size: " + comments.size()); Iterator<NewzBinReportComment> sd = comments.iterator(); while (sd.hasNext()) { NewzBinReportComment nrc = sd.next(); Log.i(LOG_NAME, nrc.toString()); } return handler.getParsedData(); } catch (ClientProtocolException e) { Log.e(LOG_NAME, "ClientProtocol thrown: ", e); } catch (IOException e) { Log.e(LOG_NAME, "IOException thrown: ", e); } catch (NewzBinPostReturnCodeException e) { Log.e(LOG_NAME, "POST ReturnCode error: " + e.toString()); } catch (ParserConfigurationException e) { Log.e(LOG_NAME, "ParserError thrown: ", e); } catch (SAXException e) { Log.e(LOG_NAME, "SAXError thrown: ", e); } return null; }
From source file:com.clutch.ClutchAB.java
private static void sendABLogs() { ArrayList<ABRow> logs = stats.getABLogs(); if (logs.size() == 0) { return;/*from ww w .jav a2s.c o m*/ } final ABRow lastRow = logs.get(logs.size() - 1); JSONArray jsonLogs = new JSONArray(); for (ABRow row : logs) { JSONObject rowObj = new JSONObject(); try { rowObj.put("uuid", row.uuid); rowObj.put("ts", row.ts); rowObj.put("data", row.data); } catch (JSONException e1) { Log.e(TAG, "Could not properly encode the AB logs into JSON for upload to Clutch. Discarding the row."); // TODO: Don't discard the row. continue; } jsonLogs.put(rowObj); } HashMap<String, Object> params = new HashMap<String, Object>(); params.put("logs", jsonLogs); params.put("guid", ClutchAPIClient.getFakeGUID()); ClutchAPIClient.callMethod("send_ab_logs", params, new ClutchAPIResponseHandler() { @Override public void onSuccess(JSONObject response) { if ("ok".equals(response.optString("status"))) { stats.deleteABLogs(lastRow.ts); } else { Log.e(TAG, "Failed to send the Clutch AB logs to the server."); } } @Override public void onFailure(Throwable e, JSONObject errorResponse) { Log.e(TAG, "Failed to send AB logs to Clutch: " + errorResponse); } }); }
From source file:Main.java
public static void DoConvertAttrsToStringMap(Attributes atts, HashMap<String, String> MapDest) { for (int attrsIndex = 0; attrsIndex < atts.getLength(); attrsIndex++) { String AttrName = atts.getLocalName(attrsIndex); String AttrValue = atts.getValue(attrsIndex); try {// w w w .j a v a2 s . c om AttrValue = URLDecoder.decode(AttrValue, URL_DECODE_TYPE); MapDest.put(AttrName, AttrValue); } catch (UnsupportedEncodingException e) { // TODO } //Log.w("FCXML", "DoConvertAttrsToStringMap: Index: " + attrsIndex + " Name: " + AttrName + " Value " + AttrValue ); } }
From source file:Main.java
/** * Returns a {@link Map} mapping each unique element in the given * {@link Collection} to an {@link Integer} representing the number of * occurances of that element in the {@link Collection}. An entry that maps * to <tt>null</tt> indicates that the element does not appear in the given * {@link Collection}./* w w w. jav a 2s.c o m*/ */ public static Map getCardinalityMap(final Collection col) { HashMap count = new HashMap(); Iterator it = col.iterator(); while (it.hasNext()) { Object obj = it.next(); Integer c = (Integer) (count.get(obj)); if (null == c) { count.put(obj, new Integer(1)); } else { count.put(obj, new Integer(c.intValue() + 1)); } } return count; }
From source file:com.gst.integrationtests.common.CenterHelper.java
public static String activateCenterAsJSON(final String activationDate) { final HashMap<String, String> map = new HashMap<>(); map.put("dateFormat", "dd MMMM yyyy"); map.put("locale", "en"); if (StringUtils.isNotEmpty(activationDate)) { map.put("activationDate", activationDate); } else {/*w w w .ja va2 s . com*/ map.put("activationDate", "CREATED_DATE"); System.out.println("defaulting to fixed date: CREATED_DATE"); } System.out.println("map : " + map); return new Gson().toJson(map); }
From source file:de.zib.gndms.gritserv.delegation.DelegationAux.java
public static void addDelegationEPR(HashMap<String, String> con, EndpointReferenceType epr) throws SerializationException, IOException { con.put(DELEGATION_EPR_KEY, encodeDelegationEPR(epr).toString()); }
From source file:cl.almejo.vsim.gui.ColorScheme.java
public static String save() throws IOException { HashMap<String, HashMap<String, String>> map = new HashMap<String, HashMap<String, String>>(); for (String schemeName : _schemes.keySet()) { ColorScheme scheme = _schemes.get(schemeName); HashMap<String, String> colors = new HashMap<String, String>(); for (String colorName : scheme._colors.keySet()) { Color color = scheme._colors.get(colorName); colors.put(colorName, "#" + Integer.toHexString(color.getRGB()).substring(2)); }//from w w w . j av a 2 s . c om map.put(schemeName, colors); } ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map); }