Skip to content

Commit 11c5cac

Browse files
Add files via upload
1 parent eb5d63d commit 11c5cac

9 files changed

+217
-0
lines changed

ConcurrentHashMapMethods24.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
3+
public class ConcurrentHashMapMethods24 {
4+
5+
//reduceKeysToLong​(long parallelismThreshold, ToLongFunction<? super K> transformer, long basis, LongBinaryOperator reducer)
6+
public static void main(String[] args) throws Exception {
7+
8+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
9+
map.put(1, "1");
10+
map.put(2, "2");
11+
map.put(3, "3");
12+
map.put(4, "4");
13+
System.out.println("Map:" + map);
14+
15+
long result = map.reduceKeysToLong(2, k -> {
16+
System.out.println("Key:" + k);
17+
return k;
18+
}, 1, (k1, k2) -> {
19+
System.out.println("Key1:" + k1 + " Key2:" + k2);
20+
return k1 + k2;
21+
});
22+
System.out.println("Result:" + result);
23+
24+
}
25+
}

ConcurrentHashMapMethods25.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
public class ConcurrentHashMapMethods25 {
3+
4+
//reduceToDouble​(long parallelismThreshold, ToDoubleBiFunction<? super K,​? super V> transformer, double basis, DoubleBinaryOperator reducer)
5+
public static void main(String[] args) throws Exception {
6+
7+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
8+
map.put(1, "1");
9+
map.put(2, "2");
10+
map.put(3, "3");
11+
map.put(4, "4");
12+
System.out.println("Map:" + map);
13+
14+
double result = map.reduceToDouble(2, (k, v) -> {
15+
System.out.println("Key:" + k + " Value:" + v);
16+
return Double.parseDouble(v);
17+
}, 2, (v1, v2) -> {
18+
System.out.println("Value1:" + v1 + " Value2:" + v2);
19+
return v1 + v2;
20+
});
21+
System.out.println("Result:" + result);
22+
23+
}
24+
}

ConcurrentHashMapMethods26.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
3+
public class ConcurrentHashMapMethods26 {
4+
//reduceToInt​(long parallelismThreshold, ToIntBiFunction<? super K,​? super V> transformer, int basis, IntBinaryOperator reducer)
5+
public static void main(String[] args) throws Exception {
6+
7+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
8+
map.put(1, "1");
9+
map.put(2, "2");
10+
map.put(3, "3");
11+
map.put(4, "4");
12+
System.out.println("Map:" + map);
13+
14+
int result = map.reduceToInt(2, (k, v) -> {
15+
System.out.println("Key:" + k + " Value:" + v);
16+
return Integer.parseInt(v);
17+
}, 0, (v1, v2) -> {
18+
System.out.println("Value1:" + v1 + " Value2:" + v2);
19+
return v1 + v2;
20+
});
21+
System.out.println("Result:" + result);
22+
}
23+
}

ConcurrentHashMapMethods27.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
3+
public class ConcurrentHashMapMethods27 {
4+
// reduceToLong​(long parallelismThreshold, ToLongBiFunction<? super K,​? super V> transformer, long basis, LongBinaryOperator reducer)
5+
6+
public static void main(String[] args) throws Exception {
7+
8+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
9+
map.put(1, "1");
10+
map.put(2, "2");
11+
map.put(3, "3");
12+
map.put(4, "4");
13+
System.out.println("Map:" + map);
14+
15+
long result = map.reduceToLong(2, (k, v) -> {
16+
System.out.println("Key:" + k + " Value:" + v);
17+
return Long.parseLong(v);
18+
}, 1, (k1, k2) -> {
19+
System.out.println("Key1:" + k1 + " Key2:" + k2);
20+
return k1 + k2;
21+
});
22+
System.out.println("Result:" + result);
23+
24+
}
25+
26+
}

ConcurrentHashMapMethods28.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
public class ConcurrentHashMapMethods28 {
3+
4+
//reduceValues​(long parallelismThreshold, BiFunction<? super V,​? super V,​? extends V> reducer)
5+
6+
public static void main(String[] args) throws Exception {
7+
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
8+
map.put("one", "1");
9+
map.put("two", "2");
10+
map.put("three", "3");
11+
map.put("four", "4");
12+
System.out.println("Map:" + map);
13+
14+
String result = map.reduceValues(2, (v1, v2) -> {
15+
System.out.println("Value1:" + v1 + " Value2:" + v2);
16+
return v1 + v2;
17+
});
18+
System.out.println("Result:" + result);
19+
}
20+
21+
}

ConcurrentHashMapMethods29.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
public class ConcurrentHashMapMethods29 {
3+
4+
//reduceValues​(long parallelismThreshold, Function<? super V,​? extends U> transformer, BiFunction<? super U,​? super U,​? extends U> reducer)
5+
6+
public static void main(String[] args) throws Exception {
7+
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
8+
map.put("one", "1");
9+
map.put("two", "2");
10+
map.put("three", "3");
11+
map.put("four", "4");
12+
System.out.println("Map:" + map);
13+
14+
String result = map.reduceValues(2, v -> {
15+
System.out.println("Value:" + v);
16+
return v;
17+
}, (v1, v2) -> {
18+
System.out.println("Value1:" + v1 + " Value2:" + v2);
19+
return v1 + v2;
20+
});
21+
System.out.println("Result:" + result);
22+
}
23+
}

ConcurrentHashMapMethods30.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
3+
public class ConcurrentHashMapMethods30 {
4+
5+
//reduceValuesToDouble​(long parallelismThreshold, ToDoubleFunction<? super V> transformer, double basis, DoubleBinaryOperator reducer)
6+
7+
public static void main(String[] args) throws Exception {
8+
9+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
10+
map.put(1, "1");
11+
map.put(2, "2");
12+
map.put(3, "3");
13+
map.put(4, "4");
14+
System.out.println("Map:" + map);
15+
16+
double result = map.reduceValuesToDouble(2, v -> {
17+
System.out.println("Value:" + v);
18+
return Double.parseDouble(v);
19+
}, 2, (v1, v2) -> {
20+
System.out.println("Value1:" + v1 + " Value2:" + v2);
21+
return v1 + v2;
22+
});
23+
System.out.println("Result:" + result);
24+
25+
}
26+
27+
}

ConcurrentHashMapMethods31.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
public class ConcurrentHashMapMethods31 {
3+
//reduceValuesToInt​(long parallelismThreshold, ToIntFunction<? super V> transformer, int basis, IntBinaryOperator reducer)
4+
5+
public static void main(String[] args) throws Exception {
6+
7+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
8+
map.put(1, "1");
9+
map.put(2, "2");
10+
map.put(3, "3");
11+
map.put(4, "4");
12+
System.out.println("Map:" + map);
13+
14+
int result = map.reduceValuesToInt(2, v -> {
15+
System.out.println("Value:" + v);
16+
return Integer.parseInt(v);
17+
}, 1, (v1, v2) -> {
18+
System.out.println("Value1:" + v1 + " Value2:" + v2);
19+
return v1 + v2;
20+
});
21+
System.out.println("Result:" + result);
22+
23+
}
24+
}

ConcurrentHashMapMethods32.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
public class ConcurrentHashMapMethods32 {
3+
//reduceValuesToLong​(long parallelismThreshold, ToLongFunction<? super V> transformer, long basis, LongBinaryOperator reducer)
4+
5+
public static void main(String[] args) throws Exception {
6+
7+
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
8+
map.put(1, "1");
9+
map.put(2, "2");
10+
map.put(3, "3");
11+
map.put(4, "4");
12+
System.out.println("Map:" + map);
13+
14+
long result = map.reduceValuesToLong(2, v -> {
15+
System.out.println("Value:" + v);
16+
return Long.parseLong(v);
17+
}, 1, (v1, v2) -> {
18+
System.out.println("Value1:" + v1 + " Value2:" + v2);
19+
return v1 + v2;
20+
});
21+
System.out.println("Result:" + result);
22+
23+
}
24+
}

0 commit comments

Comments
 (0)