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