-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcurrentHashMapMethods17.java
35 lines (29 loc) · 1.37 KB
/
ConcurrentHashMapMethods17.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentHashMapMethods17 {
public static void main(String[] args) throws Exception {
//reduceEntriesToDouble(long parallelismThreshold, ToDoubleFunction<Map.Entry<K,V>> transformer, double basis, DoubleBinaryOperator reducer)
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("one", "1");
map.put("two", "2");
map.put("three", "3");
map.put("four", "4");
System.out.println("Map:" + map);
double result = map.reduceEntriesToDouble(2, (entry) -> {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
return Double.parseDouble(entry.getValue());
}, 0, (a, b) -> {
System.out.println("Value1:" + a + " Value2:" + b);
return a + b;
});
System.out.println("Result:" + result);
System.out.println(" ");
double result2 = map.reduceEntriesToDouble(2, (entry) -> {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
return Double.parseDouble(entry.getValue());
}, 1, (a, b) -> {
System.out.println("Value1:" + a + " Value2:" + b);
return a + b;
});
System.out.println("Result:" + result2);
}
}