equals method
authorbdemsky <bdemsky>
Fri, 3 Nov 2006 20:06:35 +0000 (20:06 +0000)
committerbdemsky <bdemsky>
Fri, 3 Nov 2006 20:06:35 +0000 (20:06 +0000)
better error message
hashcode for string method

Robust/src/ClassLibrary/Object.java
Robust/src/ClassLibrary/String.java
Robust/src/ClassLibrary/System.java
Robust/src/Runtime/runtime.c

index d36f07aa37cbba7bc75258ada86c1912bec8cff6..dfaa7d3f5458c1ad1e892887f62f51a98e7bb9c9 100644 (file)
@@ -1,6 +1,10 @@
 public class Object {
     public native int hashCode();
 
+    /* DON'T USE THIS METHOD UNLESS NECESSARY */
+    /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */
+    public native int getType();
+
     public String toString() {
        return String.valueOf(this);
     }
index faabe029e7f409348b64140635a6923ff19b017a..eda1206599cb21d45ec4aded953d0174a91680ac 100644 (file)
@@ -152,4 +152,24 @@ public class String {
        } while (length!=0);
        return new String(chararray);
     }
+
+    public int hashCode() {
+       int hashcode=0;
+       for(int i=0;i<count;i++)
+           hashcode=hashcode*31+value[i+offset];
+       return hashcode;
+    }
+
+    public boolean equals(Object o) {
+       if (o.getType()!=getType())
+           return false;
+       String s=(String)o;
+       if (s.count!=count)
+           return false;
+       for(int i=0;i<count;i++) {
+           if (s.value[i+s.offset]!=value[i+offset])
+               return false;
+       }
+       return true;
+    }
 }
index 700f2b090933be33ea26f55bd392aab9be9804db..89b33ea44d07b2ac0cc6a6e583a703d1b846d4df 100644 (file)
@@ -7,6 +7,6 @@ public class System {
     public static native void printString(String s);
 
     public static void error() {
-       System.printString("Error");
+       System.printString("Error (Use Breakpoint on ___System______error method for more information!)\n");
     }
 }
index 816fa839eea4a7c5b250ac629134364919bb3962..971a1829214dd66490f24f31e5827ec579d51c24 100644 (file)
@@ -463,6 +463,10 @@ int ___Object______hashCode____(struct ___Object___ * ___this___) {
   return (int) ___this___;
 }
 
+int ___Object______getType____(struct ___Object___ * ptr) {
+  return ((int *)ptr)[0];
+}
+
 void ___System______printString____L___String___(struct ___String___ * s) {
     struct ArrayObject * chararray=s->___value___;
     int i;