1
2
3
4
5
6
7
8
9
10
11
12 package com.puppycrawl.tools.checkstyle.grammar.java8;
13 import java.util.function.Function;
14 import java.util.logging.Logger;
15
16
17 public class InputLambda15
18 {
19 private static final Logger LOG = Logger.getLogger(InputLambda15.class.getName());
20
21 public static void main(String[] args) {
22 InputLambda15 ex = new InputLambda15();
23 Function<Double, Double> sin = d -> ex.sin(d);
24 Function<Double, Double> log = d -> ex.log(d);
25 Function<Double, Double> exp = d -> ex.exp(d);
26 InputLambda15 compose = new InputLambda15();
27 LOG.info(compose.calculate(sin.compose(log), 0.8).toString());
28
29 LOG.info(compose.calculate(sin.andThen(log), 0.8).toString());
30
31 LOG.info(compose.calculate(sin.compose(log).andThen(exp), 0.8).toString());
32
33 LOG.info(compose.calculate(sin.compose(log).compose(exp), 0.8).toString());
34
35 LOG.info(compose.calculate(sin.andThen(log).compose(exp), 0.8).toString());
36
37 LOG.info(compose.calculate(sin.andThen(log).andThen(exp), 0.8).toString());
38
39
40 }
41
42 public Double calculate(Function<Double, Double> operator, Double d)
43 {
44 return operator.apply(d);
45 }
46
47 public Double sin(Double d)
48 {
49 LOG.info("sin:");
50 return Math.sin(d);
51 }
52
53 public Double log(Double d)
54 {
55 LOG.info("log:");
56 return Math.log(d);
57 }
58
59 public Double exp(Double d)
60 {
61 LOG.info("exp:");
62 return Math.exp(d);
63 }
64 }