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:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static HashMap<?, ?> sortByValue(HashMap<?, ?> map, final int flag) {
    // flag = 0 decreasing order otherwise increasing
    List<Map.Entry<?, ?>> list = new LinkedList<Map.Entry<?, ?>>(map.entrySet());
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            if (flag == 0)
                return ((Comparable) ((Map.Entry) (o2)).getValue()).compareTo(((Map.Entry) (o1)).getValue());
            else/*  ww w  . j av  a  2s .  c o m*/
                return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
        }
    });

    HashMap result = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:frequencyassignment.charts.Charts.java

public static void displayPie(String name, HashMap<String, Double> categoryValue) {
    DefaultPieDataset data = new DefaultKeyedValuesDataset();
    for (Map.Entry<String, Double> entry : categoryValue.entrySet()) {
        data.setValue(entry.getKey(), entry.getValue());
    }// w ww. j av  a 2 s .c om
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", data, true, true, true);
    ChartFrame frame = new ChartFrame(name, chart);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Returns the minimum entry of the placeDistanceMap
 *
 * @param placeDistanceMap the map containing the distance to all
 *                         places from the last position of the measurement
 * @return the minimum entry of the placeDistanceMap
 *//*from w  ww . ja  va  2  s  . co m*/
public static Map.Entry<String, Double> minMapValue(HashMap<String, Double> placeDistanceMap) {
    Map.Entry<String, Double> min = null;
    if (placeDistanceMap != null) {
        for (Map.Entry<String, Double> entry : placeDistanceMap.entrySet()) {
            if (min == null || min.getValue() > entry.getValue()) {
                if (entry.getValue() != 0) {
                    min = entry;
                }
            }

        }
    }
    return min;
}

From source file:com.surfs.nas.sql.ErrorCodeSupport.java

/**
 *
 * @param code_map//from   www.j  ava  2s  .  co m
 * @param code
 * @return int
 */
private static int getExceptionType(HashMap<Integer, Integer[]> code_map, int code) {
    for (Map.Entry<Integer, Integer[]> entry : code_map.entrySet()) {
        Integer[] codes = entry.getValue();
        if (ArrayUtils.contains(codes, code)) {
            return entry.getKey();
        }
    }
    return SortedSQLException.UncategorizedException;
}

From source file:frequencyassignment.charts.Charts.java

public static void displayBarChart(String name, HashMap<Integer, Integer> categoryValue) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Map.Entry<Integer, Integer> entry : categoryValue.entrySet()) {
        dataset.addValue(entry.getValue(), name, entry.getKey());
    }/*from   w w w . ja  va 2 s  . c om*/
    JFreeChart chart = ChartFactory.createBarChart("Bar Chart", "Category", "Value", dataset);
    ChartFrame frame = new ChartFrame(name, chart);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static ContentValues getContentValuesFromWeatherDataMap(HashMap<String, String> weatherDataMap) {
    if (weatherDataMap == null)
        return null;
    ContentValues contentValues = new ContentValues();
    for (Map.Entry<String, String> entry : weatherDataMap.entrySet()) {
        contentValues.put(entry.getKey(), entry.getValue());
    }//w  w w .j a v a  2  s  . c  o  m
    return contentValues;
}

From source file:Main.java

public static Bundle convertHashMapToBundle(HashMap<String, String> properties) {
    if (properties == null) {
        return null;
    }/*from   w  ww . ja  v a 2  s. c o m*/
    Bundle result = new Bundle();
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        result.putString(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:Main.java

public static String customrequestget(String url, HashMap<String, String> map, String method) {

    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();
            }/*w  w w  . j a  va2  s . c om*/

            i++;
        }
    }
    try {

        URL murl = new URL(url);
        System.out.print(url);
        HttpURLConnection conn = (HttpURLConnection) murl.openConnection();
        conn.setConnectTimeout(5 * 1000);
        conn.setRequestMethod(method);

        conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows XP; DigExt)");

        InputStream inStream = conn.getInputStream();
        String result = inputStream2String(inStream);
        conn.disconnect();
        return result;
    } catch (Exception e) {
        // TODO: handle exception
    }
    return null;
}

From source file:Main.java

private static String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {
    StringBuilder result = new StringBuilder();
    boolean first = true;
    for (Map.Entry<String, String> entry : params.entrySet()) {
        if (first)
            first = false;/*from  w  w  w.  jav  a2s .  co m*/
        else
            result.append("&");

        result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
        result.append("=");
        result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
    }

    return result.toString();
}

From source file:Main.java

public static String buildEncodedQueryString(HashMap<String, String> requestParams) {
    String queryString = "?";
    if (requestParams == null) {
        return null;
    }//  www . j av a 2  s.  c o m
    Iterator<Entry<String, String>> it = requestParams.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
        try {
            queryString += URLEncoder.encode(pairs.getKey().toString(), "UTF-8") + "="
                    + URLEncoder.encode(pairs.getValue().toString(), "UTF-8") + "&";
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (queryString.length() > 0)
        queryString = queryString.substring(0, queryString.length() - 1);
    return queryString;
}