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

/**
 * Convert a map to a {@link Properties} object.
 *
 * @param map/*  www . java 2  s. c o  m*/
 *            map object
 * @return properties view of the map
 */
public static Properties asProperties(final Map<String, String> map) {
    final Properties properties = new Properties();
    for (final Map.Entry<String, String> entry : map.entrySet()) {
        properties.setProperty(entry.getKey(), entry.getValue());
    }
    return properties;

}

From source file:Main.java

public static <K, V> void putIfAbsent(Map<K, V> from, Map<K, ? super V> to) {
    if (from == null || to == null) {
        return;/*from  w  ww  .  j  a va 2 s.c o m*/
    }
    for (Entry<K, V> entry : from.entrySet()) {
        if (!to.containsKey(entry.getKey())) {
            to.put(entry.getKey(), entry.getValue());
        }
    }
}

From source file:Main.java

private static void setParameter(Map<String, String> parameter, Transformer t) {
    if (parameter != null) {
        for (Map.Entry<String, String> e : parameter.entrySet()) {
            t.setParameter(e.getKey(), e.getValue());
        }/* w  ww  .jav  a2  s . co  m*/
    }
}

From source file:Main.java

public static String buildPayload(Map<String, String> params) {
    StringBuilder bodyBuilder = new StringBuilder();
    Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, String> param = iterator.next();
        bodyBuilder.append(param.getKey()).append('=').append(param.getValue());
        if (iterator.hasNext()) {
            bodyBuilder.append('&');
        }/*from  ww  w  .  ja  va 2  s  .c o  m*/
    }

    return bodyBuilder.toString();
}

From source file:Main.java

/**
 * @param map map//w  ww.  j a  va2s .c o  m
 * @return map deep copy
 */
public static Map<String, Set<String>> cloneMap(Map<String, Set<String>> map) {
    final Map<String, Set<String>> clone = new HashMap<>(map.size());
    for (Map.Entry<String, Set<String>> entry : map.entrySet()) {
        final Set<String> cloneSet = new HashSet<>(entry.getValue());
        clone.put(entry.getKey(), cloneSet);
    }

    return clone;
}

From source file:Main.java

/**
 * Set drawables for map of views.//from   ww w  .j a va  2s  .co m
 * @param views
 * @param drawables
 * @param convert
 */
public static void setDrawables(Map<Integer, ImageView> views, Map<Integer, Drawable> drawables,
        Map<Integer, Integer> convert) {
    for (Entry<Integer, ImageView> entry : views.entrySet()) {
        Drawable drawable = drawables.get(convert.get(entry.getKey()));
        entry.getValue().setImageDrawable(drawable);
    }
}

From source file:Main.java

public static <K, V> void putIfAbsent(Map<K, V> from, Map<K, ? super V> to) {
    if (from == null || to == null) {
        return;/*from  www  . j  ava2  s. c om*/
    }
    for (Map.Entry<K, V> entry : from.entrySet()) {
        if (!to.containsKey(entry.getKey())) {
            to.put(entry.getKey(), entry.getValue());
        }
    }
}

From source file:io.gravitee.common.util.EnvironmentUtils.java

private static void addAll(Map<String, Object> aBase, Map<String, Object> aToBeAdded) {
    for (Map.Entry<String, Object> entry : aToBeAdded.entrySet()) {
        if (aBase.containsKey(entry.getKey())) {
            continue;
        }/*  w w  w  .  ja  va2 s .  co m*/

        aBase.put(entry.getKey(), entry.getValue());
    }
}

From source file:Main.java

private static Map<String, Set<String>> convertHashMapToTypeSet(Map<String, String> hashMap) {
    Map<String, Set<String>> globalVars = new HashMap<String, Set<String>>();

    for (final Map.Entry<String, String> entry : hashMap.entrySet()) {
        globalVars.put(entry.getKey(), new HashSet<String>(Arrays.asList(entry.getValue())));
    }/*from ww  w .  java  2  s  . co m*/

    return globalVars;
}

From source file:Main.java

public static void dumpAllStackTraces() {
    synchronized (System.err) {
        Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
        for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet()) {
            System.err.println("Stack Trace for " + entry.getKey().getName());
            StackTraceElement[] elements = entry.getValue();
            for (StackTraceElement element : elements) {
                System.err.println("\tat " + element.toString());
            }//  w w  w. ja  v  a 2s  .  c o  m
            System.err.println();
        }
    }
}