KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > OptimizerTest


1 /**
2  * This class should be optimized through the obfuscator:
3  *
4  * <pre>
5  * java jode.Obfuscator --dest tmp.zip --preserve 'jode.test.OptimizerTest.test.(*)*' jode
6  * </pre>
7  */

8
9 public class OptimizerTest {
10     String JavaDoc blah, blub;
11     Object JavaDoc o;
12
13     private static String JavaDoc manipulateString(String JavaDoc input) {
14     char[] chars = input.toCharArray();
15     char[] dests = new char[chars.length];
16     dests[0] = chars[0];
17     for (int i=1; i< chars.length; i++) {
18         if (chars[i] > chars[i-1]) {
19         dests[i] = (char) (chars[i] - chars[i-1]);
20         } else if (chars[i] == chars[i-1]) {
21         dests[i] = 0;
22         } else if (chars[i] < chars[i-1]) {
23         dests[i] = (char) (Character.MAX_VALUE
24                    - (chars[i-1] - chars[i] - 1));
25         } else
26         dests[i] = 'X';
27     }
28     return new String JavaDoc(dests);
29     }
30
31     public static String JavaDoc doubleCompare(double d1, double d2) {
32     return d1 + ((d1 > d2) ? " > "
33              : (d1 < d2) ? " < "
34              : (d1 == d2) ? " == " : " ?? ") + d2;
35     }
36     
37     public void test() {
38     System.err.println(manipulateString("ABCDEFGGFEDCBA"));
39     blah = manipulateString("hello world");
40     o = new Object JavaDoc();
41     blub = "Hallo"+manipulateString("ABCDEFGGFDECBA");
42     System.err.println(blub);
43
44     System.err.println(doubleCompare(0.0, 0.0));
45     System.err.println(doubleCompare(0.0, 1.0));
46     System.err.println(doubleCompare(0.0, -1.0));
47     System.err.println(doubleCompare(0.0, Double.NaN));
48     System.err.println(doubleCompare(Double.NaN, 0.0));
49     System.err.println(doubleCompare(Double.NaN, Double.NaN));
50     System.err.println(doubleCompare(Double.NEGATIVE_INFINITY,
51                      Double.POSITIVE_INFINITY));
52
53     System.err.println(doubleCompare(Math.exp(1), 2.718281828459045));
54
55     System.err.println((int)Math.round(Math.exp(Math.log(5)*5))/ 625);
56     }
57 }
58
59
Popular Tags