1 package com.google.checkstyle.test.chapter4formatting.rule451wheretobreak;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import java.util.function.BiFunction;
6 import java.util.function.Function;
7 import java.util.function.Supplier;
8
9
10 public class InputLambdaBodyWrap {
11
12 private List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
13
14 private BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
15
16 private Supplier<String> getMessage =
17 () ->
18
19 "Hello, world!";
20
21 private void printNames() {
22 names.forEach(name -> System.out.println(name));
23 }
24
25 private void runTask() {
26 Runnable runTask = ()
27 -> {
28 System.out.println("Starting task");
29 System.out.println("Task completed");
30 };
31 }
32
33 private void executeNestedLambda() {
34 Function<Function<Integer, Integer>, Integer> applyFunc = f -> f.apply(5);
35 System.out.println(
36 applyFunc.apply(
37 x ->
38 x * x));
39 }
40
41 private void sumOfSquares() {
42 List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
43 int sum =
44 numbers.stream()
45 .filter(n -> n % 2 == 1)
46 .mapToInt(
47 n ->
48 n * n)
49 .sum();
50 }
51
52 private void showComplexNestedLambda() {
53
54
55
56
57
58 Function<Integer, Function<Integer, Integer>> createAdder =
59 x ->
60 (y ->
61 x + y);
62 }
63
64 private void foo() {
65 BiFunction<String, Long, Long> r =
66 (String label, Long value) -> {
67 return value;
68 };
69
70
71 java.util.function.Predicate<String> predicate = str
72 ->
73 {
74 return str.isEmpty();
75 };
76
77
78 Function<String, BiFunction<String, String, String>> s =
79 (String label) ->
80 {
81 return (a, b) ->
82 {
83 return a + " " + b;
84 };
85 };
86
87 }
88 }