Working version of SSCA2 benchmark for kernel 1
[IRC.git] / Robust / src / ClassLibrary / Integer.java
1 public class Integer {
2   private int value;
3
4   public Integer(int value) {
5     this.value=value;
6   }
7
8   public Integer(String str) {
9     value=Integer.parseInt(str, 10);
10   }
11
12   public int intValue() {
13     return value;
14   }
15
16   public double doubleValue() {
17     return (double)value;
18   }
19
20   public float floatValue() {
21     return (float)value;
22   }
23
24   public byte[] intToByteArray() {
25     byte[] b = new byte[4];
26     for (int i = 0; i < 4; i++) {
27       int offset = (b.length - 1 - i) * 8;
28       b[i] = (byte) ((value >> offset) & 0xFF);
29     }
30     return b;
31   }
32
33   public int byteArrayToInt(byte [] b) {
34     int val;
35     val = b[0] << 24 + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF);
36     return val;
37   }
38
39   public static int parseInt(String str) {
40     return Integer.parseInt(str, 10);
41   }
42
43   public static int parseInt(String str, int radix) {
44     int value=0;
45     boolean isNeg=false;
46     int start=0;
47     byte[] chars=str.getBytes();
48
49     while(chars[start]==' '||chars[start]=='\t')
50       start++;
51
52     if (chars[start]=='-') {
53       isNeg=true;
54       start++;
55     }
56     boolean cont=true;
57     for(int i=start; cont&&i<str.length(); i++) {
58       byte b=chars[i];
59       int val;
60       if (b>='0'&&b<='9')
61         val=b-'0';
62       else if (b>='a'&&b<='z')
63         val=10+b-'a';
64       else if (b>='A'&&b<='Z')
65         val=10+b-'A';
66       else {
67         cont=false;
68       }
69       if (cont) {
70         if (val>=radix)
71           System.error();
72         value=value*radix+val;
73       }
74     }
75     if (isNeg)
76       value=-value;
77     return value;
78   }
79
80   public String toString() {
81     return String.valueOf(value);
82   }
83
84   public static String toString(int i) {
85     Integer I = new Integer(i);
86     return I.toString();
87   }
88
89   public int hashCode() {
90     return value;
91   }
92
93   public boolean equals(Object o) {
94     if (o.getType()!=getType())
95       return false;
96     Integer s=(Integer)o;
97     if (s.intValue()!=this.value)
98       return false;
99     return true;
100   }
101 }