forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputReturnCountLambda3.java
72 lines (59 loc) · 1.69 KB
/
InputReturnCountLambda3.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
/*
ReturnCount
max = (default)2
maxForVoid = (default)1
format = (default)^equals$
tokens = METHOD_DEF
*/
package com.puppycrawl.tools.checkstyle.checks.coding.returncount;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
public class InputReturnCountLambda3 {
Runnable fieldWithOneReturnInLambda = () -> {
return;
};
Callable<Integer> fieldWithTwoReturnInLambda = () -> {
if (hashCode() == 0) return 0;
else return 1;
};
Optional<Integer> methodWithOneReturnInLambda() {
return Optional.of(hashCode()).filter(i -> {
return i > 0;
});
}
Optional<Integer> methodWithTwoReturnInLambda() { // violation
return Optional.of(hashCode()).filter(i -> {
if (i > 0) return true;
else return false;
});
}
Optional<Object> methodWithThreeReturnInLambda(int number) { // violation
return Optional.of(number).map(i -> {
if (i == 42) return true;
else if (i == 7) return true;
else return false;
});
}
int methodWithTwoReturnWithLambdas(final int number) { // violation
if (hashCode() > 0) {
new Thread(
() -> {
}
).start();
return number;
} else {
return Optional.of(hashCode()).orElseGet(() -> {
if (number > 0) return number;
else return 0;
});
}
}
Supplier<Supplier<Integer>> methodWithOneReturnPerLambda() { // violation
return () -> {
return () -> {
return 1;
};
};
}
}