Add a doubleValue() method
[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 static int parseInt(String str) {
21     return Integer.parseInt(str, 10);
22   }
23
24   public static int parseInt(String str, int radix) {
25     int value=0;
26     boolean isNeg=false;
27     int start=0;
28     byte[] chars=str.getBytes();
29
30     while(chars[start]==' '||chars[start]=='\t')
31       start++;
32
33     if (chars[start]=='-') {
34       isNeg=true;
35       start++;
36     }
37     boolean cont=true;
38     for(int i=start; cont&&i<str.length(); i++) {
39       byte b=chars[i];
40       int val;
41       if (b>='0'&&b<='9')
42         val=b-'0';
43       else if (b>='a'&&b<='z')
44         val=10+b-'a';
45       else if (b>='A'&&b<='Z')
46         val=10+b-'A';
47       else {
48         cont=false;
49       }
50       if (cont) {
51         if (val>=radix)
52           System.error();
53         value=value*radix+val;
54       }
55     }
56     if (isNeg)
57       value=-value;
58     return value;
59   }
60
61   public String toString() {
62     return String.valueOf(value);
63   }
64
65   public static String toString( int i ) {
66     Integer I = new Integer( i );
67     return I.toString();
68   }
69
70   public int hashCode() {
71     return value;
72   }
73
74   public boolean equals(Object o) {
75     if (o.getType()!=getType())
76       return false;
77     Integer s=(Integer)o;
78     if (s.intValue()!=this.value)
79       return false;
80     return true;
81   }
82 }