View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // Test case file for checkstyle.
3   // Created: 2001
4   ////////////////////////////////////////////////////////////////////////////////
5   package com.puppycrawl.tools.checkstyle.checks.coding.simplifybooleanexpression;
6   
7   /**
8      Contains boolean logic that can be simplified.
9   
10     @author lkuehne
11   */
12  public class InputSimplifyBooleanExpression
13  {
14  
15      public static boolean isOddMillis()
16      {
17          boolean even = System.currentTimeMillis() % 2 == 0;
18  
19          // can be simplified to "if (even)"
20          if (even == true) {
21              return false;
22          }
23          else {
24              return true;
25          }
26          // return can be simplified to "return !even"
27      }
28  
29      public static boolean isOddMillis2()
30      {
31          boolean even = System.currentTimeMillis() % 2 == 0;
32          // can be simplified to "return !even"
33          if (!even)
34              return true;
35          else
36              return false;
37      }
38  
39      public static boolean giveMeTrue()
40      {
41          boolean tt = isOddMillis() || true;
42          boolean ff = isOddMillis() && false;
43          return !false || (true != false);
44      }
45  
46      public void tryToProvokeNPE()
47      {
48          if (true) {
49          }
50          else {
51          }
52  
53          if (true) {
54              return;
55          }
56          else {
57              return;
58          }
59      }
60  
61      public boolean ifNoElse()
62      {
63          if (isOddMillis()) {
64              return true;
65          }
66          return false;
67      }
68  
69      boolean a() {
70          boolean asd = false;
71          boolean dasa = true;
72  
73          if (asd) {
74              return true;
75          } else {
76              return dasa;
77          }
78      }
79  
80      boolean b() {
81          boolean asd = false;
82  
83          if(asd);
84          else;
85  
86          return true;
87      }
88  }