start to implement second garbage collector to benchmark against...
[IRC.git] / Robust / src / ClassLibrary / Integer.java
index 39f76d25d24f8468eb35424c6c9d028eb6ffa11c..1f7909f4584b18eaf0b7448a8c3683947afe29fc 100644 (file)
@@ -31,11 +31,22 @@ public class Integer {
   }
 
   public int byteArrayToInt(byte [] b) {
-    int val;
-    val = b[0] << 24 + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF);
-    return val;
+    int value = 0;
+    for (int i = 0; i < 4; i++) {
+      int shift = (4 - 1 - i) * 8;
+      value += (b[i] & 0x000000FF) << shift;
+    }
+    return value;
   }
 
+  /*
+     public int byteArrayToInt(byte [] b) {
+     int val;
+     val = b[0] << 24 + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF);
+     return val;
+     }
+   */
+
   public static int parseInt(String str) {
     return Integer.parseInt(str, 10);
   }
@@ -58,18 +69,18 @@ public class Integer {
       byte b=chars[i];
       int val;
       if (b>='0'&&b<='9')
-       val=b-'0';
+        val=b-'0';
       else if (b>='a'&&b<='z')
-       val=10+b-'a';
+        val=10+b-'a';
       else if (b>='A'&&b<='Z')
-       val=10+b-'A';
+        val=10+b-'A';
       else {
-       cont=false;
+        cont=false;
       }
       if (cont) {
-       if (val>=radix)
-         System.error();
-       value=value*radix+val;
+        if (val>=radix)
+          System.error();
+        value=value*radix+val;
       }
     }
     if (isNeg)
@@ -98,4 +109,11 @@ public class Integer {
       return false;
     return true;
   }
+
+  public int compareTo(Integer i) {
+    if (value == i.value)
+      return 0;
+    // Returns just -1 or 1 on inequality; doing math might overflow.
+    return value > i.value?1:-1;
+  }
 }