1
2
3
4
5
6
7
8
9
10
11 package com.puppycrawl.tools.checkstyle.checks.coding.returncount;
12
13 import java.lang.Integer;
14 import java.util.Optional;
15 import java.util.concurrent.Callable;
16 import java.util.function.Supplier;
17
18
19 public class InputReturnCountLambda {
20
21 Runnable fieldWithOneReturnInLambda = () -> {
22 return;
23 };
24
25 Callable<Integer> fieldWithTwoReturnInLambda = () -> {
26 if (hashCode() == 0) return 0;
27 else return 1;
28 };
29
30 Optional<Integer> methodWithOneReturnInLambda() {
31 return Optional.of(hashCode()).filter(i -> {
32 return i > 0;
33 });
34 }
35
36 Optional<Integer> methodWithTwoReturnInLambda() {
37 return Optional.of(hashCode()).filter(i -> {
38 if (i > 0) return true;
39 else return false;
40 });
41 }
42
43 Optional<Object> methodWithThreeReturnInLambda(int number) {
44 return Optional.of(number).map(i -> {
45 if (i == 42) return true;
46 else if (i == 7) return true;
47 else return false;
48 });
49 }
50
51 int methodWithTwoReturnWithLambdas(final int number) {
52 if (hashCode() > 0) {
53 new Thread(
54 () -> {
55 }
56 ).start();
57 return number;
58 } else {
59 return Optional.of(hashCode()).orElseGet(() -> {
60 if (number > 0) return number;
61 else return 0;
62 });
63 }
64 }
65
66 Supplier<Supplier<Integer>> methodWithOneReturnPerLambda() {
67 return () -> {
68 return () -> {
69 return 1;
70 };
71 };
72 }
73 }