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