View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="ReturnCount">
5         <property name="max" value="3"/>
6         <property name="format" value="^$"/>
7       </module>
8     </module>
9   </module>
10  */
11  package com.puppycrawl.tools.checkstyle.checks.coding.returncount;
12  
13  import java.util.function.Predicate;
14  
15  // xdoc section -- start
16  public class Example4 {
17      public Example4() {}
18      // ok below, because default void restriction is 1
19      public Example4(int i) { return; }
20  
21      public int signA(int x) {
22          if (x < -2) { return -1; }
23          return 0;
24      }
25      // violation below, 'max allowed for non-void methods/lambdas is 3'
26      public int signB(int x) {
27          if (x < -2) { return -1; }
28          if (x == 0) { return 0; }
29          if (x > 2) { return 2; }
30          return 1;
31      }
32      // ok below, because non-void restriction is 3
33      final Predicate<Integer> lambdaA = i -> {
34          if (i > 5) { return true; }
35          return false;
36      };
37  
38      final Predicate<Integer> lambdaB = i -> { return i > 5; };
39  
40      public void methodA(int x) {}
41      // ok below, because default void restriction is 1
42      public void methodB(int x) { return; }
43  }
44  // xdoc section -- end