KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > InputSimplifyBoolean


1 ////////////////////////////////////////////////////////////////////////////////
2
// Test case file for checkstyle.
3
// Created: 2001
4
////////////////////////////////////////////////////////////////////////////////
5
package com.puppycrawl.tools.checkstyle;
6
7 /**
8    Contains boolean logic that can be simplified.
9
10    @author lkuehne
11  */

12 public class InputSimplifyBoolean
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
Popular Tags