equals method
[IRC.git] / Robust / src / ClassLibrary / String.java
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;
+    }
 }