Java Code Examples for java.util.concurrent.ConcurrentHashMap.reduceKeysToDouble()

The following are Jave code examples for showing how to use reduceKeysToDouble() of the java.util.concurrent.ConcurrentHashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 5 votes
/**
 * reduceKeysToDoubleSequentially accumulates mapped keys
 */
public void testReduceKeysToDoubleSequentially() {
    ConcurrentHashMap<Long, Long> m = longMap();
    double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
    assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
}
 
Example 2
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 5 votes
/**
 * reduceKeysToDoubleInParallel accumulates mapped values
 */
public void testReduceKeysToDoubleInParallel() {
    ConcurrentHashMap<Long, Long> m = longMap();
    double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
    assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
}