11
11
import java .util .stream .Stream ;
12
12
13
13
@ SuppressWarnings ({"IfStatementWithIdenticalBranches" , "RedundantOperationOnEmptyContainer" })
14
- public class BaseStreamExample {
14
+ public class BaseStreamExample {
15
15
Stream <Integer > returningStreamExample (List <Integer > list ) {
16
16
UtMock .assume (list != null );
17
17
@@ -23,7 +23,7 @@ Stream<Integer> returningStreamExample(List<Integer> list) {
23
23
}
24
24
25
25
@ SuppressWarnings ("Convert2MethodRef" )
26
- boolean filterExample (List <Integer > list ) {
26
+ boolean filterExample (List <Integer > list ) {
27
27
UtMock .assume (list != null && !list .isEmpty ());
28
28
29
29
int prevSize = list .size ();
@@ -33,7 +33,7 @@ boolean filterExample(List<Integer> list) {
33
33
return prevSize != newSize ;
34
34
}
35
35
36
- Integer [] mapExample (List <Integer > list ) {
36
+ Integer [] mapExample (List <Integer > list ) {
37
37
UtMock .assume (list != null && !list .isEmpty ());
38
38
39
39
return list .stream ().map (value -> value * 2 ).toArray (Integer []::new );
@@ -43,7 +43,7 @@ Integer[] mapExample(List<Integer> list) {
43
43
44
44
// TODO flatMap
45
45
46
- boolean distinctExample (List <Integer > list ) {
46
+ boolean distinctExample (List <Integer > list ) {
47
47
UtMock .assume (list != null && !list .isEmpty ());
48
48
49
49
int prevSize = list .size ();
@@ -53,7 +53,7 @@ boolean distinctExample(List<Integer> list) {
53
53
return prevSize != newSize ;
54
54
}
55
55
56
- Integer [] sortedExample (List <Integer > list ) {
56
+ Integer [] sortedExample (List <Integer > list ) {
57
57
UtMock .assume (list != null && list .size () >= 2 );
58
58
59
59
Integer first = list .get (0 );
@@ -71,7 +71,7 @@ Integer[] sortedExample(List<Integer> list) {
71
71
static int x = 0 ;
72
72
73
73
@ SuppressWarnings ("ResultOfMethodCallIgnored" )
74
- int peekExample (List <Integer > list ) {
74
+ int peekExample (List <Integer > list ) {
75
75
UtMock .assume (list != null && !list .isEmpty ());
76
76
77
77
int beforeStaticValue = x ;
@@ -82,7 +82,7 @@ int peekExample(List<Integer> list) {
82
82
}
83
83
84
84
@ SuppressWarnings ("IfStatementWithIdenticalBranches" )
85
- Integer [] limitExample (List <Integer > list ) {
85
+ Integer [] limitExample (List <Integer > list ) {
86
86
UtMock .assume (list != null && !list .isEmpty ());
87
87
88
88
if (list .size () <= 5 ) {
@@ -93,7 +93,7 @@ Integer[] limitExample(List<Integer> list) {
93
93
}
94
94
95
95
@ SuppressWarnings ("IfStatementWithIdenticalBranches" )
96
- Integer [] skipExample (List <Integer > list ) {
96
+ Integer [] skipExample (List <Integer > list ) {
97
97
UtMock .assume (list != null && !list .isEmpty ());
98
98
99
99
if (list .size () > 5 ) {
@@ -104,7 +104,7 @@ Integer[] skipExample(List<Integer> list) {
104
104
}
105
105
106
106
@ SuppressWarnings ("SimplifyStreamApiCallChains" )
107
- int forEachExample (List <Integer > list ) {
107
+ int forEachExample (List <Integer > list ) {
108
108
UtMock .assume (list != null && !list .isEmpty ());
109
109
110
110
int beforeStaticValue = x ;
@@ -115,7 +115,7 @@ int forEachExample(List<Integer> list) {
115
115
}
116
116
117
117
@ SuppressWarnings ("SimplifyStreamApiCallChains" )
118
- Object [] toArrayExample (List <Integer > list ) {
118
+ Object [] toArrayExample (List <Integer > list ) {
119
119
UtMock .assume (list != null );
120
120
121
121
int size = list .size ();
@@ -126,13 +126,13 @@ Object[] toArrayExample(List<Integer> list) {
126
126
}
127
127
}
128
128
129
- Integer reduceExample (List <Integer > list ) {
129
+ Integer reduceExample (List <Integer > list ) {
130
130
UtMock .assume (list != null );
131
131
132
132
return list .stream ().reduce (42 , this ::nullableSum );
133
133
}
134
134
135
- Optional <Integer > optionalReduceExample (List <Integer > list ) {
135
+ Optional <Integer > optionalReduceExample (List <Integer > list ) {
136
136
UtMock .assume (list != null );
137
137
138
138
int size = list .size ();
@@ -148,27 +148,35 @@ Optional<Integer> optionalReduceExample(List<Integer> list) {
148
148
return list .stream ().reduce (this ::nullableSum );
149
149
}
150
150
151
- Double complexReduceExample (List <Integer > list ) {
151
+ Double complexReduceExample (List <Integer > list ) {
152
152
UtMock .assume (list != null );
153
153
154
- return list .stream ().reduce (42.0 , (Double a , Integer b ) -> a + b .doubleValue (), Double ::sum );
154
+ if (list .isEmpty ()) {
155
+ return list .stream ().reduce (42.0 , (Double a , Integer b ) -> a + b .doubleValue (), Double ::sum );
156
+ }
157
+
158
+ return list .stream ().reduce (
159
+ 42.0 ,
160
+ (Double a , Integer b ) -> a + (b != null ? b .doubleValue () : 0.0 ),
161
+ Double ::sum
162
+ );
155
163
}
156
164
157
- Integer collectExample (List <Integer > list ) {
165
+ Integer collectExample (List <Integer > list ) {
158
166
UtMock .assume (list != null );
159
167
160
168
return list .stream ().collect (IntWrapper ::new , IntWrapper ::plus , IntWrapper ::plus ).value ;
161
169
}
162
170
163
171
@ SuppressWarnings ("SimplifyStreamApiCallChains" )
164
- Set <Integer > collectorExample (List <Integer > list ) {
172
+ Set <Integer > collectorExample (List <Integer > list ) {
165
173
UtMock .assume (list != null );
166
174
167
175
return list .stream ().collect (Collectors .toSet ());
168
176
}
169
177
170
178
@ SuppressWarnings ("RedundantOperationOnEmptyContainer" )
171
- Optional <Integer > minExample (List <Integer > list ) {
179
+ Optional <Integer > minExample (List <Integer > list ) {
172
180
UtMock .assume (list != null );
173
181
174
182
int size = list .size ();
@@ -185,7 +193,7 @@ Optional<Integer> minExample(List<Integer> list) {
185
193
}
186
194
187
195
@ SuppressWarnings ("RedundantOperationOnEmptyContainer" )
188
- Optional <Integer > maxExample (List <Integer > list ) {
196
+ Optional <Integer > maxExample (List <Integer > list ) {
189
197
UtMock .assume (list != null );
190
198
191
199
int size = list .size ();
@@ -202,7 +210,7 @@ Optional<Integer> maxExample(List<Integer> list) {
202
210
}
203
211
204
212
@ SuppressWarnings ({"ReplaceInefficientStreamCount" , "ConstantConditions" })
205
- long countExample (List <Integer > list ) {
213
+ long countExample (List <Integer > list ) {
206
214
UtMock .assume (list != null );
207
215
208
216
if (list .isEmpty ()) {
@@ -213,7 +221,7 @@ long countExample(List<Integer> list) {
213
221
}
214
222
215
223
@ SuppressWarnings ({"Convert2MethodRef" , "ConstantConditions" , "RedundantOperationOnEmptyContainer" })
216
- boolean anyMatchExample (List <Integer > list ) {
224
+ boolean anyMatchExample (List <Integer > list ) {
217
225
UtMock .assume (list != null );
218
226
219
227
if (list .isEmpty ()) {
@@ -241,7 +249,7 @@ boolean anyMatchExample(List<Integer> list) {
241
249
}
242
250
243
251
@ SuppressWarnings ({"Convert2MethodRef" , "ConstantConditions" , "RedundantOperationOnEmptyContainer" })
244
- boolean allMatchExample (List <Integer > list ) {
252
+ boolean allMatchExample (List <Integer > list ) {
245
253
UtMock .assume (list != null );
246
254
247
255
if (list .isEmpty ()) {
@@ -269,7 +277,7 @@ boolean allMatchExample(List<Integer> list) {
269
277
}
270
278
271
279
@ SuppressWarnings ({"Convert2MethodRef" , "ConstantConditions" , "RedundantOperationOnEmptyContainer" })
272
- boolean noneMatchExample (List <Integer > list ) {
280
+ boolean noneMatchExample (List <Integer > list ) {
273
281
UtMock .assume (list != null );
274
282
275
283
if (list .isEmpty ()) {
@@ -297,7 +305,7 @@ boolean noneMatchExample(List<Integer> list) {
297
305
}
298
306
299
307
@ SuppressWarnings ("RedundantOperationOnEmptyContainer" )
300
- Optional <Integer > findFirstExample (List <Integer > list ) {
308
+ Optional <Integer > findFirstExample (List <Integer > list ) {
301
309
UtMock .assume (list != null );
302
310
303
311
if (list .isEmpty ()) {
@@ -311,7 +319,7 @@ Optional<Integer> findFirstExample(List<Integer> list) {
311
319
}
312
320
}
313
321
314
- Integer iteratorSumExample (List <Integer > list ) {
322
+ Integer iteratorSumExample (List <Integer > list ) {
315
323
UtMock .assume (list != null && !list .isEmpty ());
316
324
317
325
int sum = 0 ;
0 commit comments