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:com.pinterest.deployservice.common.CommonUtils.java

public static Map<String, String> encodeScript(Map<String, String> data) throws Exception {
    Map<String, String> encoded = new HashMap<String, String>(data.size());
    for (Map.Entry<String, String> entry : data.entrySet()) {
        encoded.put(entry.getKey(), Base64.encodeBase64URLSafeString(entry.getValue().getBytes("UTF8")));
    }/*ww w.  j a  v a 2  s.  c o  m*/
    return encoded;
}

From source file:com.pinterest.deployservice.common.CommonUtils.java

public static Map<String, String> decodeScript(Map<String, String> data) throws Exception {
    Map<String, String> decoded = new HashMap<String, String>(data.size());
    for (Map.Entry<String, String> entry : data.entrySet()) {
        decoded.put(entry.getKey(), new String(Base64.decodeBase64(entry.getValue().getBytes("UTF8")), "UTF8"));
    }/* ww w . j a v a  2  s . c  o m*/
    return decoded;
}

From source file:Main.java

/**
 * Combines 2 maps by just adding the values of the same key together.
 *
 * @param a A map//  w w w.  j  ava 2s. c o  m
 * @param b Another map
 * @param combiner The combiner of the values
 * @param <K> The type of the keys
 * @param <V> The type of the values
 *
 * @return a map that contains all the key of map a and b and the combined values.
 */
public static <K, V> Map<K, V> combine(Map<? extends K, ? extends V> a, Map<? extends K, ? extends V> b,
        BinaryOperator<V> combiner) {
    Map<K, V> result = new HashMap<>();

    for (Entry<? extends K, ? extends V> entry : a.entrySet()) {
        if (b.containsKey(entry.getKey()))
            result.put(entry.getKey(), combiner.apply(entry.getValue(), b.get(entry.getKey())));
        else
            result.put(entry.getKey(), entry.getValue());
    }

    b.entrySet().stream().filter(e -> !result.containsKey(e.getKey()))
            .forEach(e -> result.put(e.getKey(), e.getValue()));

    return result;
}

From source file:com.epam.wilma.service.util.UrlBuilderUtils.java

private static void appendParams(StringBuilder url, Map<String, String> params) {
    if (isNotEmpty(params)) {
        String separator = QUESTION_MARK;
        for (Entry<String, String> entry : params.entrySet()) {
            appendParam(url, separator, entry.getKey(), entry.getValue());
            separator = AMPERSAND;//from   w w w.ja v a 2s  . com
        }
    }
}

From source file:com.hp.test.framework.model.testcasegen.MaptoXML.java

public static String toXML(Map<String, String> map, String root) {
    String value;/*from   w  w  w. j  a va2  s.  c  o m*/
    StringBuilder sb = new StringBuilder("<");
    sb.append(root);
    sb.append(">");

    for (Map.Entry<String, String> e : map.entrySet()) {
        sb.append("<");
        sb.append(e.getKey());
        sb.append(">");
        value = StringEscapeUtils.escapeXml(e.getValue());

        //sb.append(e.getValue());
        sb.append(value);

        sb.append("</");
        sb.append(e.getKey());
        sb.append(">");
    }

    sb.append("</");
    sb.append(root);
    sb.append(">");

    return sb.toString();
}

From source file:info.mikaelsvensson.devtools.analysis.db2eventlog.Db2EventLogReportGenerator.java

private static String toString(Map<String, MutableLong> operationsTime) {
    String str = null;/*from w  w w . j a v  a 2  s. c o m*/
    for (Map.Entry<String, MutableLong> entry : operationsTime.entrySet()) {
        str = (str == null ? "" : str + ", ") + entry.getKey() + ": "
                + toDisplayTime(entry.getValue().longValue());
    }
    return str;
}

From source file:AIR.Common.Web.WebValueCollectionCorrect.java

public static WebValueCollectionCorrect getInstanceFromString(String strn, boolean urlEncoded) {
    if (StringUtils.isEmpty(strn))
        return null;
    try {//from  w  ww. j  ava 2s  .c om
        if (urlEncoded)
            strn = UrlEncoderDecoderUtils.decode(strn);
        Map<Object, Object> o = JsonHelper.deserialize(strn, Map.class);

        WebValueCollectionCorrect collection = new WebValueCollectionCorrect();
        for (Map.Entry<Object, Object> entry : o.entrySet()) {
            collection.put(entry.getKey().toString(), entry.getValue());
        }
        return collection;
    } catch (Exception exp) {
        throw new RuntimeException(exp);
    }
}

From source file:com.liferay.apio.architect.internal.body.MultipartToBodyConverter.java

private static <T> Map<String, List<T>> _flattenMap(Map<String, Map<Integer, T>> indexedValueLists) {

    Set<Entry<String, Map<Integer, T>>> entries = indexedValueLists.entrySet();

    Stream<Entry<String, Map<Integer, T>>> stream = entries.stream();

    return stream.collect(Collectors.toMap(Entry::getKey, v -> {
        Map<Integer, T> map = v.getValue();

        return new ArrayList<>(map.values());
    }));//from  w ww.j a v a  2s  . com
}

From source file:edu.purdue.cybercenter.dm.util.Helper.java

/**
 * merge two maps recursively/*from  www  .  j  a  va  2s  .  c  o m*/
 *
 * @param map1: the map to be merged to
 * @param map2: the map to be merged
 * @return the merged map
 */
public static Map<String, Object> mergeMaps(Map<String, Object> map1, Map<String, Object> map2) {
    if (map2 != null) {
        for (Map.Entry<String, Object> entry2 : map2.entrySet()) {
            String key2 = entry2.getKey();
            Object value1 = map1.get(key2);
            Object value2 = entry2.getValue();
            if (value1 == null) {
                map1.put(key2, value2);
            } else if (value2 == null) {
                if (value1 instanceof Map) {
                    // ignore merge null into composite type
                } else {
                    // merge null into primitive type
                    map1.put(key2, value2);
                }
            } else if (!(value1 instanceof Map) || !(value2 instanceof Map)) {
                map1.put(key2, value2);
            } else {
                mergeMaps((Map) value1, (Map) value2);
            }
        }
    }
    return map1;
}