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

public static <K, V> HashMap<V, K> invert(Map<K, V> in) {
    HashMap<V, K> result = new HashMap<V, K>();
    for (Map.Entry<K, V> e : in.entrySet()) {
        result.put(e.getValue(), e.getKey());
    }/*from  w w  w .jav  a  2 s. co  m*/
    return result;
}

From source file:Main.java

public static Integer getKeyByValue(Map<Integer, String> map, Object value) {
    Integer key = -1;//from  w  ww.  j a va2  s.c  o m
    Iterator<Entry<Integer, String>> it = map.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Integer, String> entry = (Entry<Integer, String>) it.next();
        String obj = entry.getValue();
        if (obj != null && obj.equals(value)) {
            // break as find the first key, assuming key and value are one-to-one
            key = (Integer) entry.getKey();
            break;
        }
    }
    return key;
}

From source file:Main.java

public static String mapToString(Map<String, String> paramMap) {
    String paramsStr = "";
    Iterator<Map.Entry<String, String>> entries = paramMap.entrySet().iterator();

    while (entries.hasNext()) {
        Map.Entry<String, String> entry = entries.next();

        paramsStr += "&";
        paramsStr += entry.getKey() + "=" + entry.getValue();
    }/* w  ww .  j a v a2 s .com*/
    return paramsStr;
}

From source file:ee.ria.xroad.common.message.MultipartSoapMessageEncoder.java

private static String[] convertHeaders(Map<String, String> headers) {
    return headers.entrySet().stream().map(e -> e.getKey() + ": " + e.getValue()).collect(Collectors.toList())
            .toArray(new String[] {});
}

From source file:eu.openg.aws.s3.internal.FakeS3Object.java

private static Map<String, String> serializeUserMetadata(Map<String, String> metadata) {
    return metadata.entrySet().stream()
            .collect(Collectors.toMap(entry -> entry.getKey().toLowerCase(), Map.Entry::getValue));
}

From source file:Main.java

public static void printMapList(List<Map> list) {
    Map map = null;
    for (int i = 0; i < list.size(); i++) {
        map = list.get(i);//www .j a v  a 2 s  .c o  m
        Iterator iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}

From source file:Main.java

public static <K, V> Map<K, V> sortMapByKey(Map<K, V> map, final Boolean asc) {
    List<Entry<K, V>> entries = new LinkedList<Entry<K, V>>(map.entrySet());
    Collections.sort(entries, new Comparator<Entry<K, V>>() {
        @SuppressWarnings("unchecked")
        public int compare(Entry<K, V> o1, Entry<K, V> o2) {
            if (asc) {
                return ((Comparable<K>) o1.getKey()).compareTo(o2.getKey());
            } else {
                return -((Comparable<K>) o1.getKey()).compareTo(o2.getKey());
            }/* w  w  w  .  ja  v  a 2s .  c o  m*/
        }
    });

    Map<K, V> result = new LinkedHashMap<K, V>();
    for (Entry<K, V> entry : entries) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:Main.java

public static <K, V> Map<K, V> sortMapByValue(Map<K, V> map, final Boolean asc) {
    List<Entry<K, V>> entries = new LinkedList<Entry<K, V>>(map.entrySet());
    Collections.sort(entries, new Comparator<Entry<K, V>>() {
        @SuppressWarnings("unchecked")
        public int compare(Entry<K, V> o1, Entry<K, V> o2) {
            if (asc) {
                return ((Comparable<V>) o1.getValue()).compareTo(o2.getValue());
            } else {
                return -((Comparable<V>) o1.getValue()).compareTo(o2.getValue());
            }//from   ww w .  ja  v  a  2s  .  com
        }
    });

    Map<K, V> result = new LinkedHashMap<K, V>();
    for (Entry<K, V> entry : entries) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:com.adeptj.runtime.server.IdentityManagers.java

static boolean verifyAccount(Map<String, List<String>> userRolesMapping, Account account) {
    return userRolesMapping.entrySet().stream()
            .anyMatch(entry -> StringUtils.equals(entry.getKey(), account.getPrincipal().getName())
                    && entry.getValue().containsAll(account.getRoles()));
}

From source file:io.adeptj.runtime.server.IdmUtil.java

static Account verifyAccount(Map<String, List<String>> userRolesMapping, Account account) {
    return userRolesMapping.entrySet().stream()
            .anyMatch(entry -> StringUtils.equals(entry.getKey(), account.getPrincipal().getName())
                    && entry.getValue().containsAll(account.getRoles())) ? account : null;
}