Author: schor
Date: Mon Sep 19 20:24:02 2016
New Revision: 1761499

URL: http://svn.apache.org/viewvc?rev=1761499&view=rev
Log:
[UIMA-5111] refactor for common code

Added:
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CopyOnWriteIndexPart.java
Modified:
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_bag.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_flat.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java
    
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java

Added: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CopyOnWriteIndexPart.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CopyOnWriteIndexPart.java?rev=1761499&view=auto
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CopyOnWriteIndexPart.java
 (added)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CopyOnWriteIndexPart.java
 Mon Sep 19 20:24:02 2016
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.cas.impl;
+
+/**
+ * common APIs supporting the copy on write aspect of index parts
+ */
+public interface CopyOnWriteIndexPart {
+  
+  void makeCopy();
+  
+}

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_bag.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_bag.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_bag.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_bag.java
 Mon Sep 19 20:24:02 2016
@@ -19,7 +19,6 @@
 
 package org.apache.uima.cas.impl;
 
-import java.lang.ref.WeakReference;
 import java.util.Collection;
 import java.util.List;
 
@@ -28,7 +27,6 @@ import org.apache.uima.cas.FeatureStruct
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.admin.FSIndexComparator;
 import org.apache.uima.internal.util.CopyOnWriteObjHashSet;
-import org.apache.uima.internal.util.CopyOnWriteOrderedFsSet_array;
 import org.apache.uima.internal.util.ObjHashSet;
 import org.apache.uima.jcas.cas.TOP;
 
@@ -47,16 +45,16 @@ public class FsIndex_bag<T extends Featu
   final private ObjHashSet<TOP> index;
   
 
-  /**
-   * Copy on write, initially null
-   * Iterator creation initializes (if not null).
-   * Modification to index:
-   *    call cow.makeCopy();
-   *    set cow = null
-   *    do the modification
-   * index clear/flush - set to null;
-   */
-  private WeakReference<CopyOnWriteObjHashSet<TOP>> cow = null;
+//  /**
+//   * Copy on write, initially null
+//   * Iterator creation initializes (if not null).
+//   * Modification to index:
+//   *    call cow.makeCopy();
+//   *    set cow = null
+//   *    do the modification
+//   * index clear/flush - set to null;
+//   */
+//  private WeakReference<CopyOnWriteObjHashSet<TOP>> cow = null;
   
   FsIndex_bag(CASImpl cas, Type type, int initialSize, int indexType, 
FSIndexComparator comparatorForIndexSpecs) {
     super(cas, type, indexType, cleanUpComparator(comparatorForIndexSpecs, 
cas));
@@ -80,9 +78,10 @@ public class FsIndex_bag<T extends Featu
     return newComp;
   }
 
+  @Override
   public void flush() {
+    super.flush();
     index.clear();
-    cow = null;
   }
 
   @Override
@@ -144,6 +143,7 @@ public class FsIndex_bag<T extends Featu
    *           FSs in the index.
    * @return <code>true</code> if the index contains such an element.
    */
+  @Override
   public boolean contains(FeatureStructure fs) {
     return this.index.contains(fs);
   }
@@ -170,6 +170,7 @@ public class FsIndex_bag<T extends Featu
   /**
    * @see org.apache.uima.cas.FSIndex#size()
    */
+  @Override
   public int size() {
     return this.index.size();
   }
@@ -189,6 +190,7 @@ public class FsIndex_bag<T extends Featu
     return deleteFS((T) casImpl.getFsFromId_checked(fsRef));
   }
 
+  @Override
   public int hashCode() {
     throw new UnsupportedOperationException();
   }
@@ -203,43 +205,48 @@ public class FsIndex_bag<T extends Featu
    */
   @Override
   public FSIterator<T> iterator() {
-    if (null == cow || null == cow.get()) {
-      cow = new WeakReference<>(new CopyOnWriteObjHashSet<TOP>(index));
-    }
+    setupIteratorCopyOnWrite();
     return casImpl.inPearContext()
              ? new FsIterator_bag_pear<>(this, type)
              : new FsIterator_bag     <>(this, type);
   }
   
-  ObjHashSet<TOP> getObjHashSet() {
-    return index;
-  } 
-
-  private void maybeCopy() {
-    if (cow != null) {
-      CopyOnWriteObjHashSet<TOP> v = cow.get();
-      if (v != null) {
-        v.makeCopy();
-      }
-      cow = null;
-    }
+  @Override
+  protected CopyOnWriteIndexPart createCopyOnWriteIndexPart() {
+    return new CopyOnWriteObjHashSet<TOP>(index);
   }
   
-  /**
-   * Called when iterator created, and when a reset concur mod happens
-   * @return cow to use in iterator
-   */
-  public CopyOnWriteObjHashSet<TOP> getCow() {
-    if (cow != null) {
-      CopyOnWriteObjHashSet<TOP> n = cow.get();
-      if (n != null) {
-        return n;
-      }
-    }
+//  ObjHashSet<TOP> getObjHashSet() {
+//    return index;
+//  } 
     
-    // null means index updated since iterator was created, need to make new 
cow and use it
-    CopyOnWriteObjHashSet<TOP> n = new CopyOnWriteObjHashSet<TOP>(index);
-    cow = new WeakReference<>(n);
-    return n;
-  }
+
+//  private void maybeCopy() {
+//    if (cow != null) {
+//      CopyOnWriteObjHashSet<TOP> v = cow.get();
+//      if (v != null) {
+//        v.makeCopy();
+//      }
+//      cow = null;
+//    }
+//  }
+  
+//  /**
+//   * Called when iterator created, and when a reset concur mod happens
+//   * @return cow to use in iterator
+//   */
+//  public CopyOnWriteObjHashSet<TOP> getNonNullCow() {
+//    if (cow != null) {
+//      CopyOnWriteObjHashSet<TOP> n = cow.get();
+//      if (n != null) {
+//        return n;
+//      }
+//    }
+//    
+//    // null means index updated since iterator was created, need to make new 
cow and use it
+//    CopyOnWriteObjHashSet<TOP> n = new CopyOnWriteObjHashSet<TOP>(index);
+//    cow = new WeakReference<>(n);
+//    return n;
+//  }
+  
 }

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_flat.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_flat.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_flat.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_flat.java
 Mon Sep 19 20:24:02 2016
@@ -29,6 +29,7 @@ import java.util.List;
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.internal.util.IntVector;
+import org.apache.uima.internal.util.Misc;
 
 /**
  * Common part of flattened indexes, used for both snapshot iterators and 
@@ -36,7 +37,7 @@ import org.apache.uima.internal.util.Int
  *  
  * @param <T> the Java class type for this index
  */
-public class FsIndex_flat<T extends FeatureStructure> extends 
FsIndex_singletype<T> {
+public class FsIndex_flat<T extends FeatureStructure> extends 
FsIndex_singletype<T> implements CopyOnWriteIndexPart {
 
   // The index, an array.
   final private FeatureStructure[] indexedFSs;
@@ -144,6 +145,7 @@ public class FsIndex_flat<T extends Feat
   /**
    * @see org.apache.uima.cas.FSIndex#size()
    */
+  @Override
   public int size() {
     return this.indexedFSs.length;
   }
@@ -151,6 +153,7 @@ public class FsIndex_flat<T extends Feat
   /**
    * @see org.apache.uima.cas.impl.FsIndex_singletype#deleteFS(T)
    */
+  @Override
   public boolean deleteFS(T fs) {
     throw new UnsupportedOperationException();
   }  
@@ -176,4 +179,20 @@ public class FsIndex_flat<T extends Feat
     return comparator.compare(fs1,  fs2);
   }
 
+  @Override
+  protected CopyOnWriteIndexPart createCopyOnWriteIndexPart() {
+    Misc.internalError();  // should never be called
+    return this;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.cas.impl.CopyOnWriteIndexPart#makeCopy()
+   */
+  @Override
+  public void makeCopy() {
+    Misc.internalError(); // should never be called
+  }
+  
+  
+
 }

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java
 Mon Sep 19 20:24:02 2016
@@ -19,7 +19,6 @@
 
 package org.apache.uima.cas.impl;
 
-import java.lang.ref.WeakReference;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -30,7 +29,6 @@ import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.admin.FSIndexComparator;
-import org.apache.uima.internal.util.CopyOnWriteObjHashSet;
 import org.apache.uima.internal.util.CopyOnWriteOrderedFsSet_array;
 import org.apache.uima.internal.util.OrderedFsSet_array;
 import org.apache.uima.jcas.cas.TOP;
@@ -107,19 +105,19 @@ public class FsIndex_set_sorted<T extend
 //  final private TreeSet<FeatureStructure> indexedFSs;
   final private OrderedFsSet_array indexedFSs;
   
-  /**
-   * Copy on write, initially null
-   * Iterator creation initializes (if not null), and uses.
-   * Modification to index:
-   *    call cow.makeCopy();
-   *    set cow = null
-   *    do the modification
-   * index clear/flush - set to null;
-   * 
-   * Weak ref so that after iterator is GC'd, and no ref's exist, this becomes 
null, so that
-   * future mods no longer need to do extra work.
-   */
-  private WeakReference<CopyOnWriteOrderedFsSet_array> cow = null;
+//  /**
+//   * Copy on write, initially null
+//   * Iterator creation initializes (if not null), and uses.
+//   * Modification to index:
+//   *    call cow.makeCopy();
+//   *    set cow = null
+//   *    do the modification
+//   * index clear/flush - set to null;
+//   * 
+//   * Weak ref so that after iterator is GC'd, and no ref's exist, this 
becomes null, so that
+//   * future mods no longer need to do extra work.
+//   */
+//  private WeakReference<CopyOnWriteOrderedFsSet_array> cow = null;
     
   final private Comparator<TOP> comparatorWithID;
   final private Comparator<TOP> comparatorWithoutID;
@@ -173,7 +171,7 @@ public class FsIndex_set_sorted<T extend
 
   @Override
   public void flush() {
-    this.cow = null;
+    super.flush();
     this.indexedFSs.clear();
 //    this.itemsToBeAdded.clear();
 //    this.largestItemNotYetAdded = null;
@@ -348,37 +346,41 @@ public class FsIndex_set_sorted<T extend
    
   @Override
   public FSIterator<T> iterator() {
-    if (cow == null || null == cow.get()) {
-      cow = new WeakReference<>(new 
CopyOnWriteOrderedFsSet_array(this.indexedFSs));
-    }
+    setupIteratorCopyOnWrite();
     return casImpl.inPearContext()
              ? new FsIterator_set_sorted_pear<>(this, type, this)
              : new FsIterator_set_sorted     <>(this, type, this);
   }
   
-  private void maybeCopy() {
-    if (cow != null) { 
-      CopyOnWriteOrderedFsSet_array v = cow.get();
-      if (v != null) {
-        v.makeCopy();    
-      }
-      cow = null;
-    }
+  @Override
+  protected CopyOnWriteIndexPart createCopyOnWriteIndexPart() {
+    return new CopyOnWriteOrderedFsSet_array(indexedFSs);
   }
   
-  public CopyOnWriteOrderedFsSet_array getCow() {
-    if (cow != null) {
-      CopyOnWriteOrderedFsSet_array n = cow.get();
-      if (n != null) {
-        return n;
-      }
-    }
-    
-    // null means index updated since iterator was created, need to make new 
cow and use it
-    CopyOnWriteOrderedFsSet_array n = new 
CopyOnWriteOrderedFsSet_array(indexedFSs);
-    cow = new WeakReference<>(n);
-    return n;
-  }
+//  private void maybeCopy() {
+//    if (cow != null) { 
+//      CopyOnWriteOrderedFsSet_array v = cow.get();
+//      if (v != null) {
+//        v.makeCopy();    
+//      }
+//      cow = null;
+//    }
+//  }
+  
+//  public CopyOnWriteOrderedFsSet_array getNonNullCow() {
+//    if (cow != null) {
+//      CopyOnWriteOrderedFsSet_array n = cow.get();
+//      if (n != null) {
+//        return n;
+//      }
+//    }
+//    
+//    // null means index updated since iterator was created, need to make new 
cow and use it
+//    CopyOnWriteOrderedFsSet_array n = new 
CopyOnWriteOrderedFsSet_array(indexedFSs);
+//    cow = new WeakReference<>(n);
+//    return n;
+//  }
+  
     
 //  synchronized void maybeProcessBulkAdds() {
 //    final int sz = itemsToBeAdded.size();

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java
 Mon Sep 19 20:24:02 2016
@@ -63,7 +63,7 @@ public abstract class FsIndex_singletype
 
   /***********  Info about Index Comparator (not used for bag ***********
    * Index into these arrays is the key number (indexes can have multiple keys)
-   */
+   **********************************************************************/
   // For each key, the int code of the type of that key.
   final private Object[] keys;   // either a FeatImpl or a LinearTypeOrder;
 
@@ -75,6 +75,20 @@ public abstract class FsIndex_singletype
   
   final private int typeCode;
   
+  /**
+   * common copy on write instance or null; starts out as null
+   * Iterator creation initializes (if not null).
+   * A subsequent Modification to index, if this is not null:
+   *    call cow.makeCopy();
+   *    set wr_cow = null
+   *    do the modification
+   * index clear/flush - set to null;
+   * 
+   * Weak ref so that after iterator is GC'd, and no ref's exist, this becomes 
null, so that
+   * future mods no longer need to do extra work.
+   */
+  protected WeakReference<CopyOnWriteIndexPart> wr_cow = null;  
+  
   
   @Override
   public String toString() {
@@ -162,9 +176,18 @@ public abstract class FsIndex_singletype
    */
   abstract boolean deleteFS(T fs);
   
+  /**
+   * Common part of iterator creation
+   */
+  protected void setupIteratorCopyOnWrite() {
+    if (null == wr_cow || null == wr_cow.get()) {
+      wr_cow = new WeakReference<>(createCopyOnWriteIndexPart());
+    }
+  }
+  
   @Override
   public FSIterator<T> iterator(FeatureStructure initialPositionFs) {
-    FSIterator<T> fsIt = (FSIterator<T>) iterator();
+    FSIterator<T> fsIt = iterator();
     fsIt.moveTo(initialPositionFs);
     return fsIt;
   }
@@ -364,4 +387,42 @@ public abstract class FsIndex_singletype
     }
     flush();
   }
+
+  protected CopyOnWriteIndexPart getNonNullCow() {
+    if (wr_cow != null) {
+      CopyOnWriteIndexPart n = wr_cow.get();
+      if (n != null) {
+        return n;
+      }
+    }
+    
+    // null means index updated since iterator was created, need to make new 
cow and use it
+    CopyOnWriteIndexPart n = createCopyOnWriteIndexPart();  //new 
CopyOnWriteObjHashSet<TOP>(index);
+    wr_cow = new WeakReference<>(n);
+    return n;
+  }
+  
+  protected abstract CopyOnWriteIndexPart createCopyOnWriteIndexPart();
+  
+  /**
+   * Called just before modifying an index
+   * if wr_cow has a value, 
+   *   tell that value to create a preserving copy of the index part, and
+   *   set wr_cow to null
+   */
+  protected void maybeCopy() {
+    if (wr_cow != null) {
+      CopyOnWriteIndexPart v = wr_cow.get();
+      if (v != null) {
+        v.makeCopy();
+      }
+      wr_cow = null;
+    }
+  }
+  
+  @Override
+  public void flush() {
+    wr_cow = null;
+  }
+
 }

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java
 Mon Sep 19 20:24:02 2016
@@ -23,7 +23,6 @@ import java.util.NoSuchElementException;
 
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.internal.util.CopyOnWriteObjHashSet;
-import org.apache.uima.internal.util.ObjHashSet;
 import org.apache.uima.jcas.cas.TOP;
 
 class FsIterator_bag<T extends FeatureStructure> extends 
FsIterator_singletype<T> {
@@ -62,6 +61,7 @@ class FsIterator_bag<T extends FeatureSt
     throw new NoSuchElementException();
   }
 
+  @Override
   public T getNvc() {
     checkConcurrentModification();
     return (T) bag.get(position);
@@ -72,7 +72,7 @@ class FsIterator_bag<T extends FeatureSt
    */
   @Override
   public void moveToFirst() {
-    bag = fsBagIndex.getCow();
+    bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
     resetConcurrentModification();
     isGoingForward = true;
     position = (bag.size() == 0) ? -1 : bag.moveToNextFilled(0);
@@ -84,7 +84,7 @@ class FsIterator_bag<T extends FeatureSt
    */
   @Override
   public void moveToLast() {
-    bag = fsBagIndex.getCow();
+    bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
     resetConcurrentModification();
     isGoingForward = false;
     position =  (bag.size() == 0) ? -1 : 
bag.moveToPreviousFilled(bag.getCapacity() -1);
@@ -134,7 +134,7 @@ class FsIterator_bag<T extends FeatureSt
    */
   @Override
   public void moveTo(FeatureStructure fs) {
-    bag = fsBagIndex.getCow();
+    bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
     resetConcurrentModification();
     position = bag.moveTo(fs);
   }

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted.java
 Mon Sep 19 20:24:02 2016
@@ -59,9 +59,7 @@ class FsIterator_set_sorted<T extends Fe
   FsIterator_set_sorted(FsIndex_set_sorted<T> fsSetSortIndex, TypeImpl ti, 
Comparator<FeatureStructure> comp) {
     super(ti, comp);
     this.fsSetSortIndex = fsSetSortIndex;
-    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getCow(); // cast to TOP 
to allow keys outside of range of returned values
-    iterator = (Iterator<T>) navSet.iterator();  // can't use 
fsSortIndex.iterator - that recursively calls this
-    resetConcurrentModification(); // follow create of iterator, which, in 
turn, does any pending batch processing
+    moveToFirst();
   }
 
   @Override
@@ -70,7 +68,7 @@ class FsIterator_set_sorted<T extends Fe
   @Override
   public void moveToFirst() {
 //    fsSetSortIndex.maybeProcessBulkAdds();
-    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getCow();
+    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getNonNullCow();
     iterator = (Iterator<T>) navSet.iterator();  // in case iterator was 
reverse, etc.
     resetConcurrentModification(); // follow create of iterator, which, in 
turn, does any pending batch processing
     isGoingForward = true;
@@ -80,7 +78,7 @@ class FsIterator_set_sorted<T extends Fe
   @Override
   public void moveToLast() {
 //    fsSetSortIndex.maybeProcessBulkAdds();
-    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getCow();
+    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getNonNullCow();
     iterator =  (Iterator<T>) navSet.descendingIterator();
     resetConcurrentModification(); // follow create of iterator, which, in 
turn, does any pending batch processing
     isGoingForward = false;
@@ -195,7 +193,7 @@ class FsIterator_set_sorted<T extends Fe
     isGoingForward = true;
     isCurrentElementFromLastGet = false;
     currentElement = null;   
-    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getCow();
+    this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getNonNullCow();
 //    fsSetSortIndex.maybeProcessBulkAdds();  // not needed, always done due 
to previous size() call when creating iterator    
     Iterator<T> it = (Iterator<T>) navSet.headSet(fs, 
false).descendingIterator();  // may have a bunch of equal (using withoutID 
compare) at end
     // last element in headSet is 1 before the one LE fs.

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java
 Mon Sep 19 20:24:02 2016
@@ -21,12 +21,13 @@ package org.apache.uima.internal.util;
 import java.util.Iterator;
 
 import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.impl.CopyOnWriteIndexPart;
 
 /**
  * implements ObjHashSet partially, for iterator use
  */
 
-public class CopyOnWriteObjHashSet<T> {
+public class CopyOnWriteObjHashSet<T> implements CopyOnWriteIndexPart {
   
   private ObjHashSet<T> ohs;
   
@@ -38,6 +39,7 @@ public class CopyOnWriteObjHashSet<T> {
   /**
    * Called by index when about to make an update
    */
+  @Override
   public void makeCopy() {
     ohs = new ObjHashSet<>(ohs);
   }

Modified: 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java?rev=1761499&r1=1761498&r2=1761499&view=diff
==============================================================================
--- 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java
 (original)
+++ 
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java
 Mon Sep 19 20:24:02 2016
@@ -28,6 +28,7 @@ import java.util.function.Consumer;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
+import org.apache.uima.cas.impl.CopyOnWriteIndexPart;
 import org.apache.uima.jcas.cas.TOP;
 
 /**
@@ -35,7 +36,7 @@ import org.apache.uima.jcas.cas.TOP;
  * Delegates generated by Eclipse
  */
 
-public class CopyOnWriteOrderedFsSet_array implements NavigableSet<TOP> {
+public class CopyOnWriteOrderedFsSet_array implements NavigableSet<TOP>, 
CopyOnWriteIndexPart {
   
   private OrderedFsSet_array set;
   
@@ -50,6 +51,7 @@ public class CopyOnWriteOrderedFsSet_arr
   /**
    * Called by index when about to make an update
    */
+  @Override
   public void makeCopy() {
     set = new OrderedFsSet_array(set);
   }
@@ -58,6 +60,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @param action
    * @see java.lang.Iterable#forEach(java.util.function.Consumer)
    */
+  @Override
   public void forEach(Consumer<? super TOP> action) {
     set.forEach(action);
   }
@@ -66,6 +69,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see java.lang.Object#hashCode()
    */
+  @Override
   public int hashCode() {
     return set.hashCode();
   }
@@ -75,6 +79,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see java.lang.Object#equals(java.lang.Object)
    */
+  @Override
   public boolean equals(Object obj) {
     return set.equals(obj);
   }
@@ -83,6 +88,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#comparator()
    */
+  @Override
   public Comparator<? super TOP> comparator() {
     return set.comparator();
   }
@@ -91,6 +97,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#first()
    */
+  @Override
   public TOP first() {
     return set.first();
   }
@@ -99,6 +106,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#last()
    */
+  @Override
   public TOP last() {
     return set.last();
   }
@@ -107,6 +115,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#size()
    */
+  @Override
   public int size() {
     return set.size();
   }
@@ -115,6 +124,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#isEmpty()
    */
+  @Override
   public boolean isEmpty() {
     return set.isEmpty();
   }
@@ -124,6 +134,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#contains(java.lang.Object)
    */
+  @Override
   public boolean contains(Object o) {
     return set.contains(o);
   }
@@ -132,6 +143,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#toArray()
    */
+  @Override
   public Object[] toArray() {
     return set.toArray();
   }
@@ -141,6 +153,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#toArray(java.lang.Object[])
    */
+  @Override
   public <T> T[] toArray(T[] a1) {
     return set.toArray(a1);
   }
@@ -150,6 +163,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#add(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public boolean add(TOP fs) {
     return set.add(fs);
   }
@@ -158,6 +172,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see java.util.SortedSet#spliterator()
    */
+  @Override
   public Spliterator<TOP> spliterator() {
     return set.spliterator();
   }
@@ -167,6 +182,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see java.util.Collection#removeIf(java.util.function.Predicate)
    */
+  @Override
   public boolean removeIf(Predicate<? super TOP> filter) {
     return set.removeIf(filter);
   }
@@ -175,6 +191,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see java.util.Collection#stream()
    */
+  @Override
   public Stream<TOP> stream() {
     return set.stream();
   }
@@ -183,6 +200,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see java.util.Collection#parallelStream()
    */
+  @Override
   public Stream<TOP> parallelStream() {
     return set.parallelStream();
   }
@@ -192,6 +210,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#remove(java.lang.Object)
    */
+  @Override
   public boolean remove(Object o) {
     return set.remove(o);
   }
@@ -201,6 +220,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#containsAll(java.util.Collection)
    */
+  @Override
   public boolean containsAll(Collection<?> c) {
     return set.containsAll(c);
   }
@@ -210,6 +230,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#addAll(java.util.Collection)
    */
+  @Override
   public boolean addAll(Collection<? extends TOP> c) {
     return set.addAll(c);
   }
@@ -219,6 +240,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#retainAll(java.util.Collection)
    */
+  @Override
   public boolean retainAll(Collection<?> c) {
     return set.retainAll(c);
   }
@@ -228,6 +250,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#removeAll(java.util.Collection)
    */
+  @Override
   public boolean removeAll(Collection<?> c) {
     return set.removeAll(c);
   }
@@ -236,6 +259,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * 
    * @see org.apache.uima.internal.util.OrderedFsSet_array#clear()
    */
+  @Override
   public void clear() {
     set.clear();
   }
@@ -245,6 +269,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#lower(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public TOP lower(TOP fs) {
     return set.lower(fs);
   }
@@ -263,6 +288,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#floor(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public TOP floor(TOP fs) {
     return set.floor(fs);
   }
@@ -281,6 +307,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#ceiling(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public TOP ceiling(TOP fs) {
     return set.ceiling(fs);
   }
@@ -299,6 +326,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#higher(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public TOP higher(TOP fs) {
     return set.higher(fs);
   }
@@ -316,6 +344,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#pollFirst()
    */
+  @Override
   public TOP pollFirst() {
     return set.pollFirst();
   }
@@ -324,6 +353,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#pollLast()
    */
+  @Override
   public TOP pollLast() {
     return set.pollLast();
   }
@@ -332,6 +362,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#iterator()
    */
+  @Override
   public Iterator<TOP> iterator() {
     return set.iterator();
   }
@@ -340,6 +371,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#descendingSet()
    */
+  @Override
   public NavigableSet<TOP> descendingSet() {
     return set.descendingSet();
   }
@@ -348,6 +380,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#descendingIterator()
    */
+  @Override
   public Iterator<TOP> descendingIterator() {
     return set.descendingIterator();
   }
@@ -360,6 +393,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#subSet(org.apache.uima.jcas.cas.TOP,
 boolean, org.apache.uima.jcas.cas.TOP, boolean)
    */
+  @Override
   public NavigableSet<TOP> subSet(TOP fromElement, boolean fromInclusive, TOP 
toElement,
       boolean toInclusive) {
     return set.subSet(fromElement, fromInclusive, toElement, toInclusive);
@@ -371,6 +405,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#headSet(org.apache.uima.jcas.cas.TOP,
 boolean)
    */
+  @Override
   public NavigableSet<TOP> headSet(TOP toElement, boolean inclusive) {
     return set.headSet(toElement, inclusive);
   }
@@ -381,6 +416,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#tailSet(org.apache.uima.jcas.cas.TOP,
 boolean)
    */
+  @Override
   public NavigableSet<TOP> tailSet(TOP fromElement, boolean inclusive) {
     return set.tailSet(fromElement, inclusive);
   }
@@ -391,6 +427,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#subSet(org.apache.uima.jcas.cas.TOP,
 org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public SortedSet<TOP> subSet(TOP fromElement, TOP toElement) {
     return set.subSet(fromElement, toElement);
   }
@@ -400,6 +437,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#headSet(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public SortedSet<TOP> headSet(TOP toElement) {
     return set.headSet(toElement);
   }
@@ -409,6 +447,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see 
org.apache.uima.internal.util.OrderedFsSet_array#tailSet(org.apache.uima.jcas.cas.TOP)
    */
+  @Override
   public SortedSet<TOP> tailSet(TOP fromElement) {
     return set.tailSet(fromElement);
   }
@@ -425,6 +464,7 @@ public class CopyOnWriteOrderedFsSet_arr
    * @return
    * @see org.apache.uima.internal.util.OrderedFsSet_array#toString()
    */
+  @Override
   public String toString() {
     return set.toString();
   }


Reply via email to