Example usage for java.util HashMap entrySet

List of usage examples for java.util HashMap entrySet

Introduction

In this page you can find the example usage for java.util HashMap entrySet.

Prototype

Set entrySet

To view the source code for java.util HashMap entrySet.

Click Source Link

Document

Holds cached entrySet().

Usage

From source file:edu.emory.library.utils.EULHttpUtils.java

/**
 *  Utility method to GET the contents of a URL and read it into a string.
 *  @param url      url to be read//from  w  ww  .  jav a2 s  . c  o m
 *  @param headers  HashMap of request headers
 */
public static String readUrlContents(String url, HashMap<String, String> headers) throws Exception {
    String response = null;
    HttpClient client = new DefaultHttpClient();
    HttpGet getMethod = new HttpGet(url);

    // add any request headers specified
    for (Map.Entry<String, String> header : headers.entrySet()) {
        getMethod.addHeader(header.getKey(), header.getValue());
    }

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    // returns the response content as string on success
    response = client.execute(getMethod, responseHandler); // could throw HttpException or IOException
    // TODO: catch/handle errors (esp. periodic 503 when Spotlight is unavailable)
    getMethod.releaseConnection();

    return response;
}

From source file:com.aliyun.openservices.odps.console.SelectCommand.java

private static void addSetting(HashMap<String, String> taskConfig, String key, String value) {
    String origSettings = null;//from ww w  .ja va 2 s.  co m
    String addedSettings = null;

    Entry<String, String> property = null;
    for (Entry<String, String> pr : taskConfig.entrySet()) {
        if (pr.getKey().equals("settings")) {
            property = pr;
            origSettings = pr.getValue();
            break;
        }
    }

    if (property == null || origSettings == null) {
        try {
            JSONObject js = new JSONObject();
            js.put(key, value);
            addedSettings = js.toString();
        } catch (Exception e) {
            return;
        }

        if (addedSettings != null) {
            taskConfig.put("settings", addedSettings);
        } else {
            return;
        }
    } else {
        try {
            JSONObject jsob = new JSONObject(origSettings);
            jsob.put(key, value);
            addedSettings = jsob.toString();
        } catch (Exception e) {
            return;
        }

        if (addedSettings != null) {
            property.setValue(addedSettings);
        } else {
            return;
        }
    }
}

From source file:org.apache.streams.gnip.powertrack.GnipActivityFixer.java

public static JSONObject fix(JSONObject json) throws Exception {

    HashMap<ArrayList<String>, JSONObject> nullContents = new HashMap<ArrayList<String>, JSONObject>();
    ArrayList<String> drilldownKeys = new ArrayList<String>();

    findNullContents(json, drilldownKeys, nullContents);

    for (Map.Entry<ArrayList<String>, JSONObject> entry : nullContents.entrySet()) {
        JSONObject frag = entry.getValue();
        editJson(json, entry.getKey(), frag.get(""));
    }/*w  w w.j  av  a  2  s  .  c  om*/

    return json;
}

From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java

public static <K1, K2, V> void print2LevelMap(HashMap<K1, HashMap<K2, V>> twoLevelMap) {
    for (Entry<K1, HashMap<K2, V>> entry : twoLevelMap.entrySet()) {
        K1 key1 = entry.getKey();//from   w  w  w.  ja v a  2  s. co m
        log.info("K1: " + key1.toString());
        HashMap<K2, V> keyvals = entry.getValue();
        for (Entry<K2, V> e : keyvals.entrySet()) {
            K2 key2 = e.getKey();
            V value = e.getValue();
            log.info("K2, V: " + key2.toString() + ", " + value.toString());
        }
    }

}

From source file:it.unibz.instasearch.ui.InstaSearchPage.java

/**
 * @param filter/*from   ww  w . j  a  v  a2 s  .  c  om*/
 * @return
 */
private static String convertFilterToString(HashMap<Field, Set<String>> filter) {

    String filterString = "";

    for (Entry<Field, Set<String>> entry : filter.entrySet()) {

        String fieldFilterString = getFieldFilterString(entry.getKey(), entry.getValue());

        if (!"".equals(fieldFilterString))
            filterString += " " + fieldFilterString;
    }

    return filterString;
}

From source file:edu.emory.library.utils.EULHttpUtils.java

/**
 *  Utility method to POST to a URL and read the result into a string
 *  @param url      url to be read/* w  w w . j av a 2 s  .  c  o  m*/
 *  @param headers  HashMap of request headers
 *  @param parameters  HashMap of parameters
 */
public static String postUrlContents(String url, HashMap<String, String> headers,
        HashMap<String, String> parameters) throws Exception {
    String response = null;
    HttpClient client = new DefaultHttpClient();
    HttpPost postMethod = new HttpPost(url);

    // add any request headers specified
    for (Map.Entry<String, String> header : headers.entrySet()) {
        postMethod.addHeader(header.getKey(), header.getValue());
    }

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> param : parameters.entrySet()) {
        nvps.add(new BasicNameValuePair(param.getKey(), param.getValue()));
    }
    postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    // returns the response content as string on success
    response = client.execute(postMethod, responseHandler); // could throw HttpException or IOException
    // TODO: catch/handle errors (esp. periodic 503 when Spotlight is unavailable)
    postMethod.releaseConnection();

    return response;
}

From source file:org.apache.streams.gnip.powertrack.GnipActivityFixer.java

public static Activity fix(Activity activity) throws Exception {
    ObjectMapper mapper = new ObjectMapper();

    String des = mapper.writeValueAsString(activity);
    JSONObject json = new JSONObject(des);

    HashMap<ArrayList<String>, JSONObject> nullContents = new HashMap<ArrayList<String>, JSONObject>();
    ArrayList<String> drilldownKeys = new ArrayList<String>();

    findNullContents(json, drilldownKeys, nullContents);

    for (Map.Entry<ArrayList<String>, JSONObject> entry : nullContents.entrySet()) {
        JSONObject frag = entry.getValue();
        editJson(json, entry.getKey(), frag.get(""));
    }/*from ww  w. ja  v  a  2 s. c o  m*/

    StringReader str = new StringReader(json.toString());
    Activity testAct = null;
    try {
        testAct = mapper.readValue(str, Activity.class);
    } catch (Exception e) {
        LOGGER.error("Exception creating activity.", e);
        LOGGER.error("JSON : {}" + json.toString());
    }

    return testAct;
}

From source file:ca.uhn.fhir.util.UrlUtil.java

private static Map<String, String[]> toQueryStringMap(HashMap<String, List<String>> map) {
    HashMap<String, String[]> retVal = new HashMap<String, String[]>();
    for (Entry<String, List<String>> nextEntry : map.entrySet()) {
        retVal.put(nextEntry.getKey(), nextEntry.getValue().toArray(new String[nextEntry.getValue().size()]));
    }/*ww  w. ja va2  s . c o m*/
    return retVal;
}

From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java

private static HashMap sortByValues(HashMap map) {
    List list = new LinkedList(map.entrySet());
    // Defined Custom Comparator here
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
        }/*from w w  w .  j  a  va2  s .co  m*/
    });

    // Here I am copying the sorted list in HashMap
    // using LinkedHashMap to preserve the insertion order
    HashMap sortedHashMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedHashMap.put(entry.getKey(), entry.getValue());
    }
    return sortedHashMap;
}

From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java

private static HashMap sortByValuesArray(HashMap map) {
    List list = new LinkedList(map.entrySet());
    // Defined Custom Comparator here
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            ArrayList<Integer> a1 = (ArrayList<Integer>) ((Map.Entry) (o1)).getValue();
            ArrayList<Integer> a2 = (ArrayList<Integer>) ((Map.Entry) (o2)).getValue();
            return ((Comparable) a1.get(0)).compareTo(a2.get(0));
        }/*from  w ww  .  j av a  2 s . c  o m*/
    });

    // Here I am copying the sorted list in HashMap
    // using LinkedHashMap to preserve the insertion order
    HashMap sortedHashMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedHashMap.put(entry.getKey(), entry.getValue());
    }
    return sortedHashMap;
}