changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / ClassLibrary / SSJava / Integer.java
1 @LATTICE("V<C, V<O")
2 @METHODDEFAULT("O<V,V<C,C<IN,THISLOC=IN,C*,GLOBALLOC=V")
3 public class Integer {
4   
5   @LOC("V")  private int value;
6   
7   /**
8    * The maximum value an <code>int</code> can represent is 2147483647 (or
9    * 2<sup>31</sup> - 1).
10    */
11   public static final int MAX_VALUE = 0x7fffffff;
12
13   public Integer(int value) {
14     this.value = value;
15   }
16
17   // public Integer(String str) {
18   // value=Integer.parseInt(str, 10);
19   // }
20
21   public int intValue() {
22     return value;
23   }
24
25   public double doubleValue() {
26     return (double) value;
27   }
28
29   public float floatValue() {
30     return (float) value;
31   }
32
33   public byte[] intToByteArray() {
34     byte[] b = new byte[4];
35     for (int i = 0; i < 4; i++) {
36       int offset = (b.length - 1 - i) * 8;
37       b[i] = (byte) ((value >> offset) & 0xFF);
38     }
39     return b;
40   }
41
42   public int byteArrayToInt(byte[] b) {
43     int value = 0;
44     for (int i = 0; i < 4; i++) {
45       int shift = (4 - 1 - i) * 8;
46       value += (b[i] & 0x000000FF) << shift;
47     }
48     return value;
49   }
50
51   public static int parseInt(String str) {
52     return Integer.parseInt(str, 10);
53   }
54
55   public static int parseInt(String str, int radix) {
56     int value = 0;
57     boolean isNeg = false;
58     int start = 0;
59     byte[] chars = str.getBytes();
60
61     while (chars[start] == ' ' || chars[start] == '\t')
62       start++;
63
64     if (chars[start] == '-') {
65       isNeg = true;
66       start++;
67     }
68     boolean cont = true;
69     for (int i = start; cont && i < str.length(); i++) {
70       byte b = chars[i];
71       int val;
72       if (b >= '0' && b <= '9')
73         val = b - '0';
74       else if (b >= 'a' && b <= 'z')
75         val = 10 + b - 'a';
76       else if (b >= 'A' && b <= 'Z')
77         val = 10 + b - 'A';
78       else {
79         cont = false;
80       }
81       if (cont) {
82         if (val >= radix)
83           System.error();
84         value = value * radix + val;
85       }
86     }
87     if (isNeg)
88       value = -value;
89     return value;
90   }
91
92   @RETURNLOC("V")
93   public String toString() {
94     return String.valueOf(value);
95   }
96   
97   @RETURNLOC("V")
98   public static String toString(@LOC("IN") int i) {
99    @LOC("C") Integer I = new Integer(i);
100     return I.toString();
101   }
102
103   @RETURNLOC("V")
104   public int hashCode() {
105     return value;
106   }
107
108   public boolean equals(Object o) {
109     if (o.getType() != getType())
110       return false;
111     Integer s = (Integer) o;
112     if (s.intValue() != this.value)
113       return false;
114     return true;
115   }
116
117   public int compareTo(Integer i) {
118     if (value == i.value)
119       return 0;
120     // Returns just -1 or 1 on inequality; doing math might overflow.
121     return value > i.value ? 1 : -1;
122   }
123 }