-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
73 lines (50 loc) · 2.08 KB
/
Main.java
File metadata and controls
73 lines (50 loc) · 2.08 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.dj;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
class PlainOld{
private static int last_id = 1;
private int id;
public PlainOld() {
id = PlainOld.last_id++;
System.out.println("Creating a PlainOld Object: id = " + id);
}
}
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>(List.of(
"Anna", "Bob", "Chuck", "Dave"));
list.forEach(System.out::println);
calculator(Integer::sum, 10, 25);
calculator(Double::sum, 2.5, 7.5);
Supplier<PlainOld> reference1 = PlainOld::new;
PlainOld newPojo = reference1.get();
System.out.println("Getting Array");
PlainOld[] pojo1 = seedArray(PlainOld::new,10);
calculator((s1, s2) -> s1 + s2, "Hello ","World");
calculator((s1, s2) -> s1.concat(s2), "Hello ","World");
BinaryOperator<String> b1 = (s1, s2) -> s1.concat(s2);
BiFunction<String, String, String> b2 = (s1, s2) -> s1.concat(s2);
UnaryOperator<String> u1 = String::toUpperCase;
System.out.println(b1.apply("Hello ", "World"));
System.out.println(b2.apply("Hello ", "World"));
System.out.println(u1.apply("Hello "));
String result = "Hello".transform(u1);
System.out.println("Result = " + result);
result = result.transform(String::toLowerCase);
System.out.println("Result = " + result);
Function<String, Boolean> f0 = String:: isEmpty;
boolean resultBoolean = result.transform(f0);
System.out.println("Result = " + resultBoolean);
}
private static <T> void calculator(BinaryOperator<T> function, T value1, T value2){
T result = function.apply(value1, value2);
System.out.println("Result of operation:" + result);
}
private static PlainOld[] seedArray(Supplier<PlainOld> reference, int count){
PlainOld[] array = new PlainOld[count];
Arrays.setAll(array, i -> reference.get());
return array;
}
}