forked from LuigiCortese/java-certification-ocp8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.java
155 lines (129 loc) · 3.96 KB
/
App.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package net.devsedge.functionalinterfaces.binary;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.BinaryOperator;
import java.util.function.DoubleBinaryOperator;
import java.util.function.IntBinaryOperator;
import java.util.function.LongBinaryOperator;
import java.util.function.ObjDoubleConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.ObjLongConsumer;
import java.util.function.ToDoubleBiFunction;
import java.util.function.ToIntBiFunction;
import java.util.function.ToLongBiFunction;
public class App {
public static void main(String[] args) {
/*
*
* BiPredicate
*
*/
System.out.println("'BiPredicate' takes two parameters of any type and returns a boolean");
new BiPredicate<String,Integer>(){
@Override
public boolean test(String t,Integer i) {
System.out.println("\tBiPredicate takes two parameters of any type");
return true;
}
}.test("",1);
/*
*
* BiConsumer
*
*/
System.out.println("\n'BiConsumer' takes two parameters of any type and returns any type");
new BiConsumer<String,Integer>(){
@Override
public void accept(String t,Integer i) {
System.out.println("\tBiConsumer takes any type");
}
}.accept("",1);
new ObjIntConsumer<String>(){
@Override
public void accept(String s,int t) {
System.out.println("\tObjIntConsumer takes an Object and an int");
}
}.accept("",1);
new ObjLongConsumer<String>(){
@Override
public void accept(String s,long t) {
System.out.println("\tObjLongConsumer takes an Object and a long");
}
}.accept("",1L);
new ObjDoubleConsumer<String>(){
@Override
public void accept(String s,double t) {
System.out.println("\tObjDoubleConsumer takes an Object and a double");
}
}.accept("",1D);
/*
*
* BiFunction
*
*/
System.out.println("\n'Function' takes two parameter of any type and returns any type");
new BiFunction<String,Double,Integer>(){
@Override
public Integer apply(String t,Double d) {
System.out.println("\tBiFunction takes any type and returns any type");
return 1;
}
}.apply("",1D);
new ToIntBiFunction<String,Double>(){
@Override
public int applyAsInt(String value,Double d) {
System.out.println("\tToIntFunction takes any type and returns an int");
return 0;
}
}.applyAsInt("",1D);
new ToLongBiFunction<String,Double>(){
@Override
public long applyAsLong(String value,Double d) {
System.out.println("\tToLongFunction takes any type and returns a long");
return 0L;
}
}.applyAsLong("",1D);
new ToDoubleBiFunction<String,Double>(){
@Override
public double applyAsDouble(String value,Double d) {
System.out.println("\tToDoubleFunction takes any type and returns a double");
return 0L;
}
}.applyAsDouble("",1D);
/*
*
* BinaryOperator
*
*/
System.out.println("\n'BinaryOperator' takes two objects of any type and returns the same type");
new BinaryOperator<String>(){
@Override
public String apply(String t,String s) {
System.out.println("\tBinaryOperator takes/returns any type");
return "";
}
}.apply("","");
new IntBinaryOperator(){
@Override
public int applyAsInt(int t,int u) {
System.out.println("\tIntBinaryOperator takes/returns an int");
return 1;
}
}.applyAsInt(1,2);
new LongBinaryOperator(){
@Override
public long applyAsLong(long t,long u) {
System.out.println("\tLongBinaryOperator takes/returns a long");
return 1L;
}
}.applyAsLong(1L,1L);
new DoubleBinaryOperator(){
@Override
public double applyAsDouble(double t,double u) {
System.out.println("\tDoubleBinaryOperator takes/returns a double");
return 1D;
}
}.applyAsDouble(1D,1D);
}
}