List of usage examples for java.util Hashtable entrySet
Set entrySet
To view the source code for java.util Hashtable entrySet.
Click Source Link
From source file:org.wso2.ei.bpmn.analytics.core.utils.BPMNAnalyticsCoreUtils.java
/** * Get sorted list (sort by int type values) * * @param table is a hash table to keep the result as key-value pairs * @param key1 is the name for the first value of the JSON object * @param key2 is the name for the second value for the JSON object * @param order is to get the top or bottom results * @param count is to limit the number of results * @return a sorted list as a JSON array string * @throws JSONException/*www .j a va 2 s . c o m*/ */ public static String getIntegerValueSortedList(Hashtable<String, Integer> table, String key1, String key2, String order, int count) throws JSONException { ArrayList<Map.Entry<String, Integer>> l = new ArrayList(table.entrySet()); Collections.sort(l, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return o1.getValue().compareTo(o2.getValue()); } }); Collections.reverse(l); JSONArray array = new JSONArray(); for (int i = 0; i < l.size(); i++) { JSONObject o = new JSONObject(); o.put(key1, l.get(i).getKey()); o.put(key2, l.get(i).getValue()); array.put(o); } //if count exceeds the array length, then assign the array length to the count variable if (count > array.length()) { count = array.length(); } JSONArray arrayPortion = new JSONArray(); if (order.equalsIgnoreCase(BPMNAnalyticsCoreConstants.TOP)) { for (int i = array.length() - count; i < array.length(); i++) { arrayPortion.put(array.get(i)); } } else if (order.equalsIgnoreCase(BPMNAnalyticsCoreConstants.BOTTOM)) { for (int i = 0; i < count; i++) { arrayPortion.put(array.get(i)); } } return arrayPortion.toString(); }
From source file:org.wso2.carbon.pc.analytics.core.utils.AnalyticsUtils.java
/** * Get sorted list (sort by long type keys) * * @param table is a hash table to keep the result as key-value pairs * @param key1 is the name for the first value of the JSON object * @param key2 is the name for the second value for the JSON object * @return a sorted list as a JSON array string * @throws JSONException//from w w w . ja v a2 s . c o m */ public static String getLongKeySortedList(Hashtable<Long, Integer> table, String key1, String key2) throws JSONException { ArrayList<Map.Entry<Long, Integer>> l = new ArrayList(table.entrySet()); Collections.sort(l, new Comparator<Map.Entry<Long, Integer>>() { public int compare(Map.Entry<Long, Integer> o1, Map.Entry<Long, Integer> o2) { return o1.getKey().compareTo(o2.getKey()); } }); JSONArray array = new JSONArray(); for (int i = 0; i < l.size(); i++) { JSONObject o = new JSONObject(); o.put(key1, dateFormatter(l.get(i).getKey())); o.put(key2, l.get(i).getValue()); array.put(o); } return array.toString(); }
From source file:org.wso2.carbon.pc.analytics.core.generic.utils.AnalyticsUtils.java
/** * Get sorted list (sort by double type values) * * @param table is a hash table to keep the result as key-value pairs * @param key1 is the name for the first value of the JSON object * @param key2 is the name for the second value for the JSON object * @param order is to get the top or bottom results * @param count is to limit the number of results * @return a sorted list as a JSON array string * @throws JSONException//from ww w.j a v a 2 s. co m */ public static String getDoubleValueSortedList(Hashtable<String, Double> table, String key1, String key2, String order, int count) throws JSONException { //Transfer as List and sort it ArrayList<Map.Entry<String, Double>> l = new ArrayList(table.entrySet()); Collections.sort(l, new Comparator<Map.Entry<String, Double>>() { public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) { return o1.getValue().compareTo(o2.getValue()); } }); JSONArray array = new JSONArray(); for (int i = 0; i < l.size(); i++) { JSONObject o = new JSONObject(); o.put(key1, l.get(i).getKey()); o.put(key2, round(l.get(i).getValue(), 2)); array.put(o); } //if count exceeds the array length, then assign the array length to the count variable if (count > array.length()) { count = array.length(); } JSONArray arrayPortion = new JSONArray(); if (order.equalsIgnoreCase(AnalyticsConstants.TOP)) { for (int i = array.length() - count; i < array.length(); i++) { arrayPortion.put(array.get(i)); } } else if (order.equalsIgnoreCase(AnalyticsConstants.BOTTOM)) { for (int i = 0; i < count; i++) { arrayPortion.put(array.get(i)); } } return arrayPortion.toString(); }
From source file:org.wso2.ei.bpmn.analytics.core.utils.BPMNAnalyticsCoreUtils.java
/** * Get sorted list (sort by double type values) * * @param table is a hash table to keep the result as key-value pairs * @param key1 is the name for the first value of the JSON object * @param key2 is the name for the second value for the JSON object * @param order is to get the top or bottom results * @param count is to limit the number of results * @return a sorted list as a JSON array string * @throws JSONException/* w w w .j ava 2 s . co m*/ */ public static String getDoubleValueSortedList(Hashtable<String, Double> table, String key1, String key2, String order, int count) throws JSONException { //Transfer as List and sort it ArrayList<Map.Entry<String, Double>> l = new ArrayList(table.entrySet()); Collections.sort(l, new Comparator<Map.Entry<String, Double>>() { public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) { return o1.getValue().compareTo(o2.getValue()); } }); Collections.reverse(l); JSONArray array = new JSONArray(); for (int i = 0; i < l.size(); i++) { JSONObject o = new JSONObject(); o.put(key1, l.get(i).getKey()); o.put(key2, round(l.get(i).getValue(), 2)); array.put(o); } //if count exceeds the array length, then assign the array length to the count variable if (count > array.length()) { count = array.length(); } JSONArray arrayPortion = new JSONArray(); if (order.equalsIgnoreCase(BPMNAnalyticsCoreConstants.TOP)) { for (int i = array.length() - count; i < array.length(); i++) { arrayPortion.put(array.get(i)); } } else if (order.equalsIgnoreCase(BPMNAnalyticsCoreConstants.BOTTOM)) { for (int i = 0; i < count; i++) { arrayPortion.put(array.get(i)); } } return arrayPortion.toString(); }
From source file:com.music.Generator.java
@SuppressWarnings({ "unchecked", "unused" }) private static void printStatistics(ScoreContext ctx, Part part) { if (false) {//ww w.j av a 2 s . c o m Hashtable<String, Object> table = PhraseAnalysis.getAllStatistics(part.getPhrase(0), 1, 0, ctx.getScale().getDefinition()); for (Entry<String, Object> entry : table.entrySet()) { System.out.println(entry.getKey() + "=" + entry.getValue()); } } }
From source file:org.apache.manifoldcf.crawler.connectors.meridio.CommonsHTTPSender.java
/** * Extracts info from message context./*from ww w.j a v a2s . c o m*/ * * @param method Post or get method * @param msgContext the message context */ private static boolean addContextInfo(HttpPost method, MessageContext msgContext) throws AxisFault { boolean httpChunkStream = false; // Get SOAPAction, default to "" String action = msgContext.useSOAPAction() ? msgContext.getSOAPActionURI() : ""; if (action == null) { action = ""; } Message msg = msgContext.getRequestMessage(); if (msg != null) { // First, transfer MIME headers of SOAPMessage to HTTP headers. // Some of these might be overridden later. MimeHeaders mimeHeaders = msg.getMimeHeaders(); if (mimeHeaders != null) { for (Iterator i = mimeHeaders.getAllHeaders(); i.hasNext();) { MimeHeader mimeHeader = (MimeHeader) i.next(); method.addHeader(mimeHeader.getName(), mimeHeader.getValue()); } } method.setHeader(new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, msg.getContentType(msgContext.getSOAPConstants()))); } method.setHeader(new BasicHeader("Accept", "*/*")); method.setHeader(new BasicHeader(HTTPConstants.HEADER_SOAP_ACTION, "\"" + action + "\"")); method.setHeader(new BasicHeader(HTTPConstants.HEADER_USER_AGENT, Messages.getMessage("axisUserAgent"))); // process user defined headers for information. Hashtable userHeaderTable = (Hashtable) msgContext.getProperty(HTTPConstants.REQUEST_HEADERS); if (userHeaderTable != null) { for (Iterator e = userHeaderTable.entrySet().iterator(); e.hasNext();) { Map.Entry me = (Map.Entry) e.next(); Object keyObj = me.getKey(); if (null == keyObj) { continue; } String key = keyObj.toString().trim(); String value = me.getValue().toString().trim(); if (key.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT) && value.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT_100_Continue)) { HttpProtocolParams.setUseExpectContinue(method.getParams(), true); } else if (key.equalsIgnoreCase(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) { String val = me.getValue().toString(); if (null != val) { httpChunkStream = JavaUtils.isTrue(val); } } else { method.addHeader(key, value); } } } return httpChunkStream; }
From source file:org.chililog.server.data.MongoUtils.java
/** * Saves a key-value map to the mongoDB object * /*from w w w.j av a 2 s.c o m*/ * @param dbObject * mongoDB DBObject to which data will be saved * @param fieldName * name of field to save * @param fieldValue * value of field to save * @param isRequired * flag to indicate if field is required. * @throws ChiliLogException */ public static void setKeyValuePairs(DBObject dbObject, String fieldName, Hashtable<String, String> fieldValue, boolean isRequired) throws ChiliLogException { if (dbObject == null) { throw new IllegalArgumentException("dbObject is null"); } if (StringUtils.isBlank(fieldName)) { throw new IllegalArgumentException("fieldName is blank"); } if (isRequired && (fieldValue == null || fieldValue.isEmpty())) { throw new ChiliLogException(Strings.MONGODB_MISSING_REQURIED_FIELD_ERROR, fieldName); } BasicDBObject obj = new BasicDBObject(); for (Entry<String, String> s : fieldValue.entrySet()) { String key = s.getKey(); String value = s.getValue(); obj.put(key, value); } dbObject.put(fieldName, obj); }
From source file:org.apache.manifoldcf.connectorcommon.common.CommonsHTTPSender.java
/** * Extracts info from message context./*from w w w. ja v a 2 s . co m*/ * * @param method Post or get method * @param msgContext the message context */ private static boolean addContextInfo(HttpPost method, MessageContext msgContext) throws AxisFault { boolean httpChunkStream = false; // Get SOAPAction, default to "" String action = msgContext.useSOAPAction() ? msgContext.getSOAPActionURI() : ""; if (action == null) { action = ""; } Message msg = msgContext.getRequestMessage(); if (msg != null) { // First, transfer MIME headers of SOAPMessage to HTTP headers. // Some of these might be overridden later. MimeHeaders mimeHeaders = msg.getMimeHeaders(); if (mimeHeaders != null) { for (Iterator i = mimeHeaders.getAllHeaders(); i.hasNext();) { MimeHeader mimeHeader = (MimeHeader) i.next(); method.addHeader(mimeHeader.getName(), mimeHeader.getValue()); } } method.setHeader(new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, msg.getContentType(msgContext.getSOAPConstants()))); } method.setHeader(new BasicHeader("Accept", "*/*")); method.setHeader(new BasicHeader(HTTPConstants.HEADER_SOAP_ACTION, "\"" + action + "\"")); method.setHeader(new BasicHeader(HTTPConstants.HEADER_USER_AGENT, Messages.getMessage("axisUserAgent"))); // process user defined headers for information. Hashtable userHeaderTable = (Hashtable) msgContext.getProperty(HTTPConstants.REQUEST_HEADERS); if (userHeaderTable != null) { for (Iterator e = userHeaderTable.entrySet().iterator(); e.hasNext();) { Map.Entry me = (Map.Entry) e.next(); Object keyObj = me.getKey(); if (null == keyObj) { continue; } String key = keyObj.toString().trim(); String value = me.getValue().toString().trim(); //if (key.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT) && // value.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT_100_Continue)) { // HttpProtocolParams.setUseExpectContinue(method.getParams(),true); //} else if (key.equalsIgnoreCase(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) { String val = me.getValue().toString(); if (null != val) { httpChunkStream = JavaUtils.isTrue(val); } } else { method.addHeader(key, value); } } } return httpChunkStream; }
From source file:org.apache.synapse.transport.fix.FIXUtils.java
/** * Compares two given FIX URL strings. The second URL is considered equal to the * first URL if all the properties in the first URL also exist in the second URL * and if they have equals values./*from w w w . j a v a 2 s . c o m*/ * * @param url1 a FIX URL String * @param url2 a FIX URL String * @return a boolean value */ public static boolean compareURLs(String url1, String url2) { if (!url1.substring(0, url1.indexOf("?")).equals(url2.substring(0, url2.indexOf("?")))) { return false; } else { Hashtable<String, String> properties1 = BaseUtils.getEPRProperties(url1); Hashtable<String, String> properties2 = BaseUtils.getEPRProperties(url2); for (Map.Entry<String, String> entry : properties1.entrySet()) { if (!properties2.containsKey(entry.getKey())) { return false; } else if (!properties1.get(entry.getKey()).equals(entry.getValue())) { return false; } } } return true; }
From source file:com.nokia.carbide.internal.bugreport.model.Communication.java
/** * Sends given fields as a bug_report to the server provided by product. * @param fields values which are sent to the server * @param product product provides e.g. server URL * @return bug_id of the added bug_entry * @throws RuntimeException if an error occurred. Error can be either some communication error * or error message provided by the server (e.g. invalid password) *///from w w w .ja v a2s . com public static String sendBugReport(Hashtable<String, String> fields, IProduct product) throws RuntimeException { // Nothing to send if (fields == null || fields.size() < 1) { throw new RuntimeException(Messages.getString("Communication.NothingToSend")); //$NON-NLS-1$ } String bugNumber = ""; //$NON-NLS-1$ String url = product.getUrl(); if (url.startsWith("https")) { //$NON-NLS-1$ // we'll support HTTPS with trusted (i.e. signed) certificates // Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); //$NON-NLS-1$ //$NON-NLS-2$ } PostMethod filePost = new PostMethod(url); Part[] parts = new Part[fields.size()]; int i = 0; Iterator<Map.Entry<String, String>> it = fields.entrySet().iterator(); // create parts while (it.hasNext()) { Map.Entry<String, String> productField = it.next(); // attachment field if (productField.getKey() == FieldsHandler.FIELD_ATTACHMENT) { File f = new File(productField.getValue()); try { parts[i] = new FilePart(FieldsHandler.FIELD_DATA, f); } catch (FileNotFoundException e) { e.printStackTrace(); parts[i] = new StringPart(FieldsHandler.FIELD_DATA, Messages.getString("Communication.NotFound")); //$NON-NLS-1$ } // string field } else { parts[i] = new StringPart(productField.getKey(), productField.getValue()); } i++; } filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(8000); setProxyData(client, filePost); int status = 0; String receivedData = ""; //$NON-NLS-1$ try { status = client.executeMethod(filePost); receivedData = filePost.getResponseBodyAsString(1024 * 1024); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { filePost.releaseConnection(); } // HTTP status codes: 2xx = Success if (status >= 200 && status < 300) { // some error occurred in the server side (e.g. invalid password) if (receivedData.contains(FieldsHandler.TAG_RESPONSE_ERROR) && receivedData.contains(FieldsHandler.TAG_RESPONSE_ERROR_CLOSE)) { int beginIndex = receivedData.indexOf(FieldsHandler.TAG_RESPONSE_ERROR) + FieldsHandler.TAG_RESPONSE_ERROR.length(); int endIndex = receivedData.indexOf(FieldsHandler.TAG_RESPONSE_ERROR_CLOSE); String error = receivedData.substring(beginIndex, endIndex); error = error.trim(); throw new RuntimeException(error); // bug_entry was added successfully to database, read the bug_number } else if (receivedData.contains(FieldsHandler.TAG_RESPONSE_BUG_ID) && receivedData.contains(FieldsHandler.TAG_RESPONSE_BUG_ID_CLOSE)) { int beginIndex = receivedData.indexOf(FieldsHandler.TAG_RESPONSE_BUG_ID) + FieldsHandler.TAG_RESPONSE_BUG_ID.length(); int endIndex = receivedData.indexOf(FieldsHandler.TAG_RESPONSE_BUG_ID_CLOSE); bugNumber = receivedData.substring(beginIndex, endIndex); bugNumber = bugNumber.trim(); // some unknown error } else { throw new RuntimeException(Messages.getString("Communication.UnknownError")); //$NON-NLS-1$ } // some HTTP error (status code other than 2xx) } else { String error = Messages.getString("Communication.HttpError") + status; //$NON-NLS-1$ throw new RuntimeException(error); } return bugNumber; }