*** empty log message ***
authorhkhang <hkhang>
Wed, 4 Nov 2009 00:47:21 +0000 (00:47 +0000)
committerhkhang <hkhang>
Wed, 4 Nov 2009 00:47:21 +0000 (00:47 +0000)
Robust/src/ClassLibrary/JavaDSM/GlobalString.java
Robust/src/ClassLibrary/JavaDSM/Work.java

index 68c117beff0befbe56ca13ae5f618aa5966edcd1..c9441e7e8f946e63f9807b1dc1c28cc325b6218a 100644 (file)
@@ -2,6 +2,7 @@ public class GlobalString {
   char value[];
   int count;
   int offset;
+       private int cachedHashcode;
 
   public GlobalString() {
   }
@@ -35,6 +36,17 @@ public class GlobalString {
                }
        }
 
+  public int hashCode() {
+    if (cachedHashcode!=0)
+      return cachedHashcode;
+    int hashcode=0;
+    for(int i=0; i<count; i++)
+      hashcode=hashcode*31+value[i+offset];
+    cachedHashcode=hashcode;
+    return hashcode;
+  }
+
+
        public static char[] toLocalCharArray(GlobalString str) {
                char[] c;
                int length;
@@ -107,6 +119,14 @@ public class GlobalString {
                return true;
        }
 
+       public GlobalString substring(int beginIndex) {
+               return substring(beginIndex, this.count);
+       }
+
+  public GlobalString subString(int beginIndex) {
+    return subString(beginIndex, this.count);
+  }
+
        public GlobalString subString(int beginIndex, int endIndex) {
                return substring(beginIndex, endIndex);
        }
@@ -115,15 +135,39 @@ public class GlobalString {
                GlobalString str;
                atomic {
                        str = global new GlobalString();
-//             }
-//             if (beginIndex > this.count || endIndex > this.count || beginIndex > endIndex) {
-//                     System.printString("Index error\n");
-//             }
-//             atomic {
+               }
+               if (beginIndex > this.count || endIndex > this.count || beginIndex > endIndex) {
+                       System.printString("Index error\n");
+               }
+               atomic {
                        str.value = this.value;
                        str.count = endIndex-beginIndex;
                        str.offset = this.offset + beginIndex;
                }
                return str;     
        }
+
+       public boolean equals(String str) {
+               GlobalString gstr;
+
+               atomic {
+                       gstr = global new GlobalString(str);
+               }
+               return equals(gstr);
+       }
+
+       public boolean equals(Object o) {
+               if (o.getType()!= getType())
+                       return false;
+               
+               GlobalString gs = (GlobalString)o;
+               if (gs.count!= count)
+                       return false;
+
+               for(int i = 0; i < count; i++) {
+                       if (gs.value[i+gs.offset] != value[i+offset])
+                               return false;
+               }
+               return true;
+       }
 }
index 3a1b59ecc67d9e342f6e44941f402cd54450285b..5692cd5bb61b4e2d0a5f6017601947545ba42799 100644 (file)
@@ -25,7 +25,6 @@ public class Work extends Thread {
                boolean isEmpty; 
 
     while(true) {
-
       atomic {
                                        isEmpty = tasks.isTodoListEmpty();              // flag > !keep assigning