Example usage for java.util.concurrent ConcurrentHashMap reduceEntries

List of usage examples for java.util.concurrent ConcurrentHashMap reduceEntries

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap reduceEntries.

Prototype

public Map.Entry<K, V> reduceEntries(long parallelismThreshold,
        BiFunction<Map.Entry<K, V>, Map.Entry<K, V>, ? extends Map.Entry<K, V>> reducer) 

Source Link

Document

Returns the result of accumulating all entries using the given reducer to combine values, or null if none.

Usage

From source file:Main.java

public static <K, V extends Comparable> K getKeyOfMaxValue(ConcurrentHashMap<K, V> map) {
    Map.Entry<K, V> entry = map.reduceEntries(1000, (oldEntry, newEntry) -> {
        if (oldEntry.getValue().compareTo(newEntry.getValue()) > 0)
            return oldEntry;
        else/*w w w  .j av a 2 s .c om*/
            return newEntry;
    });
    return entry.getKey();
}