Example usage for java.util Map entrySet

List of usage examples for java.util Map entrySet

Introduction

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

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:edu.coeia.charts.PieChartPanel.java

private static PieDataset createSampleDataset(final Map<String, Double> map, int factor) {
    final DefaultPieDataset result = new DefaultPieDataset();

    Set set = map.entrySet();
    Iterator itr = set.iterator();

    while (itr.hasNext()) {
        Map.Entry me = (Map.Entry) itr.next();

        String str = me.getValue().toString();
        double counts = Double.valueOf(str).doubleValue();

        if (counts < factor)
            continue;

        double per = (counts / map.size()) * 100;

        result.setValue((String) me.getKey(), per);
    }// ww w  . j  av  a 2 s. c  o m

    return result;
}

From source file:net.logstash.logback.composite.JsonWritingUtils.java

/**
 * Writes entries of the map as fields./*from w  w  w .  j a v  a2 s. com*/
 */
public static void writeMapEntries(JsonGenerator generator, Map<?, ?> map)
        throws IOException, JsonMappingException {
    if (map != null) {
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            if (entry.getKey() != null && entry.getValue() != null) {
                generator.writeFieldName(entry.getKey().toString());
                generator.writeObject(entry.getValue());
            }
        }
    }
}

From source file:ar.com.zauber.commons.facebook.utils.impl.DefaultCallbackRequestValidator.java

/**
 * @param request//from  w w  w.ja  v  a  2  s .c  o m
 * @return
 */
public static Map<String, String> extractFacebookParams(final HttpServletRequest request) {
    final Map<String, String> params = new HashMap<String, String>();
    final Map tmp = FacebookSignatureUtil.extractFacebookNamespaceParams(request.getParameterMap());
    Set<Entry<String, Object>> s = tmp.entrySet();
    // el jetty pasa los parametros como arreglos. y facebook no se la banca
    for (final Entry<String, Object> entry : s) {
        if (entry.getValue().getClass().isArray()) {
            params.put(entry.getKey(), ((String[]) entry.getValue())[0]);
        } else {
            params.put(entry.getKey(), entry.getKey());
        }
    }
    return params;
}

From source file:Main.java

public static void divideBigDecimalsInMap(Map<String, Object> baseMap, BigDecimal divisor) {
    if (baseMap == null || divisor == null || divisor.doubleValue() == 0.0)
        return;//from ww w . j av  a 2 s  .  c om
    for (Map.Entry<String, Object> entry : baseMap.entrySet()) {
        if (!(entry.getValue() instanceof BigDecimal))
            continue;
        BigDecimal baseVal = (BigDecimal) entry.getValue();
        entry.setValue(baseVal.divide(divisor, BigDecimal.ROUND_HALF_UP));
    }
}

From source file:com.netsteadfast.greenstep.util.ExportData2CsvUtils.java

private static String processCsvText(ExportDataConfig config, NamedParameterJdbcTemplate jdbcTemplate,
        Map<String, Object> sqlParamMap) throws Exception {
    logger.info("export-Id: " + config.getId() + " name: " + config.getName());
    StringBuilder out = new StringBuilder();
    out.append(config.getTitle()).append("\r\n");
    List<Map<String, Object>> results = jdbcTemplate.queryForList(config.getSql(), sqlParamMap);
    for (int i = 0; results != null && i < results.size(); i++) {
        Map<String, Object> dataMap = results.get(i);
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            if (entry.getValue() != null) {
                String str = "";
                if (entry.getValue() instanceof byte[]) { // blob text
                    str = new String((byte[]) entry.getValue(), Constants.BASE_ENCODING);
                } else {
                    str = String.valueOf(entry.getValue());
                }//from   w w w .  ja  v a 2 s  .  c o m
                if (config.isEscapeCsv()) {
                    //str = StringEscapeUtils.escapeCsv(str);
                    str = SimpleUtils.escapeCsv(str);
                }
                if (StringUtils.isBlank(str)) {
                    str = " ";
                }
                out.append("\"").append(str).append("\"");
            } else {
                out.append(" ");
            }
            out.append(config.getSeparateSymbol());
        }
        out.append("\r\n");
    }
    return out.toString();
}

From source file:Main.java

public static String mapToQueryString(Map<String, String> map) {
    StringBuilder string = new StringBuilder();

    if (map.size() > 0) {
        string.append("?");
    }/*from   ww w. j  ava 2s  . c  o  m*/

    for (Map.Entry<String, String> entry : map.entrySet()) {
        string.append(entry.getKey());
        string.append("=");
        string.append(entry.getValue());
        string.append("&");
    }

    return string.toString();
}

From source file:Main.java

/**
 *
 * @param input map to reverse/*  w  ww  . j av  a  2 s  .c o  m*/
 * @param <T> type of map and collection
 * @return reversed map with value sets switched with key sets.
 */
public static <T> Map<T, HashSet<T>> reverseMap(Map<T, ? extends Collection<T>> input) {

    Map<T, HashSet<T>> ret = new HashMap<T, HashSet<T>>();

    for (Map.Entry<T, ? extends Collection<T>> entry : input.entrySet()) {

        final Collection<T> values = entry.getValue();
        final T key = entry.getKey();

        //foreach value in key->values mapping
        for (T value : values) {

            //get the reversed collection created when previously iterated keys
            // were associated with this value, value -> keys
            HashSet<T> newValues = ret.get(value);

            //if we've never processed a key that pointed to this value -
            // it's time to initialize the reversed collection from this value to keys that pointed to it
            if (newValues == null) {

                newValues = new HashSet<T>();
                ret.put(value, newValues);
            }

            //and obviously put the key in the reversed collection
            newValues.add(key);
        }
    }

    return ret;
}

From source file:Main.java

public static <G> Map<String, G> transferRootNameMap(Map<Integer, Integer> rootIdIdMap,
        Map<Integer, G> idValueMap, G defaultValue) {
    Map<String, G> rootValueMap = new LinkedHashMap<String, G>();
    for (Entry<Integer, Integer> entry : rootIdIdMap.entrySet()) {
        if (idValueMap.containsKey(entry.getValue())) {
            rootValueMap.put(entry.getKey().toString(), idValueMap.get(entry.getValue()));
        } else {/*  ww  w  . j  ava  2 s .c o m*/
            rootValueMap.put(entry.getKey().toString(), defaultValue);
        }
    }
    return rootValueMap;
}

From source file:com.vincestyling.netroid.stack.HttpClientStack.java

private static void addHeaders(HttpUriRequest httpRequest, Map<String, String> headers) {
    for (Entry<String, String> header : headers.entrySet()) {
        httpRequest.setHeader(header.getKey(), header.getValue());
    }/* w  w  w  .ja v  a  2 s . co  m*/
}

From source file:com.hisuntech.ArchOnlineSchoolAuth.test.aop.MyTest.java

/**
  * MAP??NameValuePair//from w w w.j a  va 2 s .  c om
  * @param properties  MAP
  * @return NameValuePair
  */
private static NameValuePair[] generatNameValuePair(Map<String, String> properties) {
    NameValuePair[] nameValuePair = new NameValuePair[properties.size()];
    int i = 0;
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        nameValuePair[i++] = new NameValuePair(entry.getKey(), entry.getValue());
    }

    return nameValuePair;
}