1
2
3
4
5
6
7
8
9
10
11
12
13 package com.puppycrawl.tools.checkstyle.checks.coding.hiddenfield;
14
15 import java.lang.Integer;
16 import java.util.Arrays;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Optional;
21
22
23 public class InputHiddenFieldLambdas {
24
25
26
27
28 List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
29 Integer value = new Integer(1);
30 {
31 numbers.forEach((Integer value) -> String.valueOf(value));
32 }
33
34
35
36
37
38
39 static List<String> firstNames = Arrays.asList("Andrei", "Michal", "Roman", "Vladislav");
40 String name = new String();
41 static {
42 firstNames.forEach((String name) -> String.valueOf(name));
43 }
44
45
46
47
48
49
50 static List<String> carBrands = Arrays.asList("BMW", "Mazda", "Volkswagen");
51 String brand = new String();
52 static {
53 carBrands.forEach(brand -> String.valueOf(brand));
54 }
55
56
57
58
59
60 static List<String> languageCodes = Arrays.asList("de", "ja", "fr", "pt");
61 static String languageCode = new String();
62 {
63 languageCodes.forEach(languageCode -> String.valueOf(languageCode));
64 }
65
66
67
68
69
70 int number = 1;
71 Optional<Object> foo1(int i) {
72 return Optional.of(5).map(number -> {
73 if (number == 1) return true;
74 else if (number == 2) return true;
75 else return false;
76 });
77 }
78
79
80
81
82
83 static long id = 1;
84 Optional<Object> foo2(int i) {
85 return Optional.of(5).map(id -> {
86 if (id == 1) return true;
87 else if (id == 2) return true;
88 else return false;
89 });
90 }
91
92
93
94
95
96
97 int age = 21;
98 static Optional<Object> foo3(int i) {
99 return Optional.of(5).map(age -> {
100 if (age == 1) return true;
101 else if (age == 2) return true;
102 else return false;
103 });
104 }
105
106
107
108
109
110 static String note = new String();
111 private void foo4() {
112 List<String> acceptableNotes = Arrays.asList("C", "D", "E", "F", "G", "A", "B");
113 acceptableNotes.forEach(note -> String.valueOf(note));
114 }
115
116
117
118
119
120
121 String letter = new String("a");
122 private static void foo5() {
123 List<String> acceptableAlphabet = Arrays.asList("a", "b", "c");
124 acceptableAlphabet.forEach(letter -> String.valueOf(letter));
125 }
126
127 @FunctionalInterface
128 interface Function <A, B> {
129 public B apply (A a, B b);
130 }
131
132
133
134
135 String stringValue = "248.3";
136 int intValue = 2;
137 {
138 Function <String, Integer> m = (String stringValue, Integer intValue) -> {
139 return Integer.parseInt(stringValue) + intValue;
140 };
141 String.valueOf(m.apply ("22.4", 2));
142 }
143
144
145
146
147 Double doubleValue = 8.5;
148 {
149 Function <Integer, Double> a =(Integer integerValue, Double doubleValue) -> {
150 return integerValue + doubleValue;
151 };
152 String.valueOf(a.apply(2, 2.2));
153 }
154
155
156
157
158 String firstString = "Hello,";
159 String secondString = " World!";
160 {
161 Function <String, String> stringConcat = (firstString, secondString) -> {
162 return firstString + secondString;
163 };
164 String.valueOf(stringConcat.apply("A", "B"));
165 }
166
167 @FunctionalInterface
168 interface SomeFunction<One, Two> {
169 public Two apply(One one, Two two);
170 }
171
172
173
174
175 Integer first = 1;
176 {
177 Function<Integer, Character> turnToZ = (first, second) -> 'z';
178 }
179
180 @FunctionalInterface
181 public interface Foo {
182 public String apply();
183 }
184
185
186
187
188 {
189 Foo foo = () -> "";
190 }
191 @FunctionalInterface
192 interface FunctionWithOneParameter<One> {
193 public One apply(One one);
194 }
195
196
197
198
199 Double mPi = Math.PI;
200 List<Double> simpleNumbers = Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
201 {
202 simpleNumbers.forEach(digit -> {
203 FunctionWithOneParameter<Double> strangeAdder = (mPi -> mPi+= digit);
204 });
205 }
206
207 @FunctionalInterface
208 interface FunctionWithComplexGenerics<One, Two> {
209 public Two foo(One one, Two two);
210 }
211
212
213
214
215 List<Double> justSomeList;
216 Map<String, Object> justSomeMap;
217 {
218 FunctionWithComplexGenerics<List<Double>, Map<String, Object>> someWierdFunc =
219 (List<Double> justSomeList, Map<String, Object> justSomeMap) -> {
220 String.valueOf(justSomeList);
221 String.valueOf(justSomeMap);
222 return new HashMap<>();
223 };
224 }
225
226
227
228
229
230 Object someObject = new Object();
231 FunctionWithOneParameter objectToString = (Object someObject) -> {
232 return someObject.toString();
233 };
234
235
236
237
238
239 FunctionWithOneParameter otherObjectToString = someObject -> {
240 return someObject.toString();
241 };
242
243 private final String l = "";
244 private interface NestedInterface {
245 void print(String l);
246 }
247 }