1   package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses;
2   
3   import java.io.Serializable;
4   import java.util.HashSet;
5   import java.util.Objects;
6   import java.util.function.Function;
7   
8   public class InputUnnecessaryParenthesesLambdas {
9       int foo(int y) {
10          MathOperation case1 = (x) -> x + x;
11          MathOperation case2 = (x) -> { return x + x; };
12          MathOperation case3 = (int x) -> x + x;
13          MathOperation case4 = x -> x + x;
14          MathOperation2 case5 = (a, b) -> a + b;
15          MathOperation2 case6 = (int a, int b) -> a + b;
16          MathOperation2 case7 = (int a, int b) -> { return a + b; };
17          Objects.requireNonNull(null, () -> "message");
18          call((x) -> x + x);
19          new HashSet<Integer>().stream().filter((filter) -> filter > 0);
20          return y;
21      }
22  
23      static <T> CheckedFunction1<T, T> identity() {
24          return t -> t;
25      }
26  
27      public interface CheckedFunction2<T1, T2, R> extends Lambda<R> {
28          R apply(T1 t1, T2 t2) throws Throwable;
29  
30          default CheckedFunction1<T2, R> apply(T1 t1) {
31              return (T2 t2) -> apply(t1, t2);
32          }
33          @Override
34          default Function1<T1, CheckedFunction1<T2, R>> curried() {
35                      return t1 -> t2 -> apply(t1, t2);
36          }
37          default Function1<T1, CheckedFunction1<T2, R>> curried2() {
38              return (t1) -> (t2) -> apply(t1, t2);
39          }
40          default Function1<T1, CheckedFunction1<T2, R>> curried3() {
41              return (t1) -> t2 -> apply(t1, t2);
42          }
43          default Function1<T1, CheckedFunction1<T2, R>> curried4() {
44              return t1 -> (t2) -> apply(t1, t2);
45          }
46      }
47  
48      private void call(MathOperation o) {
49          o.operation(1);
50      }
51  
52      interface MathOperation {
53          int operation(int a);
54      }
55  
56      interface MathOperation2 {
57          int operation(int a, int b);
58      }
59  
60      interface Lambda<R> extends Serializable {
61          Lambda<?> curried();
62      }
63  
64      public interface Function1<T1, R> extends Lambda<R>, Function<T1, R> {
65          @Override
66          default Function1<T1, R> curried() {
67              return this;
68          }
69      }
70  
71      public interface CheckedFunction1<T1, R> extends Lambda<R> {
72          R apply(T1 t1) throws Throwable;
73  
74          @Override
75          default CheckedFunction1<T1, R> curried() {
76              return this;
77          }
78      }
79  }