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