2
2
3
3
import com .java15 .example .modern_java_in_action .Apple ;
4
4
import com .java15 .example .modern_java_in_action .Colors ;
5
+ import com .java15 .example .modern_java_in_action .Data ;
5
6
6
7
import java .util .ArrayList ;
7
8
import java .util .Arrays ;
8
9
import java .util .Comparator ;
9
10
import java .util .List ;
10
11
import java .util .function .*;
11
12
13
+ import static java .util .Comparator .comparing ;
14
+
12
15
public class Test {
13
16
14
17
public static int staticValue = 10 ;
@@ -19,7 +22,46 @@ public static void main(String[] args) {
19
22
//extracted2();
20
23
//extracted3();
21
24
//extracted4(startsWithNumber.test("1he"));
22
- extracted5 ();
25
+ //extracted5();
26
+ //extracted6();
27
+ //extracted7();
28
+ //extracted8();
29
+ extracted9 ();
30
+ }
31
+
32
+ private static void extracted9 () {
33
+ Function <Integer , Integer > f = x -> x + 1 ;
34
+ Function <Integer , Integer > g = x -> x * 2 ;
35
+ Function <Integer , Integer > h = f .compose (g );
36
+ int result = h .apply (1 );
37
+ System .out .println (result );
38
+ }
39
+
40
+ private static void extracted8 () {
41
+ Function <Integer , Integer > f = x -> x + 1 ;
42
+ Function <Integer , Integer > g = x -> x * 2 ;
43
+ Function <Integer , Integer > h = f .andThen (g );
44
+ int result = h .apply (1 );
45
+ System .out .println (result );
46
+ }
47
+
48
+ private static void extracted7 () {
49
+ Data .getData ().stream ().filter (notRedApple ).forEach (System .out ::println );
50
+ Data .getData ().stream ().filter (redAppleWithConditions ).forEach (System .out ::println );
51
+ }
52
+
53
+ static Predicate <Apple > redApple = apple -> Colors .RED .equals (apple .getColor ());
54
+ static Predicate <Apple > notRedApple = redApple .negate ();
55
+ static Predicate <Apple > redAppleWithConditions = redApple .and (apple -> apple .getWeight ()>2 ).or (apple ->Colors .GREEN .equals (apple .getColor ()));
56
+
57
+
58
+ private static void extracted6 () {
59
+ List <Apple > list = Data .getData1 ();
60
+ list .sort (comparing (Apple ::getWeight ).reversed ());
61
+ list .forEach (System .out ::println );
62
+ System .out .println ("++++++++++++++++++++++++++++++" );
63
+ list .sort (comparing (Apple ::getColor ).thenComparing (Apple ::getWeight ));
64
+ list .forEach (System .out ::println );
23
65
}
24
66
25
67
private static void extracted5 () {
0 commit comments