You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/05/06 17:42:14 UTC

svn commit: r1742568 - /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java

Author: schor
Date: Fri May  6 17:42:13 2016
New Revision: 1742568

URL: http://svn.apache.org/viewvc?rev=1742568&view=rev
Log:
[UIMA-4674] support concurrent modification exception detection; fix impl of moveTo for bag index when not found, to follow the interface spec and return an invalid iterator; change shrink trigger to size < 1/4 (not 1/2) of size which triggers expansion.

Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java?rev=1742568&r1=1742567&r2=1742568&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java Fri May  6 17:42:13 2016
@@ -27,7 +27,6 @@ import java.util.NoSuchElementException;
 import java.util.Set;
 
 import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.util.Misc;
 
 /**
  * A set of Objects of type T 
@@ -68,6 +67,8 @@ public class ObjHashSet<T> implements Se
 
   private boolean secondTimeShrinkable = false;
   
+  private int modificationCount = 0;
+  
   public ObjHashSet(Class<T> clazz, T removedMarker) {
     this(12, clazz, removedMarker);  // default initial size
   }
@@ -158,12 +159,13 @@ public class ObjHashSet<T> implements Se
   private void resetTable() {
     resetHistogram();
     size = 0;
+    modificationCount ++;
   }
   
   @Override
   public void clear() {
-    // see if size is less than the 1/2 size that triggers expansion
-    if (size <  (sizeWhichTriggersExpansion >>> 1)) {
+    // see if size is less than the 1/4 size that triggers expansion
+    if (size <  (sizeWhichTriggersExpansion >>> 2)) { 
       // if 2nd time then shrink by 50%
       //   this is done to avoid thrashing around the threshold
       if (secondTimeShrinkable) {
@@ -274,6 +276,7 @@ public class ObjHashSet<T> implements Se
     }
     keys[i] = obj;
     incrementSize();
+    modificationCount ++;
     return true;
   }
         
@@ -308,7 +311,8 @@ public class ObjHashSet<T> implements Se
   private boolean removeAtPosition(int pos) {
     // found, remove it
     keys[pos] = (T) removedMarker;  // at runtime, this cast is a no-op    
-    size--;
+    size --;
+    modificationCount ++;
     nbrRemoved ++;
     return true;
   }
@@ -476,9 +480,9 @@ public class ObjHashSet<T> implements Se
   
   /**
    * if the fs is in the set, the iterator should return it.
-   * if not, move to the first - just to return something.
+   * if not, return -1 (makes iterator invalid)
    * @param fs position to this fs
-   * @return the index if present, otherwise moveToNextFileed(0);
+   * @return the index if present, otherwise -1;
    */
   public int moveTo(FeatureStructure fs) {
     if (clazz.isAssignableFrom(fs.getClass())) {
@@ -487,7 +491,7 @@ public class ObjHashSet<T> implements Se
         return pos;
       }
     }
-    return moveToFirst(); 
+    return -1; 
   }
 
   @Override
@@ -568,4 +572,8 @@ public class ObjHashSet<T> implements Se
     }
     return anyChanged;
   }
+  
+  public int getModificationCount() {
+    return modificationCount;
+  }
 }