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:common.DB.java
public static JSONArray createJson(String query, HashMap<String, String> extra) { //Get the formating of lable JSONArray jsonArray = new JSONArray(); try {// w w w . ja v a 2s . c o m DB.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery(query); rsmd = resultSet.getMetaData(); int total_cols = resultSet.getMetaData().getColumnCount(); while (resultSet.next()) { JSONObject obj = new JSONObject(); HashMap<String, String> temp = new HashMap(extra); for (int i = 0; i < total_cols; i++) { String colName = rsmd.getColumnLabel(i + 1); for (Map.Entry<String, String> entry : temp.entrySet()) { String value = entry.getValue(); value = value.replaceAll("\\[" + colName + "\\]", resultSet.getString(colName)); entry.setValue(value); } obj.put(colName, resultSet.getObject(i + 1)); } for (Map.Entry<String, String> entry : temp.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); obj.put(key, val); } jsonArray.put(obj); } } catch (SQLException e) { e.printStackTrace(); } catch (JSONException ex) { ex.printStackTrace(); } close(); return jsonArray; }
From source file:pl.betoncraft.betonquest.editor.model.PackageSet.java
private static PackageSet parseStreams(String setName, HashMap<String, HashMap<String, InputStream>> streamMap) throws IOException { PackageSet set = new PackageSet(setName); for (Entry<String, HashMap<String, InputStream>> entry : streamMap.entrySet()) { String packName = entry.getKey(); HashMap<String, LinkedHashMap<String, String>> values = new LinkedHashMap<>(); for (Entry<String, InputStream> subEntry : entry.getValue().entrySet()) { String name = subEntry.getKey(); InputStream stream = subEntry.getValue(); YAMLParser parser = new YAMLFactory().createParser(stream); String currentPath = ""; String fieldName = ""; while (true) { JsonToken token = parser.nextToken(); if (token == null) break; switch (token) { case START_OBJECT: currentPath = currentPath + fieldName + "."; break; case FIELD_NAME: fieldName = parser.getText(); break; case END_OBJECT: currentPath = currentPath.substring(0, currentPath.substring(0, currentPath.length() - 1).lastIndexOf(".") + 1); break; case VALUE_STRING: case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: case VALUE_FALSE: case VALUE_TRUE: String key = (currentPath + fieldName).substring(1, currentPath.length() + fieldName.length()); LinkedHashMap<String, String> map = values.get(name); if (map == null) { map = new LinkedHashMap<>(); values.put(name, map); }//from ww w . j av a 2 s.c o m map.put(key, parser.getText()); default: // do nothing } } parser.close(); stream.close(); } QuestPackage pack = new QuestPackage(set, packName, values); set.packages.add(pack); } return set; }
From source file:org.anhonesteffort.flock.sync.SyncWorkerUtil.java
protected static <T> HashMap<String, Optional<String>> handleFilterUidsChangedRemotely( AbstractLocalComponentCollection<T> localCollection, HashMap<String, String> remoteUidETagMap) throws RemoteException { HashMap<String, Optional<String>> localUidETagMap = new HashMap<String, Optional<String>>(); for (java.util.Map.Entry<String, String> remoteETagEntry : remoteUidETagMap.entrySet()) { Optional<String> localETag = localCollection.getETagForUid(remoteETagEntry.getKey()); if (!localETag.isPresent() || !localETag.get().equals(remoteETagEntry.getValue())) localUidETagMap.put(remoteETagEntry.getKey(), localETag); }// w w w. j a va2 s. c om return localUidETagMap; }
From source file:gov.wa.wsdot.android.wsdot.service.MountainPassesSyncService.java
private static Integer getWeatherImage(HashMap<Integer, String[]> weatherPhrases, String weather) { Integer image = R.drawable.weather_na; Set<Entry<Integer, String[]>> set = weatherPhrases.entrySet(); Iterator<Entry<Integer, String[]>> i = set.iterator(); if (weather.equals("")) return image; String s0 = weather.split("\\.")[0]; // Pattern match on first sentence only. while (i.hasNext()) { Entry<Integer, String[]> me = i.next(); for (String phrase : (String[]) me.getValue()) { if (s0.toLowerCase().startsWith(phrase)) { image = (Integer) me.getKey(); return image; }/*from w w w . ja va 2 s . c o m*/ } } return image; }
From source file:com.wso2telco.gsma.authenticators.util.USSDOutboundMessage.java
public static String prepare(MessageType messageType, HashMap<String, String> map, String operator) { MobileConnectConfig.OperatorSpecificMessage operatorSpecificMessage = null; String template = ""; Map<String, String> data = new HashMap<String, String>(); // add default map values here // data.put("key", "value"); if (map != null && map.size() > 0) { for (Map.Entry<String, String> entry : map.entrySet()) { data.put(entry.getKey(), entry.getValue()); }/*from w w w . j a v a2s . c o m*/ } // Load operator specific message from hash map if (operator != null) { operatorSpecificMessage = operatorSpecificMessageMap.get(operator); data.put("operator", operator); } if (operatorSpecificMessage != null) { if (messageType == MessageType.LOGIN) { template = operatorSpecificMessage.getLoginMessage(); } if (messageType == MessageType.REGISTRATION) { template = operatorSpecificMessage.getRegistrationMessage(); } } else { if (messageType == MessageType.LOGIN) { template = ussdConfig.getUssdLoginMessage(); } if (messageType == MessageType.REGISTRATION) { template = ussdConfig.getUssdRegistrationMessage(); } } return StrSubstitutor.replace(template, data); }
From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java
/** * changes a mapping keyType1->keyType2->value to * keyType2->keyType1->value/*from w w w . j a v a 2 s . com*/ * * @param tariffSubscriptions * @return */ public static <K1, K2, V> HashMap<K2, HashMap<K1, V>> revertKeyMapping( HashMap<K1, HashMap<K2, V>> twoLevelMap) { HashMap<K2, HashMap<K1, V>> result = new HashMap<K2, HashMap<K1, V>>(); for (Entry<K1, HashMap<K2, V>> entry : twoLevelMap.entrySet()) { K1 key1 = entry.getKey(); HashMap<K2, V> keyvals = entry.getValue(); for (Entry<K2, V> e : keyvals.entrySet()) { K2 key2 = e.getKey(); V value = e.getValue(); HashMap<K1, V> current = result.get(key2); if (current == null) { current = new HashMap<K1, V>(); result.put(key2, current); } current.put(key1, value); } } return result; }
From source file:org.raegdan.troca.Main.java
private static void printRates(HashMap<String, Double> rates) { int maxlen = 0; for (Entry<String, Double> rate : rates.entrySet()) if (rate.getKey().length() > maxlen) maxlen = rate.getKey().length(); maxlen++;//from w ww . j a v a 2 s . com for (Entry<String, Double> rate : rates.entrySet()) { if (rate.getValue() != 0.0) printRate(rate.getKey(), rate.getValue().toString(), maxlen); else printRate(rate.getKey(), "N/A", maxlen); } }
From source file:Main.java
static public String doHttpGet(String url, HashMap<String, String> map) { HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT); HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT); ConnManagerParams.setTimeout(client.getParams(), TIMEOUT); String result = "ERROR"; if (null != map) { int i = 0; for (Map.Entry<String, String> entry : map.entrySet()) { if (i == 0) { url = url + "?" + entry.getKey() + "=" + entry.getValue(); } else { url = url + "&" + entry.getKey() + "=" + entry.getValue(); }/*from w w w . j a va2s .c o m*/ i++; } } HttpGet get = new HttpGet(url); get.setHeaders(headers); try { HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // setCookie(response); result = EntityUtils.toString(response.getEntity(), "UTF-8"); } else { result = EntityUtils.toString(response.getEntity(), "UTF-8") + response.getStatusLine().getStatusCode() + "ERROR"; } if (result != null) { if (result.startsWith("\ufeff")) { result = result.substring(1); } } } catch (ConnectTimeoutException e) { result = "TIMEOUTERROR"; } catch (Exception e) { result = "OTHERERROR"; e.printStackTrace(); } return result; }
From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java
public static HashMap<TariffSpecification, Double> initializeDoubleSubsMap( HashMap<TariffSpecification, Integer> oldmap) { HashMap<TariffSpecification, Double> newmap = new HashMap<TariffSpecification, Double>(); for (Entry<TariffSpecification, Integer> entry : oldmap.entrySet()) { TariffSpecification key = entry.getKey(); double value = entry.getValue().doubleValue(); newmap.put(key, value);/*from w ww.j a va 2 s. co m*/ } return newmap; }
From source file:com.wst.cls.HTTPBaseIO.java
/** * hashMapToString/*from w ww. j a v a 2 s . c o m*/ * * @param map * @param charset * @param charset HTTP.UTF_8 * @return * @throws UnsupportedEncodingException */ @SuppressWarnings("unchecked") public static String hashMapToString(HashMap map, String charset) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); java.util.Iterator it = map.entrySet().iterator(); boolean isfirst = true; while (it.hasNext()) { java.util.Map.Entry entry = (java.util.Map.Entry) it.next(); if (isfirst) { isfirst = false; } else { result.append("&"); } result.append(URLEncoder.encode(entry.getKey().toString(), charset)); result.append("="); result.append(URLEncoder.encode(entry.getValue().toString(), charset)); } return result.toString(); }