bug fixing
[IRC.git] / Robust / src / ClassLibrary / Integer.java
index 4ce665f94193147b144248dd0cdf76994760cb6e..523acb2b2e7abf876834da943cb7e126f45f4061 100644 (file)
@@ -1,50 +1,73 @@
 public class Integer {
-    private int value;
+  private int value;
 
-    public Integer(int value) {
-       this.value=value;
-    }
+  public Integer(int value) {
+    this.value=value;
+  }
 
-    public Integer(String str) {
-       value=Integer.parseInt(str, 10);
-    }
+  public Integer(String str) {
+    value=Integer.parseInt(str, 10);
+  }
 
-    public int intValue() {
-       return value;
-    }
+  public int intValue() {
+    return value;
+  }
 
-    public static int parseInt(String str) {
-       return Integer.parseInt(str, 10);
-    }
+  public static int parseInt(String str) {
+    return Integer.parseInt(str, 10);
+  }
 
-    public static int parseInt(String str, int radix) {
-       int value=0;
-       boolean isNeg=false;
-       int start=0;
-       byte[] chars=str.getBytes();
-       if (chars[0]=='-') {
-           isNeg=true;
-           start=1;
-       }
-       for(int i=start;i<str.length();i++) {
-           byte b=chars[i];
-           int val;
-           if (b>='0'&&b<='9')
-               val=b-'0';
-           else if (b>='a'&&b<='z')
-               val=10+b-'a';
-           else if (b>='A'&&b<='Z')
-               val=10+b-'A';
-           if (val>=radix)
-               System.error();
-           value=value*radix+val;
-       }
-       if (isNeg)
-           value=-value;
-       return value;
-    }
+  public static int parseInt(String str, int radix) {
+    int value=0;
+    boolean isNeg=false;
+    int start=0;
+    byte[] chars=str.getBytes();
 
-    public String toString() {
-       return String.valueOf(value);
+    while(chars[start]==' '||chars[start]=='\t')
+      start++;
+
+    if (chars[start]=='-') {
+      isNeg=true;
+      start++;
+    }
+    boolean cont=true;
+    for(int i=start; cont&&i<str.length(); i++) {
+      byte b=chars[i];
+      int val;
+      if (b>='0'&&b<='9')
+       val=b-'0';
+      else if (b>='a'&&b<='z')
+       val=10+b-'a';
+      else if (b>='A'&&b<='Z')
+       val=10+b-'A';
+      else {
+       cont=false;
+      }
+      if (cont) {
+       if (val>=radix)
+         System.error();
+       value=value*radix+val;
+      }
     }
+    if (isNeg)
+      value=-value;
+    return value;
+  }
+
+  public String toString() {
+    return String.valueOf(value);
+  }
+  
+  public int hashCode() {
+      return value;
+  }
+
+  public boolean equals(Object o) {
+      if (o.getType()!=getType())
+         return false;
+      Integer s=(Integer)o;
+      if (s.intValue()!=this.value)
+         return false;
+      return true;
+  }
 }