List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:common.DB.java
public static ResultList query(String query) { ArrayList list = new ArrayList(); ResultList result = new ResultList(list); try {//from ww w . j av a 2s . co m DB.getConnection(); if (connection != null) { statement = connection.createStatement(); resultSet = statement.executeQuery(query); ResultSetMetaData md = resultSet.getMetaData(); int columns = md.getColumnCount(); list.add(new HashMap(columns)); while (resultSet.next()) { HashMap row = new HashMap(columns); for (int i = 1; i <= columns; ++i) { row.put(md.getColumnLabel(i), resultSet.getString(i)); } list.add(row); } } else { return null; } } catch (SQLException e) { e.printStackTrace(); } close(); return result; }
From source file:de.tudarmstadt.ukp.dkpro.tc.weka.evaluation.MekaEvaluationUtils.java
/** * Calculates a number of evaluation measures for multi-label classification, including class-wise measures. * /*from w ww. j av a2 s. co m*/ * @param predictions * predictions by the classifier (ranking) * @param goldStandard * gold standard (bipartition) * @param t * a threshold to create bipartitions from rankings * @param classNames * the class label names * @return the evaluation statistics */ public static HashMap<String, Double> calcMLStats(double predictions[][], int goldStandard[][], double t[], String[] classNames) { HashMap<String, Double> results = calcMLStats(predictions, goldStandard, t); int L = goldStandard[0].length; int Ypred[][] = ThresholdUtils.threshold(predictions, t); // class-wise measures for (int j = 0; j < L; j++) { results.put(HAMMING_ACCURACY + " [" + classNames[j] + "]", Metrics.P_Hamming(goldStandard, Ypred, j)); results.put(PRECISION + " [" + classNames[j] + "]", Metrics.P_Precision(goldStandard, Ypred, j)); results.put(RECALL + " [" + classNames[j] + "]", Metrics.P_Recall(goldStandard, Ypred, j)); } return results; }
From source file:eu.prestoprime.p4gui.connection.SearchConnection.java
private static SearchResults solrSearch(final P4Service service, final String searchUri, String query, final String from, final String resultCount, final String sortField, final String sortAsc, final Map<String, String> facetMap) { HashMap<String, String> urlParamMap = new HashMap<>(); urlParamMap.put("queryTerms", query); urlParamMap.put("from", from); urlParamMap.put("resultCount", resultCount); urlParamMap.put("sortAsc", sortAsc); urlParamMap.put("sortField", sortField); urlParamMap.put("facetFilters", wrapParams(facetMap)); final String path = service.getURL() + searchUri + URLUtils.buildUrlParamString(urlParamMap); SearchResults results = new SearchResults(); Unmarshaller unmarshaller = null; String resultString = null;//from www . ja v a2 s.c o m try { logger.debug("Query to P4WS:\n" + path); P4HttpClient client = new P4HttpClient(service.getUserID()); client.getParams().setParameter("http.protocol.content-charset", "UTF-8"); HttpRequestBase request = new HttpGet(path); HttpResponse response = client.executeRequest(request); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream is = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } resultString = sb.toString(); is.close(); } EntityUtils.consume(entity); unmarshaller = ModelUtils.getUnmarshaller(P4JAXBPackage.CONF); results = (SearchResults) unmarshaller.unmarshal(new ByteArrayInputStream(resultString.getBytes())); } catch (JAXBException | IOException e) { String message = e.getMessage() + " - "; logger.error(e.getMessage()); if (e instanceof JAXBException) { message += "The returned xml from P4WS was not a valid searchresult."; } else { message += "P4WS could not be accessed."; } results.setErrorMessage(message); } return results; }
From source file:com.activecq.api.utils.TypeUtil.java
/** * Converts a JSONObject to a simple Map. This will only work properly for * JSONObjects of depth 1.//from w ww . java 2 s .com * * @param json * @return */ public static Map toMap(JSONObject json) { HashMap<String, Object> map = new HashMap<String, Object>(); List<String> keys = IteratorUtils.toList(json.keys()); for (String key : keys) { try { map.put(key, json.get(key)); } catch (JSONException ex) { Logger.getLogger(ActiveForm.class.getName()).log(Level.SEVERE, null, ex); } } return map; }
From source file:com.gst.integrationtests.common.GroupHelper.java
public static String updateGroupAsJSON(final String name) { final HashMap<String, String> map = new HashMap<>(); map.put("name", name); System.out.println("map : " + map); return new Gson().toJson(map); }
From source file:com.opengamma.analytics.util.surface.StringValue.java
/** * Create a new object containing the point of both initial objects. If a point is only on one surface, its value is the original value. * If a point is on both surfaces, the values on that point are added. * @param value1 The first "string value". * @param value2 The second "string value". * @return The combined/sum "string value". *//* ww w . ja v a2 s. c om*/ public static StringValue plus(final StringValue value1, final StringValue value2) { Validate.notNull(value1, "Surface value 1"); Validate.notNull(value2, "Surface value 2"); final HashMap<String, Double> plus = new HashMap<String, Double>(value1._data); for (final String p : value2._data.keySet()) { if (value1._data.containsKey(p)) { plus.put(p, value2._data.get(p) + value1._data.get(p)); } else { plus.put(p, value2._data.get(p)); } } return new StringValue(plus); }
From source file:com.baasbox.controllers.Root.java
@With({ RootCredentialWrapFilter.class }) public static Result getOverridableConfiguration() { HashMap returnMap = new HashMap(); returnMap.put(BBConfiguration.DB_ALERT_THRESHOLD, BBConfiguration.getDBAlertThreshold()); returnMap.put(BBConfiguration.DB_SIZE_THRESHOLD, BBConfiguration.getDBSizeThreshold()); try {/*w w w. j a va 2 s. c om*/ return ok(new ObjectMapper().writeValueAsString(returnMap)); } catch (JsonProcessingException e) { return internalServerError(ExceptionUtils.getMessage(e)); } }
From source file:com.gst.integrationtests.common.GroupHelper.java
public static String assignStaffAndInheritStaffForClientAccountsAsJSON(final String staffId) { final HashMap<String, String> map = new HashMap<>(); map.put("staffId", staffId); map.put("inheritStaffForClientAccounts", "true"); System.out.println("map : " + map); return new Gson().toJson(map); }
From source file:Main.java
public static void loadHashMapData() throws IOException { HashMap<String, String> hashMap = new HashMap<String, String>(); Properties properties = new Properties(); File file = new File(HASHMAPFILEPATH); if (file.exists()) { properties.load(new FileInputStream(HASHMAPFILEPATH)); for (String key : properties.stringPropertyNames()) { hashMap.put(key, properties.getProperty(key)); GPSDataMap = hashMap;/*from w ww . j a v a2 s . com*/ } } else { file.createNewFile(); } }
From source file:info.aamulumi.sharedshopping.APIConnection.java
/** * Send a request to create a shopping list * * @param name - name of the shopping list * @return the created user//from w ww . j ava 2s . c o m */ public static ShoppingList createShoppingList(String name) { HashMap<String, String> params = new HashMap<>(1); params.put("name", name); return APIConnection.createItem(urlShoppingLists, "parseShoppingList", null, params); }