View Javadoc
1   /*
2   com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck
3   format = (default)^[a-z][a-zA-Z0-9]*$
4   applyToPublic = (default)true
5   applyToProtected = (default)true
6   applyToPackage = (default)true
7   applyToPrivate = (default)true
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          // prints log:sin:-0.22
29          LOG.info(compose.calculate(sin.andThen(log), 0.8).toString());
30          // prints sin:log:-0.33
31          LOG.info(compose.calculate(sin.compose(log).andThen(exp), 0.8).toString());
32          //log:sin:exp:0.80
33          LOG.info(compose.calculate(sin.compose(log).compose(exp), 0.8).toString());
34          //exp:log:sin:0.71
35          LOG.info(compose.calculate(sin.andThen(log).compose(exp), 0.8).toString());
36          //exp:sin:log:-0.23
37          LOG.info(compose.calculate(sin.andThen(log).andThen(exp), 0.8).toString());
38          //sin:log:exp:0.71
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  }