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 ArrayList<Pair<String, String>> convertHeaders(Map<String, List<String>> map) {
    ArrayList<Pair<String, String>> array = new ArrayList<Pair<String, String>>();
    for (Map.Entry<String, List<String>> mapEntry : map.entrySet()) {
        for (String mapEntryValue : mapEntry.getValue()) {
            // HttpURLConnection puts a weird null entry in the header map that corresponds to
            // the HTTP response line (for instance, HTTP/1.1 200 OK).  Ignore that weirdness...
            if (mapEntry.getKey() != null) {
                array.add(Pair.create(mapEntry.getKey(), mapEntryValue));
            }//from   w  ww.jav  a 2 s .  co m
        }
    }
    return array;
}

From source file:nu.yona.server.goals.service.ActivityCategoryDto.java

private static Map<Locale, String> mapToLocaleMap(Map<String, String> localeStringMap) {
    return localeStringMap.entrySet().stream()
            .collect(Collectors.toMap(e -> Locale.forLanguageTag(e.getKey()), Map.Entry::getValue));
}

From source file:Main.java

public static <K, V> Map<V, Set<K>> invertMapOfCollection(Map<K, ? extends Collection<V>> mapOfCollection) {
    Map<V, Set<K>> result = new TreeMap<V, Set<K>>();

    for (Entry<K, ? extends Collection<V>> inputEntry : mapOfCollection.entrySet()) {
        K inputKey = inputEntry.getKey();
        Collection<V> inputCollection = inputEntry.getValue();

        for (V inputValue : inputCollection) {
            Set<K> resultSet = result.get(inputValue);
            if (resultSet == null) {
                resultSet = new TreeSet<K>();
                result.put(inputValue, resultSet);
            }/*from ww w.  jav  a2 s . c  o  m*/
            resultSet.add(inputKey);
        }
    }

    return result;
}

From source file:Main.java

/**
 * For logging.//from w w  w  .  j  a  v  a 2  s . c  om
 *
 * @param map
 * @return
 */
public static <K, V> String map2str(Map<K, V> map) {
    StringBuilder sb = new StringBuilder();
    try {
        if (!isEmpty(map)) {
            for (Map.Entry<K, V> entry : map.entrySet()) {
                String key = entry.getKey().toString();
                String val = entry.getValue().toString();
                sb.append(key).append(':').append(val).append(',');
            }
            return sb.substring(0, sb.length() - 1);
        }
    } catch (Exception e) {
    }
    return sb.toString();
}

From source file:com.palantir.atlasdb.keyvalue.impl.RowResults.java

public static <T> IterableView<RowResult<T>> viewOfMap(Map<byte[], SortedMap<byte[], T>> map) {
    return viewOfEntries(map.entrySet());
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> checkMap(Map<?, ?> map, Class<K> keyType, Class<V> valueType) {
    if (DEBUG) {//from   w ww  .  j ava 2 s .c  om
        Map<K, V> copy = new HashMap<K, V>();
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            copy.put(keyType.cast(entry.getKey()), valueType.cast(entry.getValue()));
        }
        return copy;
    }
    return (Map<K, V>) map;
}

From source file:com.intel.podm.allocation.strategy.matcher.ProcessorMatcher.java

private static boolean areMatched(List<RequestedProcessor> requestedProcessors,
        List<Processor> availableProcessors) {
    ProcessorsAllocationMapper mapper = new ProcessorsAllocationMapper();
    Map<RequestedProcessor, Processor> mappedProcessors = mapper.map(requestedProcessors,
            newArrayList(availableProcessors));
    return Objects.equals(mappedProcessors.entrySet().size(), requestedProcessors.size());
}

From source file:com.streamsets.pipeline.stage.origin.spooldir.TestOffsetUtil.java

private static Map<String, String> removeAbsolutePaths(Map<String, String> offsetV2) {
    Map<String, String> resultMap = new HashMap<>();
    for (Map.Entry<String, String> entry : offsetV2.entrySet()) {
        if (entry.getKey().contains(PATH_SEPARATOR)) {
            String filename = new StringJoiner(".").add(FilenameUtils.getBaseName(entry.getKey()))
                    .add(FilenameUtils.getExtension(entry.getKey())).toString();
            resultMap.put(filename, entry.getValue());
        } else {//w  ww. ja va  2 s.  c  om
            resultMap.put(entry.getKey(), entry.getValue());
        }
    }
    return resultMap;
}

From source file:dev.meng.wikipedia.profiler.util.StringUtils.java

public static String mapToURLParameters(Map<String, Object> params) {
    String result = "";
    Iterator it = params.entrySet().iterator();
    while (it.hasNext()) {
        try {// w  ww  .j a va 2 s.  c o m
            Map.Entry<String, Object> pair = (Map.Entry) it.next();
            result += URLEncoder.encode(pair.getKey(), "utf-8") + "="
                    + URLEncoder.encode(pair.getValue().toString(), "utf-8");
            if (it.hasNext()) {
                result += "&";
            }
        } catch (UnsupportedEncodingException ex) {
            LogHandler.console(StringUtils.class, ex);
        }
    }
    return result;
}

From source file:Main.java

public static String toString(Map<?, ?> col) {
    StringBuilder buf = new StringBuilder();
    buf.append("[");
    boolean first = true;
    for (Map.Entry<?, ?> o : col.entrySet()) {
        if (first) {
            first = false;//www  . j  a  v a2  s  . c om
        } else {
            buf.append(", ");
        }
        buf.append(o.getKey().toString()).append(" : ").append(o.getValue().toString());
    }
    buf.append("]");
    return buf.toString();
}