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/10/07 18:56:18 UTC

svn commit: r1763809 - in /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src: main/java/org/apache/uima/cas/impl/ main/java/org/apache/uima/jcas/ test/java/org/apache/uima/cas/test/

Author: schor
Date: Fri Oct  7 18:56:18 2016
New Revision: 1763809

URL: http://svn.apache.org/viewvc?rev=1763809&view=rev
Log:
[UIMA-5115] add support for covering, including an optimization using the max span information if available. Expand the annotatorIterator test case 

Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java
    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_iicp.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/FsIndex_snapshot.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_allViews.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.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_limited.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/cas/impl/FsIterator_subtypes.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java Fri Oct  7 18:56:18 2016
@@ -125,63 +125,9 @@ public class FsIndex_annotation <T exten
     }
   }
 
-//  /* ***********************************
-//   *  Support for withSnapshotIterators
-//   *  using proxy
-//   * ***********************************/
-//  private final static Class<?>[] proxyInterface = new Class<?>[] {FsIndex_annotation.class};
-//  
-//  private class ProxySnapshotHandler implements InvocationHandler {
-//    @Override
-//    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-//      if ("iterator".equals(method.getName())) {
-//        if (args == null || args.length == 0) {
-//          if (fsIndex_singletype.getIndexingStrategy() == FSIndex.SORTED_INDEX) {
-//            return iterator(IteratorExtraFunction.SNAPSHOT);
-//          }
-//          return iterator(IteratorExtraFunction.UNORDERED_SNAPSHOT);
-//        }
-//        // iterator call with an arg boolean ambiguous
-//        // TODO ambiguous/unambig with snapshot
-//      }
-//      
-//      // pass thru all other methods
-//      return method.invoke(args);
-//    }    
-//  }
-
   @Override
   public FSIndex<T> withSnapshotIterators() {
     return new FsIndex_snapshot<>(this);
   }
-//  public FSIndex<T> withSnapshotIterators() {
-//    return (FSIndex<T>) Proxy.newProxyInstance(
-//        FSIndex.class.getClassLoader(),  // class loader 
-//        proxyInterface,  
-//        new ProxySnapshotHandler());
-//  }
   
-  /*********************************************************
-   * Stream / SplitIterator support
-   * 
-   * Use:
-   *   myAnnotIndex.annotStream()
-   *      .reverse()
-   *      .boundedBy(fs)
-   *      .strict()
-   *      .unambiguous()
-   *      .noTypePriorities()
-   *      .stream()  // or   .splititerator()
-   *         ... stream operations;
-   *         
-   *********************************************************/
-//  public AnnotStream<T> annotStream() {
-//    return new AnnotStream<T>(this.fsIndex_singletype);
-//  }
-//  
-//  public Stream<T extends TOP> stream() {
-//    return StreamSupport.stream(, parallel)
-//    
-//  }
-//  
-}
+ }

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=1763809&r1=1763808&r2=1763809&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 Fri Oct  7 18:56:18 2016
@@ -216,6 +216,11 @@ public class FsIndex_bag<T extends Featu
     return new CopyOnWriteObjHashSet<TOP>(index);
   }
   
+  @Override
+  public int ll_maxAnnotSpan() {
+    return Integer.MAX_VALUE;
+  }
+  
 //  ObjHashSet<TOP> getObjHashSet() {
 //    return index;
 //  } 

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=1763809&r1=1763808&r2=1763809&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 Fri Oct  7 18:56:18 2016
@@ -45,6 +45,8 @@ public class FsIndex_flat<T extends Feat
   final private FsIndex_iicp<T> iicp;
   
   final private Comparator<FeatureStructure> comparator;
+  
+  final private int maxAnnotSpan;
     
   FsIndex_flat(FsIndex_iicp<T> iicp) {
     super(iicp.getCasImpl(), iicp.fsIndex_singletype.getType(), iicp.fsIndex_singletype.getIndexingStrategy(),
@@ -52,6 +54,7 @@ public class FsIndex_flat<T extends Feat
     this.iicp = iicp;
     indexedFSs = fillFlatArray();
     comparator = iicp.fsIndex_singletype;
+    maxAnnotSpan = iicp.ll_maxAnnotSpan();
   }  
   
   /**
@@ -193,6 +196,10 @@ public class FsIndex_flat<T extends Feat
     Misc.internalError(); // should never be called
   }
   
+  @Override
+  public int ll_maxAnnotSpan() {
+    return maxAnnotSpan;
+  }
   
 
 }

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java Fri Oct  7 18:56:18 2016
@@ -240,6 +240,21 @@ class FsIndex_iicp<T extends FeatureStru
     return size;
   }
   
+  public int ll_maxAnnotSpan() {
+    createIndexIteratorCache();  // does nothing if already created
+    int span = -1;
+    FsIndex_singletype<T> idx = getFsIndex_singleType();
+    if (idx instanceof FsIndex_set_sorted && ((FsIndex_set_sorted)idx).isAnnotIdx) {
+      for (FsIndex_singletype<FeatureStructure> subIndex : cachedSubFsLeafIndexes) {
+        int s = ((FsIndex_set_sorted)subIndex).ll_maxAnnotSpan(); 
+        if (s > span) {
+          span = s;
+        }
+      }
+    }
+    return (span == -1) ? Integer.MAX_VALUE : span;
+  }
+  
   public boolean isEmpty() {
     createIndexIteratorCache();  
     for (FsIndex_singletype<FeatureStructure> index : cachedSubFsLeafIndexes) {

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=1763809&r1=1763808&r2=1763809&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 Fri Oct  7 18:56:18 2016
@@ -32,6 +32,7 @@ import org.apache.uima.cas.admin.FSIndex
 import org.apache.uima.internal.util.CopyOnWriteOrderedFsSet_array;
 import org.apache.uima.internal.util.OrderedFsSet_array;
 import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.jcas.tcas.Annotation;
 
 /**
  * Common index impl for set and sorted indexes.
@@ -55,83 +56,19 @@ public class FsIndex_set_sorted<T extend
 //   * This impl of sorted set interface allows using the bulk add operation implemented in Java's 
 //   * TreeSet - that tests if the argument being passed in is an instance of SortedSet and does a fast insert.
 //   */
-//  final private SortedSet<T> ss = new SortedSet<T>() {
-//    
-//    @Override
-//    public int size() { return itemsToBeAdded.size(); }
-//    @Override
-//    public boolean isEmpty() { return false; }
-//    @Override
-//    public boolean contains(Object o) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public Iterator<T> iterator() { return itemsToBeAdded.iterator(); }
-//    @Override
-//    public Object[] toArray() { throw new UnsupportedOperationException(); }
-//    @Override
-//    public <U> U[] toArray(U[] a) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public boolean add(T e) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public boolean remove(Object o) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public boolean addAll(Collection<? extends T> c) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public void clear() { throw new UnsupportedOperationException(); }
-//    @Override
-//    public Comparator<? super T> comparator() { return (Comparator<? super T>) comparatorWithID; }
-//    @Override
-//    public SortedSet<T> subSet(FeatureStructure fromElement, FeatureStructure toElement) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public SortedSet<T> headSet(FeatureStructure toElement) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public SortedSet<T> tailSet(FeatureStructure fromElement) { throw new UnsupportedOperationException(); }
-//    @Override
-//    public T first() { throw new UnsupportedOperationException(); }
-//    @Override
-//    public T last() { throw new UnsupportedOperationException(); }  
-//    
-//    
-//  };
 
 
   // The index, a NavigableSet. 
-//  final private TreeSet<FeatureStructure> indexedFSs;
-//  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;
     
   final private Comparator<TOP> comparatorWithID;
   final private Comparator<TOP> comparatorWithoutID;
   
-//  final private Comparator<Object> comparatorO;
-  
-  // batching of adds
-//  final private ArrayList<T> itemsToBeAdded = new ArrayList<>();  // to batch the adds
-//  final private MethodHandle getItemsToBeAddedArray = Misc.getProtectedFieldGetter(ArrayList.class, "elementData");
-//
-//  private long lastTrimToSizeTime = System.nanoTime();
-  
-//  private T largestItemNotYetAdded = null;
-   
+  // only an optimization used for select.covering for AnnotationIndexes
+  private int maxAnnotSpan = -1;
+  public final boolean isAnnotIdx;
+     
   FsIndex_set_sorted(CASImpl cas, Type type, int indexType, FSIndexComparator comparatorForIndexSpecs, boolean useSorted) {
     super(cas, type, indexType, comparatorForIndexSpecs);
     FSIndexRepositoryImpl ir = this.casImpl.indexRepository;
@@ -139,7 +76,9 @@ public class FsIndex_set_sorted<T extend
     if (ir.isAnnotationIndex(comparatorForIndexSpecs, indexType)) {
       comparatorWithID = ir.getAnnotationFsComparatorWithId(); 
       comparatorWithoutID = ir.getAnnotationFsComparator();
+      isAnnotIdx = true;
     } else {
+      isAnnotIdx = false;
       comparatorWithoutID = (o1, o2) -> compare(o1,  o2);
       comparatorWithID = useSorted   
           ? (o1, o2) -> {
@@ -148,23 +87,6 @@ public class FsIndex_set_sorted<T extend
               return (c == 0) ? (Integer.compare(o1._id(), o2._id())) : c;} 
           : comparatorWithoutID;
     }          
-//    comparatorO = new Comparator() {
-//
-//      @Override
-//      public int compare(Object o1, Object o2) {
-//        return comparator.compare((FeatureStructure)o1, (FeatureStructure)o2);
-//      }
-//      
-//    };
-
-//    this.indexedFSs = new TreeSet<FeatureStructure>(comparator);
-//    Comparator<TOP> c = new Comparator<TOP>() {
-//
-//      @Override
-//      public int compare(TOP o1, TOP o2) {
-//        return comparatorWithID.compare(o1, o2);
-//      }      
-//    };
     
     this.indexedFSs = new OrderedFsSet_array(comparatorWithID, comparatorWithoutID);
   }
@@ -173,8 +95,6 @@ public class FsIndex_set_sorted<T extend
   public void flush() {
     super.flush();
     this.indexedFSs.clear();
-//    this.itemsToBeAdded.clear();
-//    this.largestItemNotYetAdded = null;
   }
 
   /**
@@ -194,38 +114,15 @@ public class FsIndex_set_sorted<T extend
   @Override
   void insert(T fs) {
     
-//    /**
-//     * The implementation tries for speedup for the initial loading of the treeset
-//     *   Taking advantage of the bulk addAll optimization implemented in TreeSet when the 
-//     *      items being added are sorted, and the tree set is initially empty
-//     */
-//    // measured - not efficient.
-//    if (indexedFSs.size() > 1024) {
-//      // optimize for insert at end
-//      TOP last = indexedFSs.last();
-//      if (indexedFSs.comparator().compare(last, fs) <= 0) {
-//        // insert at end fast path maybe
-//        return indexedFSs.tailSet(last, true).add(fs);
-//      }
-//    }
-//    if (indexedFSs.isEmpty()) {
-//      if (largestItemNotYetAdded == null ||
-//          comparatorWithID.compare((TOP)fs,  (TOP)largestItemNotYetAdded) > 0) {
-//        // batch the add
-//        itemsToBeAdded.add(fs);
-//        largestItemNotYetAdded = fs;
-//        return;
-//      }       
-////      maybeProcessBulkAdds(); // moved to OrderedFsSet_array class
-//    }
-//    
     // past the initial load, or item is not > previous largest item to be added 
     maybeCopy();
+    if (isAnnotIdx) {
+      int span = ((Annotation)fs).getEnd() - ((Annotation)fs).getBegin();
+      if (span > maxAnnotSpan) {
+        maxAnnotSpan = span;
+      }
+    }
     indexedFSs.add((TOP)fs);
-//    // batch this add 
-//    largestItemNotYetAdded = fs;
-//    itemsToBeAdded.add(fs);
-//    return true;
   }
 
   /**
@@ -248,7 +145,6 @@ public class FsIndex_set_sorted<T extend
    */
   @Override
   public T find(FeatureStructure templateKey) {
-//    maybeProcessBulkAdds(); // moved to OrderedFsSet_array class
     if (null == templateKey || this.indexedFSs.isEmpty()) {
       return null;
     }
@@ -281,7 +177,6 @@ public class FsIndex_set_sorted<T extend
   }
 
   public T findLeftmost(TOP templateKey) {
-//    maybeProcessBulkAdds(); // moved to OrderedFsSet_array class
     // descending iterator over elements LessThan templateKey
     // iterator is over TOP, not T, to make compare easier
     Iterator<TOP> it = indexedFSs.headSet(templateKey, false).descendingIterator();
@@ -330,17 +225,11 @@ public class FsIndex_set_sorted<T extend
   
   @Override
   protected void bulkAddTo(List<T> v) {
-//    maybeProcessBulkAdds(); // moved to OrderedFsSet_array class
     v.addAll((Collection<? extends T>) indexedFSs);
   }
   
-//  @Override
-//  protected void bulkAddTo(IntVector v) {
-//    this.indexedFSs.stream().mapToInt(fs -> ((FeatureStructureImplC)fs).id()).forEach(v::add);
-//  }
   
   NavigableSet<T> getNavigableSet() { //used by FsIterator_set_sorted to compute various derivitive nav sets
-//    maybeProcessBulkAdds(); // moved to OrderedFsSet_array class
     return (NavigableSet<T>) indexedFSs;
   }
    
@@ -357,69 +246,7 @@ public class FsIndex_set_sorted<T extend
     return new CopyOnWriteOrderedFsSet_array(indexedFSs);
   }
   
-//  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();
-//    if (sz > 0) {
-//      
-//      // debug
-//  //    if (sz > 1) {
-//  //      TOP prev = itemsToBeAdded.get(0);
-//  //      for (int i = 1; i < sz; i++) {
-//  //        TOP next = itemsToBeAdded.get(i);
-//  //        if (comparator.compare(next,  prev) <= 0) {
-//  //          System.out.println("debug");
-//  //        }
-//  //        prev = next;
-//  //      }
-//  //    }
-////      Object[] tba;
-////      try {
-////        tba =  (Object[])getItemsToBeAddedArray.invokeExact(itemsToBeAdded);
-////      } catch (Throwable e) {
-////        Misc.internalError(e);  // always throws
-////        return;  // only to get rid of compile issue
-////      }
-////      if (sz > 100) {
-////        Arrays.sort(tba, 0, sz, comparatorO);
-////      } else {
-////        Arrays.sort(tba, 0, sz, comparatorO);
-////      }
-////      
-////      FeatureStructure prev = null;
-////      indexedFSs.addAll(ss);
-//      for (FeatureStructure fs : itemsToBeAdded) {
-////        if (fs != prev) { // the itemsToBeAdded may contain duplicates
-//          indexedFSs.add((TOP)fs);   
-////          prev = fs;
-////        }
-//      }
-//      itemsToBeAdded.clear();
-//      itemsToBeAdded.trimToSize();
-//    }
-//  }  
+  public int ll_maxAnnotSpan() {
+    return maxAnnotSpan;
+  }
 }

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=1763809&r1=1763808&r2=1763809&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 Fri Oct  7 18:56:18 2016
@@ -426,7 +426,5 @@ public abstract class FsIndex_singletype
     wr_cow = null;
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.uima.cas.FSIndex#select()
-   */
+
 }

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java Fri Oct  7 18:56:18 2016
@@ -121,4 +121,8 @@ public class FsIndex_snapshot <T extends
     return wrapped.getComparatorForIndexSpecs();
   }
 
+  @Override
+  public int ll_maxAnnotSpan() {
+    return wrapped.ll_maxAnnotSpan();
+  }
 }

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java Fri Oct  7 18:56:18 2016
@@ -193,6 +193,19 @@ class FsIterator_aggregation_common<T ex
     }
     return sum;
   }
+  
+  
+  public int ll_maxAnnotSpan() {
+    int span = -1;
+    for (int i = iterators.length - 1; i >=  0; i--) {
+      FSIterator<T> it = iterators[i];
+      int x = ((LowLevelIterator<T>)it).ll_maxAnnotSpan();
+      if (x > span) {
+        span = x;
+      }
+    }
+    return (span == -1) ? Integer.MAX_VALUE : span;
+  };
 
   /* (non-Javadoc)
    * @see org.apache.uima.cas.FSIterator#copy()

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_allViews.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_allViews.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_allViews.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_allViews.java Fri Oct  7 18:56:18 2016
@@ -169,6 +169,11 @@ public class FsIterator_allViews<T exten
     // TODO Auto-generated method stub
     return 0;
   }
+  
+  @Override
+  public int ll_maxAnnotSpan() {
+    return Integer.MAX_VALUE;
+  }
 
   /* (non-Javadoc)
    * @see org.apache.uima.cas.impl.LowLevelIterator#ll_getIndex()

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java Fri Oct  7 18:56:18 2016
@@ -37,50 +37,67 @@ class FsIterator_backwards<T extends Fea
     it.moveToLast();
   }
 
+  @Override
   public int ll_indexSize() {
     return it.ll_indexSize();
   }
 
+  @Override
+  public int ll_maxAnnotSpan() {
+    return it.ll_maxAnnotSpan();
+  }
+  
+  @Override
   public LowLevelIndex<T> ll_getIndex() {
     return it.ll_getIndex();
   }
 
+  @Override
   public boolean isValid() {
     return it.isValid();
   }
 
+  @Override
   public T get() throws NoSuchElementException {
     return it.get();
   }
 
+  @Override
   public T getNvc() {
     return it.getNvc();
   }
 
+  @Override
   public void moveToNext() {
     it.moveToPrevious();
   }
 
+  @Override
   public void moveToNextNvc() {
     it.moveToPreviousNvc();
   }
 
+  @Override
   public void moveToPrevious() {
     it.moveToNext();
   }
 
+  @Override
   public void moveToPreviousNvc() {
     it.moveToNextNvc();
   }
 
+  @Override
   public void moveToFirst() {
     it.moveToLast();
   }
 
+  @Override
   public void moveToLast() {
     it.moveToFirst();
   }
 
+  @Override
   public void moveTo(FeatureStructure fs) {
     it.moveTo(fs);  // moves to left most of equal, or one greater
     LowLevelIndex<T> lli = ll_getIndex();
@@ -108,6 +125,7 @@ class FsIterator_backwards<T extends Fea
     }
   }
 
+  @Override
   public FSIterator<T> copy() {
     return new FsIterator_backwards<T>(it.copy());
   }

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=1763809&r1=1763808&r2=1763809&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 Fri Oct  7 18:56:18 2016
@@ -156,11 +156,17 @@ class FsIterator_bag<T extends FeatureSt
 
   /* (non-Javadoc)
    * @see org.apache.uima.cas.impl.LowLevelIterator#ll_indexSize()
-   */  @Override
+   */  
+  @Override
   public int ll_indexSize() {
     return bag.size();
   }
 
+  @Override
+  public int ll_maxAnnotSpan() {
+    return Integer.MAX_VALUE;
+  }
+
   /* (non-Javadoc)
    * @see org.apache.uima.cas.impl.LowLevelIterator#ll_getIndex()
    */

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java Fri Oct  7 18:56:18 2016
@@ -110,6 +110,11 @@ class FsIterator_limited<T extends Featu
   }
 
   @Override
+  public int ll_maxAnnotSpan() {
+    return iterator.ll_maxAnnotSpan();
+  }
+
+  @Override
   public LowLevelIndex<T> ll_getIndex() {
     return iterator.ll_getIndex();
   }

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=1763809&r1=1763808&r2=1763809&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 Fri Oct  7 18:56:18 2016
@@ -237,6 +237,14 @@ class FsIterator_set_sorted<T extends Fe
     return navSet.size();
   }
   
+
+  @Override
+  public int ll_maxAnnotSpan() {
+    return fsSetSortIndex.isAnnotIdx 
+        ?   fsSetSortIndex.ll_maxAnnotSpan()
+        : Integer.MAX_VALUE;
+  }
+
   @Override
   public LowLevelIndex<T> ll_getIndex() {
     return fsSetSortIndex;

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes.java Fri Oct  7 18:56:18 2016
@@ -41,7 +41,7 @@ public abstract class FsIterator_subtype
   
   @Override
   public LowLevelIndex<T> ll_getIndex() {
-    return iicp.fsIndex_singletype;
+    return iicp;
   }
 
   /* (non-Javadoc)
@@ -49,9 +49,14 @@ public abstract class FsIterator_subtype
    */
   @Override
   public int ll_indexSize() {
-    return ll_getIndex().size();
+    return iicp.size();
   }
-  
+
+  @Override
+  public int ll_maxAnnotSpan() {
+    return iicp.ll_maxAnnotSpan();
+  }
+
   @Override
   public String toString() {
     TypeImpl type = (TypeImpl) this.ll_getIndex().getType();

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java Fri Oct  7 18:56:18 2016
@@ -80,4 +80,19 @@ public abstract class FsIterator_subtype
     return sz;
   }
   
+  @Override
+  public int ll_maxAnnotSpan() {
+    int span = -1;
+    for (FsIterator_singletype<T> it : iterators) {
+      int s = ((LowLevelIterator)it).ll_maxAnnotSpan();
+      if (s == Integer.MAX_VALUE) {
+        return s;
+      }
+      if (s > span) {
+        span = s;
+      }
+    }
+    return (span == -1) ? Integer.MAX_VALUE : span;
+  }
+  
 }

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java Fri Oct  7 18:56:18 2016
@@ -170,6 +170,11 @@ public class FsIterator_subtypes_snapsho
   public int ll_indexSize() {
     return snapshot.length;
   }
+  
+  @Override
+  public int ll_maxAnnotSpan() {
+    return indexForComparator.ll_maxAnnotSpan();   
+  }
 
   /* (non-Javadoc)
    * @see org.apache.uima.cas.impl.LowLevelIterator#ll_getIndex()

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java Fri Oct  7 18:56:18 2016
@@ -113,6 +113,13 @@ public interface LowLevelIndex<T extends
     return getCasImpl().indexRepository.getIndexBySpec(ti.getCode(), getIndexingStrategy(), (FSIndexComparatorImpl) getComparatorForIndexSpecs());
   }
 
+  /**
+   * @return for annotation indexes, an conservative estimate the maximum span between begin and end
+   * The value may be larger than actual.
+   */
+  int ll_maxAnnotSpan();  
+  
+  
   @Override
   default SelectFSs<T> select() {
     return getCasImpl().select().index(this);
@@ -138,5 +145,4 @@ public interface LowLevelIndex<T extends
     return select().type(fullyQualifiedTypeName);
   }
   
-  
 }

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java Fri Oct  7 18:56:18 2016
@@ -73,6 +73,11 @@ public interface LowLevelIterator<T exte
   LowLevelIndex<T> ll_getIndex();
   
   /**
+   * @return an estimate of the maximum span over all annotations (end - begin)
+   */
+  int ll_maxAnnotSpan();
+  
+  /**
    * an empty iterator
    */
   static final LowLevelIterator<FeatureStructure> FS_ITERATOR_LOW_LEVEL_EMPTY = new LowLevelIterator<FeatureStructure> () {
@@ -103,6 +108,8 @@ public interface LowLevelIterator<T exte
     @Override
     public int ll_indexSize() { return 0; }
     @Override
+    public int ll_maxAnnotSpan() { return Integer.MAX_VALUE; }
+    @Override
     public LowLevelIndex<FeatureStructure> ll_getIndex() { return null; }    
   };
 }

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java Fri Oct  7 18:56:18 2016
@@ -336,7 +336,7 @@ public class SelectFSs_impl <T extends F
   } 
   @Override
   public SelectFSs_impl<T> startAt(int begin, int end) {  // AI
-    this.startingFs = new Annotation(jcas, begin, end);
+    this.startingFs = makePosAnnot(begin, end);
     return this;
   } 
   
@@ -348,7 +348,7 @@ public class SelectFSs_impl <T extends F
   } 
   @Override
   public SelectFSs_impl<T> startAt(int begin, int end, int offset) {  // AI
-    this.startingFs = new Annotation(jcas, begin, end);
+    this.startingFs = makePosAnnot(begin, end);
     this.shift = offset;
     return this;
   }  
@@ -373,7 +373,7 @@ public class SelectFSs_impl <T extends F
   @Override
   public SelectFSs_impl<T> coveredBy(int begin, int end) {       // AI
     boundsUse = BoundsUse.coveredBy;
-    this.boundingFs = new Annotation(jcas, begin, end);
+    this.boundingFs = makePosAnnot(begin, end);
     this.isEndWithinBounds = true; //default
     return this;
   }
@@ -388,15 +388,14 @@ public class SelectFSs_impl <T extends F
   @Override
   public SelectFSs_impl<T> covering(int begin, int end) {      // AI
     boundsUse = BoundsUse.covering;
-    this.boundingFs = new Annotation(jcas, begin, end);
+    this.boundingFs = makePosAnnot(begin, end);
     return this;
   }
 
   @Override
   public SelectFSs_impl<T> between(AnnotationFS fs1, AnnotationFS fs2) {   // AI
     final boolean reverse = fs1.getEnd() > fs2.getBegin();
-    this.boundingFs = new Annotation(
-        jcas, 
+    this.boundingFs = makePosAnnot(
         (reverse ? fs2 : fs1).getEnd(), 
         (reverse ? fs1 : fs2).getBegin());
     this.boundsUse = BoundsUse.coveredBy;
@@ -420,7 +419,7 @@ public class SelectFSs_impl <T extends F
    */
   @Override
   public SelectFSs<T> at(int begin, int end) {
-    return at(new Annotation(jcas, begin, end));
+    return at(makePosAnnot(begin, end));
   }
 
   private String maybeMsgPosition() {
@@ -733,6 +732,14 @@ public class SelectFSs_impl <T extends F
     FeatureStructure[] r = (FeatureStructure[]) Array.newInstance(FeatureStructure.class,  al.size());
     return al.toArray(r);
   }
+  
+  private Annotation makePosAnnot(int begin, int end) {
+    if (end < begin) {
+      throw new IllegalArgumentException("End value must be >= Begin value");
+    }
+    return new Annotation(jcas, begin, end);
+  }
+  
   /**
    * Iterator respects backwards
    * 
@@ -755,9 +762,12 @@ public class SelectFSs_impl <T extends F
 
       private final FSIterator<T> it = fsIterator();
       
+      private final FSIndex<T> localIndex = index;
+      
       private final Comparator<? super T> comparator = 
-          (index != null && index.getIndexingStrategy() == FSIndex.SORTED_INDEX) 
-            ? (Comparator<? super T>)index : null;
+          (localIndex != null && localIndex.getIndexingStrategy() == FSIndex.SORTED_INDEX) 
+            ? (Comparator<? super T>)localIndex 
+            : null;
                                                           
       private final int characteristics;
       { // set the characteristics and comparator
@@ -769,7 +779,7 @@ public class SelectFSs_impl <T extends F
         }
         
         // set per indexing strategy
-        switch ((null == index) ? -1 : index.getIndexingStrategy()) {
+        switch ((null == localIndex) ? -1 : localIndex.getIndexingStrategy()) {
         case FSIndex.SORTED_INDEX: c |= Spliterator.ORDERED | Spliterator.SORTED; break;
         case FSIndex.SET_INDEX: c |= Spliterator.ORDERED; break;
         default: // do nothing
@@ -797,7 +807,7 @@ public class SelectFSs_impl <T extends F
 
       @Override
       public long estimateSize() {
-        return ((characteristics & Spliterator.SIZED) == Spliterator.SIZED) ? index.size() : Long.MAX_VALUE;
+        return ((characteristics & Spliterator.SIZED) == Spliterator.SIZED) ? localIndex.size() : Long.MAX_VALUE;
       }
 
       @Override
@@ -807,7 +817,13 @@ public class SelectFSs_impl <T extends F
 
       @Override
       public Comparator<? super T> getComparator() {
-        return (comparator == null) ? Spliterator.super.getComparator() : comparator;
+        if (comparator != null) {
+          return comparator;
+        }
+        if ((characteristics & Spliterator.SORTED) == Spliterator.SORTED) {
+          return null;
+        }
+        throw new IllegalStateException();
       }
     };
   }
@@ -1050,7 +1066,7 @@ public class SelectFSs_impl <T extends F
    */
   @Override
   public SelectFSs<T> following(int begin, int end) {
-    return commonFollowing(new Annotation(jcas, begin, end), 0);
+    return commonFollowing(makePosAnnot(begin, end), 0);
   }
 
   /* (non-Javadoc)
@@ -1066,7 +1082,7 @@ public class SelectFSs_impl <T extends F
    */
   @Override
   public SelectFSs<T> following(int begin, int end, int offset) {
-    return commonFollowing(new Annotation(jcas, begin, end), offset);
+    return commonFollowing(makePosAnnot(begin, end), offset);
   }
 
   /* (non-Javadoc)
@@ -1082,7 +1098,7 @@ public class SelectFSs_impl <T extends F
    */
   @Override
   public SelectFSs<T> preceding(int begin, int end) {
-    return commonPreceding(new Annotation(jcas, begin, end), 0);
+    return commonPreceding(makePosAnnot(begin, end), 0);
   }
 
   /* (non-Javadoc)
@@ -1098,7 +1114,7 @@ public class SelectFSs_impl <T extends F
    */
   @Override
   public SelectFSs<T> preceding(int begin, int end, int offset) {
-    return commonPreceding(new Annotation(jcas, begin, end), offset);
+    return commonPreceding(makePosAnnot(begin, end), offset);
   }
 
    
@@ -1253,7 +1269,7 @@ public class SelectFSs_impl <T extends F
 
   @Override
   public void forEachOrdered(Consumer<? super T> action) {
-    forEachOrdered(action);
+    stream().forEachOrdered(action);
   }
 
   @Override

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java Fri Oct  7 18:56:18 2016
@@ -92,7 +92,10 @@ public class Subiterator<T extends Annot
   
   private final Annotation boundingAnnot;  // the bounding annotation need not be a subtype of T
   
-  private final boolean isAmbiguous;
+  private final Annotation coveringStartPos;
+  private final Annotation coveringEndPos;  // an approx end position
+  
+  private final boolean isAmbiguous;  // true means ordinary, false means to skip until start is past prev end
   private final boolean isStrict;
   private final boolean isBounded;
   private final boolean isTypePriority;
@@ -145,11 +148,10 @@ public class Subiterator<T extends Annot
       ) {
     this.it = (FSIterator<Annotation>) it;
     this.boundingAnnot = (Annotation) boundingAnnot;
-    this.isBounded = boundsUse != null;
+    this.isBounded = boundsUse != null && boundsUse != BoundsUse.notBounded;
     this.boundsUse = (boundsUse == null) ? BoundsUse.notBounded : boundsUse;
     this.isAmbiguous = ambiguous;
     this.isStrict = strict;
-    this.isTypePriority = isTypePriority;
     this.isPositionUsesType = isPositionUsesType;
     this.isSkipEquals = isSkipEquals;
  
@@ -159,13 +161,35 @@ public class Subiterator<T extends Annot
     this.boundBegin = isBounded ? boundingAnnot.getBegin() : -1;
     this.boundEnd = isBounded ? boundingAnnot.getEnd(): -1;
     this.boundType = isBounded ? (TypeImpl) boundingAnnot.getType() : null;
-    
+
+    this.isTypePriority = (boundsUse == BoundsUse.covering) ? false : isTypePriority;
+
     this.annotationComparator = annotationComparator;
-        
+    this.jcas = (JCasImpl) ((LowLevelIterator<T>)it).ll_getIndex().getCasImpl().getJCas();
+    
+    if (boundsUse == BoundsUse.covering) {
+      // compute start position and isEmpty setting
+      int span = ((LowLevelIterator<?>)it).ll_maxAnnotSpan();
+      int begin = boundEnd - span;
+      if (begin > boundBegin) {
+        makeInvalid();
+        coveringStartPos = coveringEndPos = null;
+        isEmpty = true;
+        startId = 0;
+        return;
+      }
+      if (begin < 0) {
+        begin = 0;
+      }
+      coveringStartPos = new Annotation(jcas, begin, Integer.MAX_VALUE);
+      coveringEndPos = new Annotation(jcas, boundBegin + 1, boundBegin + 1);
+    } else {
+      coveringStartPos = coveringEndPos = null;
+    }
+    
     moveToStart();
     isEmpty = !isValid();
     startId = isValid() ? get()._id() : 0;
-    this.jcas = (JCasImpl) ((LowLevelIterator<T>)it).ll_getIndex().getCasImpl().getJCas();
   }
    
   /** 
@@ -191,7 +215,9 @@ public class Subiterator<T extends Annot
       boolean isSkipEquals,
       Comparator<TOP> annotationComparator,
       int startId,
-      boolean isEmpty
+      boolean isEmpty,
+      Annotation coveringStartPos,
+      Annotation coveringEndPos
       ) {
     this.it = it;
     this.boundingAnnot = boundingAnnot;
@@ -211,6 +237,8 @@ public class Subiterator<T extends Annot
     this.annotationComparator = annotationComparator;
     this.isEmpty = isEmpty;
     this.jcas = (JCasImpl) ((LowLevelIterator<T>)it).ll_getIndex().getCasImpl().getJCas();
+    this.coveringStartPos = coveringStartPos;
+    this.coveringEndPos = coveringEndPos;
   }
 
   /**
@@ -233,6 +261,8 @@ public class Subiterator<T extends Annot
   
   private void moveToExact(Annotation targetAnnotation) {
     it.moveTo(targetAnnotation);  // move to left-most equal one
+    boolean found = adjustForTypePriorityBoundingBegin(targetAnnotation._id);
+    if (!found)
     while (it.isValid()) {         // advance to the exact equal one
       if (targetAnnotation._id() == it.getNvc()._id()) {
         break;
@@ -242,32 +272,51 @@ public class Subiterator<T extends Annot
   }
   /**
    * Move to the starting position of the sub iterator
+   * isEmpty may not yet be set
    */
   private void moveToStart() {
     switch (boundsUse) {
     case notBounded:
       it.moveToFirst();
       break;
-    case coveredBy:
     case sameBeginEnd:
       it.moveTo(boundingAnnot);
-      adjustForTypePriorityBoundingBegin();
-      adjustForStrictAndBoundSkip(true);
+      adjustForTypePriorityBoundingBegin(0);
+      skipOverBoundingAnnot(true);
+      maybeMakeItInvalidSameBeginEnd(); 
+    case coveredBy:
+      it.moveTo(boundingAnnot);
+      adjustForTypePriorityBoundingBegin(0);
+      adjustForStrictOrCoveringAndBoundSkip(true); // forward
       break;
     case covering:
-      Misc.internalError(); // not yet impl
+      it.moveTo(coveringStartPos); // sufficiently before the bounds
+      adjustForTypePriorityBoundingBegin(0);
+      adjustForCoveringAndBoundSkip(true);  // forward
       break;
     }
     maybeSetPrevEnd();  // used for unambiguous
   }
   
-  private void adjustForStrictAndBoundSkip(boolean forward) {
+  private void adjustForStrictOrCoveringAndBoundSkip(boolean forward) {
+    if (boundsUse == BoundsUse.covering) {
+      adjustForCoveringAndBoundSkip(forward);
+      return;
+    }
+    // this used for both coveredBy and sameBeginEnd
     adjustForStrict(forward);
     if (skipOverBoundingAnnot(forward)) {
       adjustForStrict(forward);
     }
   }
   
+  private void adjustForCoveringAndBoundSkip(boolean forward) {
+    adjustForCovering(forward);
+    if (skipOverBoundingAnnot(forward)) {
+      adjustForCovering(forward);
+    }    
+  }
+  
   /**
    * advance over FSs that are equal (2 choices) to the bounding annotation.
    * May leave the iterator in invalid state.
@@ -329,6 +378,33 @@ public class Subiterator<T extends Annot
   }
   
   /**
+   * when covering, skip items where the end < bounds end
+   * may result in iterator becoming invalid
+   * @param forward
+   */
+  private void adjustForCovering(boolean forward) {
+    if (!it.isValid()) {
+      return;
+    }
+    // moveTo may move to invalid position
+    if (it.getNvc().getBegin() > this.boundBegin) {
+      makeInvalid();
+      return;
+    }
+    while (it.isValid() && (it.getNvc().getEnd() < this.boundEnd)) {
+      if (forward) {
+        it.moveToNextNvc();
+        if (it.isValid() && it.getNvc().getBegin() > this.boundBegin) {
+          makeInvalid();
+          return;
+        }
+      } else {
+        maybeMoveToPrevBounded();
+      }
+    }
+  }
+  
+  /**
    * Assume: iterator is valid
    */
   private void maybeMoveToPrevBounded() {
@@ -341,30 +417,37 @@ public class Subiterator<T extends Annot
   /**
    * moves the iterator backwards if not using type priorities
    * to the left most position with the same begin /end (and maybe type) as the fs at the current position.
+   * @param exactId 0 or the id to stop the traversal on
+   * @return false unless stopped on the matching exactId
    */
-  private void adjustForTypePriorityBoundingBegin() {
+  private boolean adjustForTypePriorityBoundingBegin(int exactId) {
     if (isTypePriority || !it.isValid()) {
-      return;
+      return false;
     }
     Annotation a = it.get();
     int begin = a.getBegin();
     int end = a.getEnd();
     Type type = a.getType();
     do {
-      if (it.get()._id == startId) { // start id may not be set yet; if so it is set to 0 so this test is always false
-        return;  // iterator is at the start, can't move more
+      int id = it.get()._id;
+      if (id == exactId) {
+        return true;
+      }
+      if (id == startId) { // start id may not be set yet; if so it is set to 0 so this test is always false
+        return false;  // iterator is at the start, can't move more
       }
       it.moveToPrevious();
       if (!it.isValid()) {
         it.moveToFirst();  // not moveToStart - called by moveToStart
-        Annotation f = it.getNvc();
-        if (!isBeginEndTypeEqualToBound(it.getNvc())) {
-          it.moveToPrevious();  // make invalid
-        }      
-        return;  
+//        Annotation f = it.getNvc();
+//        if (!isBeginEndTypeEqualToBound(it.getNvc())) {
+//          it.moveToPrevious();  // make invalid
+//        }      
+        return false;  
       }
     } while (isBeginEndTypeEqual(it.get(), begin, end, type));
     it.moveToNext();  // went back one to far
+    return false;
   }
     
   private boolean isBeginEndTypeEqualToBound(Annotation fs) {
@@ -396,6 +479,7 @@ public class Subiterator<T extends Annot
    */
   @Override
   public boolean isValid() {
+    if (isEmpty) return false;
     if (isListForm) {
       return (this.pos >= 0) && (this.pos < this.list.size());
     }
@@ -410,8 +494,7 @@ public class Subiterator<T extends Annot
     case coveredBy:
       return it.get().getBegin() <= boundEnd;
     case covering:
-      Misc.internalError();  //not yet impl
-      return false;
+      return it.isValid();
     case sameBeginEnd:
       Annotation a = it.get();
       return a.getBegin() == boundBegin &&
@@ -459,31 +542,24 @@ public class Subiterator<T extends Annot
    */
   @Override
   public void moveToNext() {
-    moveToNext(false);
+    if (!isValid()) return;
+    moveToNextNvc();
   }
   
   @Override
   public void moveToNextNvc() {
-    moveToNext(true);
-  }
-
-  private void moveToNext(boolean nvc) {
     if (isListForm) {
       ++this.pos;
       // maybeSetPrevEnd not needed because list form already accounted for unambiguous
       return;
     }
    
-    if (nvc) {
-      it.moveToNextNvc();
-    } else {
-      it.moveToNext();
-    }
+    it.moveToNextNvc();
     if (!isAmbiguous) {               // skip until start > prev end
       movePastPrevAnnotation();
     }
 
-    adjustForStrictAndBoundSkip(true); 
+    adjustForStrictOrCoveringAndBoundSkip(true);
     
     // stop logic going forwards for various bounding cases
     if (it.isValid()) {
@@ -495,20 +571,23 @@ public class Subiterator<T extends Annot
         maybeMakeItInvalid_bounds(it.getNvc(), a -> a.getBegin() > boundEnd);
         break;
       case covering:
-        Misc.internalError(); // not yet implemented
+        maybeMakeItInvalid_bounds(it.getNvc(), a -> a.getBegin() > boundBegin);
         break;
       case sameBeginEnd:
-        maybeMakeItInvalid_bounds(it.getNvc(), a -> a.getBegin() != boundBegin || a.getEnd() != boundEnd);
+        maybeMakeItInvalidSameBeginEnd();
         break;
       }
     } 
     maybeSetPrevEnd();
   }
   
+  private void maybeMakeItInvalidSameBeginEnd() {
+    maybeMakeItInvalid_bounds(it.getNvc(), a -> a.getBegin() != boundBegin || a.getEnd() != boundEnd);
+  }
+  
   private void maybeMakeItInvalid_bounds(Annotation a, Predicate<Annotation> outOfBounds) {
     if (outOfBounds.test(a)) {
-      it.moveToFirst();
-      it.moveToPrevious(); // make invalid
+      makeInvalid();
     }
   }
   
@@ -517,12 +596,15 @@ public class Subiterator<T extends Annot
    * 
    * @see org.apache.uima.cas.FSIterator#moveToPrevious()
    */
-  public void moveToPreviousNvc() {
-    moveToPrevious();
+  public void moveToPrevious() {
+    if (!isValid()) {
+      return;
+    }
+    moveToPreviousNvc();
   }
   
   @Override  
-  public void moveToPrevious() {
+  public void moveToPreviousNvc() {
     if (isListForm) {
       --this.pos;
       return;
@@ -541,7 +623,24 @@ public class Subiterator<T extends Annot
       maybeMoveToPrevBounded();
     }
 
-    adjustForStrictAndBoundSkip(false);   // false - moving backwards
+    adjustForStrictOrCoveringAndBoundSkip(false); // moving backwards
+    // stop logic going backwards for various bounding cases
+    // this is done by the maybeMoveToPrev call, where it compares to the saved startId
+//    if (it.isValid()) {
+//      // stop in bounded case if out of bounds going forwards UIMA-5063
+//      switch(boundsUse) {
+//      case notBounded: 
+//        break;
+//      case coveredBy:
+//        break;
+//      case covering:
+//        maybeMakeItInvalid_bounds(it.getNvc(), a -> a.getBegin() > boundBegin);
+//        break;
+//      case sameBeginEnd:
+//        maybeMakeItInvalidSameBeginEnd();
+//        break;
+//      }
+//    } 
   }
   
 
@@ -560,12 +659,15 @@ public class Subiterator<T extends Annot
   }
 
   /*
-   * This operation is relatively expensive for unambiguous
+   * This operation is relatively expensive one time for unambiguous
    * 
    * @see org.apache.uima.cas.FSIterator#moveToLast()
    */
   @Override
   public void moveToLast() {
+    if (isEmpty) {
+      return;
+    }
     if (!isAmbiguous && !isListForm) {
       convertToListForm();
     }
@@ -575,33 +677,38 @@ public class Subiterator<T extends Annot
     } else {
     
       // always bounded case because if unambig. case, above logic converted to list form and handled as list
+      // and unambig is the only Subiterator case without bounds
       assert isBounded;
-      if (isEmpty) {
-        return; // iterator is invalid, leave it that way
-      }
 
       switch (boundsUse) {
       case notBounded:
-        Misc.internalError();
+        Misc.internalError();  // never happen, because should always be bounded here
         break;
 
       case coveredBy:
-        moveToJustPastBoundsAndBackup(boundEnd + 1, Integer.MAX_VALUE, a -> a.getBegin() > boundEnd);
+        moveToJustPastBoundsAndBackup(boundEnd + 1, boundEnd + 1, a -> a.getBegin() > boundEnd);
         break;
       
       case covering:
-        Misc.internalError();  // not yet implemented
+        moveToJustPastBoundsAndBackup(boundBegin + 1, boundBegin + 1, a -> a.getBegin() > boundBegin);
         break;
 
       case sameBeginEnd:
-        moveToJustPastBoundsAndBackup(boundBegin,  boundEnd + 1, 
-            a -> a.getBegin() != boundBegin ||
-                 a.getEnd() != boundEnd);
+        moveToJustPastBoundsAndBackup(boundBegin,  boundEnd + 1, a -> a.getEnd() != boundEnd);
         break;
       }
     } 
   }
 
+  /**
+   * Called by move to Last, to move to a place just beyond the last spot, and then backup
+   * while the goBacwards is true
+   * 
+   * Includes adjustForStrictOrCoveringAndBoundSkip going backwards
+   * @param begin a position just past the last spot
+   * @param end a position just past the last spot
+   * @param goBackwards when true, continue to backup
+   */
   private void moveToJustPastBoundsAndBackup(int begin, int end, Predicate<Annotation> goBackwards) {
     it.moveTo(new Annotation (jcas, begin, end));
     if (it.isValid()) {
@@ -610,10 +717,10 @@ public class Subiterator<T extends Annot
         if (a._id == startId) {
           assert a.getBegin() <= boundEnd; // because it's non-empty
             // use this as the last
-          break;  // still need to adjust for strict and bound skip
+          break;  // no need to adjust for strict and bound skip because the startId has that incorporated
         } 
         it.moveToPreviousNvc();
-        adjustForStrictAndBoundSkip(false);
+        adjustForStrictOrCoveringAndBoundSkip(false);
         if (!it.isValid()) {
           break;
         }
@@ -621,7 +728,7 @@ public class Subiterator<T extends Annot
       }
     } else {
       it.moveToLast();
-      adjustForStrictAndBoundSkip(false);
+      adjustForStrictOrCoveringAndBoundSkip(false);
     }
   }
   // default visibility - referred to by flat iterator
@@ -659,6 +766,8 @@ public class Subiterator<T extends Annot
    */
   @Override
   public void moveTo(FeatureStructure fs) {
+    if (isEmpty) return;
+    
     Annotation fsa = (Annotation) fs;
     if (!isAmbiguous && !isListForm) {  // unambiguous must be in list form
       convertToListForm();
@@ -714,18 +823,16 @@ public class Subiterator<T extends Annot
       // not list form
       // is ambiguous, may be strict, always bounded
       it.moveTo(fs);  // may move before, within, or after bounds
-      adjustForTypePriorityBoundingBegin();
-      adjustForStrictAndBoundSkip(true);
+      adjustForTypePriorityBoundingBegin(0);
+      adjustForStrictOrCoveringAndBoundSkip(true);
       
       if (it.isValid()) {
         // mark invalid if end up outside of bounds after adjustments
         Annotation a = it.get();
         if (a.getBegin() > boundEnd) {
-          it.moveToLast();
-          it.moveToNext();  // make invalid
+          makeInvalid();
         } else if (isTypePriority && annotationComparator.compare(a,  boundingAnnot) < 0) {
-          it.moveToFirst();
-          it.moveToPrevious(); // make invalid
+          makeInvalid();
         } else if (a.getBegin() < boundBegin || 
                    a.getBegin() > boundEnd ||
                    (a.getBegin() == boundBegin && a.getEnd() > boundEnd) ||
@@ -733,8 +840,7 @@ public class Subiterator<T extends Annot
                        a.getBegin() == boundBegin && 
                        a.getEnd() == boundEnd &&
                        a.getType() != boundType)) {
-          it.moveToFirst();
-          it.moveToPrevious(); // make invalid
+          makeInvalid();
         }
       }
     }
@@ -758,7 +864,9 @@ public class Subiterator<T extends Annot
         this.isSkipEquals,
         this.annotationComparator,
         this.startId,
-        this.isEmpty);
+        this.isEmpty,
+        this.coveringStartPos,
+        this.coveringEndPos);
     copy.list = this.list;  // non-final things
     copy.pos  = this.pos;
     copy.isListForm = this.isListForm;
@@ -770,13 +878,20 @@ public class Subiterator<T extends Annot
     throw new UnsupportedOperationException();
   }
 
+  @Override
+  public int ll_maxAnnotSpan() {
+    return ((LowLevelIterator)it).ll_maxAnnotSpan();
+  }
 
   @Override
   public LowLevelIndex<T> ll_getIndex() {
     return ((LowLevelIterator<T>)it).ll_getIndex();
   }
 
-
+  private void makeInvalid() {
+    it.moveToFirst();
+    it.moveToPrevious();
+  }
 
 
 

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java Fri Oct  7 18:56:18 2016
@@ -120,25 +120,6 @@ public interface JCas extends AbstractCa
    */
   Feature getRequiredFeature(Type t, String s) throws CASException;
 
-//  /*
-//   * Internal Use - look up a feature-name-string in the CAS type system and returns the Cas Feature
-//   * object. If the feature isn't found, adds an exception to the errorSet but doesn't throw
-//   * 
-//   * DE suffix means "Deferred Exception"
-//   */
-//
-//  Feature getRequiredFeatureDE(Type t, String s, String rangeName, boolean featOkTst);
-
-//  /*
-//   * Internal Use. 
-//   */
-//  void checkArrayBounds(int fsRef, int pos);
-//
-//  /*
-//   * Internal Use - throw missing feature exception at runtime.
-//   */
-//  void throwFeatMissing(String feat, String type);
-//  
   /**
    * @deprecated As of v2.0, use {#getView(String)}. From the view you can access the Sofa data, or
    *             call {@link #getSofa()} if you truly need to access the SofaFS object.
@@ -676,23 +657,23 @@ public interface JCas extends AbstractCa
   <T extends TOP> FSIndex<T> getIndex(String label, Class<T> clazz);
   
   
-  default <T extends TOP> SelectFSs<T> select() {
+  default <T extends FeatureStructure> SelectFSs<T> select() {
     return new SelectFSs_impl<>(getCas());
   }
 
-  default <N extends TOP> SelectFSs<N> select(Type type) {
+  default <N extends FeatureStructure> SelectFSs<N> select(Type type) {
     return new SelectFSs_impl<>(getCasImpl()).type(type);
   }
 
-  default <N extends TOP> SelectFSs<N> select(Class<N> clazz) {
+  default <N extends FeatureStructure> SelectFSs<N> select(Class<N> clazz) {
     return new SelectFSs_impl<>(getCasImpl()).type(clazz);
   }
 
-  default <N extends TOP> SelectFSs<N> select(int jcasType) {
+  default <N extends FeatureStructure> SelectFSs<N> select(int jcasType) {
     return new SelectFSs_impl<>(getCasImpl()).type(jcasType);
   }
 
-  default <N extends TOP> SelectFSs<N> select(String fullyQualifiedTypeName) {
+  default <N extends FeatureStructure> SelectFSs<N> select(String fullyQualifiedTypeName) {
     return new SelectFSs_impl<>(getCasImpl()).type(fullyQualifiedTypeName);
   }
 

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java Fri Oct  7 18:56:18 2016
@@ -87,6 +87,8 @@ public class AnnotationIteratorTest exte
   private Feature endFeature;
 
   private Type sentenceType;
+  
+  private Type phraseType;
 
   private boolean isSave;
 
@@ -145,6 +147,8 @@ public class AnnotationIteratorTest exte
     assertTrue(this.endFeature != null);
     this.sentenceType = this.ts.getType(CASTestSetup.SENT_TYPE);
     assertTrue(this.sentenceType != null);
+    this.phraseType = this.ts.getType(CASTestSetup.PHRASE_TYPE);
+    assertTrue(this.phraseType != null);
   }
 
   @Override
@@ -218,6 +222,21 @@ public class AnnotationIteratorTest exte
       }
     }
     
+    // create overlapping phrases
+    // begin =  0,  6,  10, 14, ...
+    // end   =  5,  9,  16, 19, ...
+    
+    int beginAlt = 0, endAlt = 0;
+    for (int i = 0; i < text.length() - 10; i += 5) {
+      ++annotCount;
+      ir.addFS(fs = this.cas.createAnnotation(this.phraseType,  i + beginAlt, i + 5 + endAlt));
+      beginAlt = (beginAlt == 1) ? -1 : beginAlt + 1;
+      endAlt = (endAlt == -1) ? 1 : endAlt - 1;
+      if (true ||showFSs) {
+        System.out.format("creating: %d begin: %d end: %d type: %s%n", annotCount, fs.getBegin(), fs.getEnd(), fs.getType().getName() );
+      }
+    }
+    
     ++annotCount;
     ir.addFS(fs = this.cas.createAnnotation(this.sentenceType,  12, 31));
     if (showFSs) {
@@ -325,15 +344,15 @@ public class AnnotationIteratorTest exte
     
     AnnotationFS bigBound = this.cas.createAnnotation(this.sentenceType, 10, 41);
     it = annotIndex.subiterator(bigBound, true, true);  // ambiguous, and strict
-    assertCount("Subiterator over annot with big bound, strict", 33, it);
+    assertCount("Subiterator over annot with big bound, strict", 38, it);
     select_it = cas.<AnnotationFS>select().coveredBy((Annotation) bigBound).endWithinBounds().fsIterator();
-    assertCount("Subiterator select over annot with big bound, strict", 33, select_it);
+    assertCount("Subiterator select over annot with big bound, strict", 38, select_it);
 
     select_it = cas.<AnnotationFS>select().coveredBy(bigBound).limit(7).endWithinBounds().fsIterator();
     assertCountLimit("Subiterator select limit 7 over annot with big bound, strict", 7, select_it);
 
     Object[] o = cas.<AnnotationFS>select().coveredBy(bigBound).skip(3).toArray();
-    assertEquals(o.length, 30);
+    assertEquals(35, o.length);
     
     Object[] o1 = cas.<AnnotationFS>select().coveredBy(bigBound).toArray();
     List<AnnotationFS> l2 = cas.<AnnotationFS>select().coveredBy(bigBound).backwards().asList(AnnotationFS.class);
@@ -348,17 +367,22 @@ public class AnnotationIteratorTest exte
     select_it = cas.<AnnotationFS>select().backwards().coveredBy((Annotation) bigBound).endWithinBounds().nonOverlapping().fsIterator();
     assertCount("Subiterator select over annot unambiguous strict", 3, select_it);
 
+//    it = annotIndex.subiterator(bigBound, true, false);
+//    while (it.hasNext()) {
+//      Annotation a = (Annotation) it.next();
+//      System.out.format("debug %s:%d   b:%d e:%d%n", a.getType().getShortName(), a._id(), a.getBegin(), a.getEnd());
+//    }
 
     it = annotIndex.subiterator(bigBound, true, false);
-    assertCount("Subiterator over annot ambiguous not-strict", 40, it);
+    assertCount("Subiterator over annot ambiguous not-strict", 46, it);
     
     // covered by implies endWithinBounds
     select_it = sselect(annotIndex).coveredBy(bigBound).fsIterator();
-    assertCount("Subiterator select over annot ambiguous not-strict", 33, select_it);
+    assertCount("Subiterator select over annot ambiguous not-strict", 38, select_it);
     select_it = annotIndex.<AnnotationFS>select().coveredBy(bigBound).fsIterator();
-    assertCount("Subiterator select over annot ambiguous not-strict", 33, select_it);
+    assertCount("Subiterator select over annot ambiguous not-strict", 38, select_it);
     select_it = sselect(annotIndex).coveredBy(bigBound).endWithinBounds(false).fsIterator();
-    assertCount("Subiterator select over annot ambiguous not-strict", 40, select_it);
+    assertCount("Subiterator select over annot ambiguous not-strict", 46, select_it);
     
     it = annotIndex.subiterator(bigBound, false, false);  // unambiguous, not strict
     assertCount("Subiterator over annot, unambiguous, not-strict", 4, it);
@@ -374,9 +398,9 @@ public class AnnotationIteratorTest exte
     // strict skips first item
     bigBound = this.cas.createAnnotation(this.sentenceType,  11, 30);
     it = sentIndex.subiterator(bigBound, true, true);
-    assertCount("Subiteratover over sent ambiguous strict", 2, it);
+    assertCount("Subiteratover over sent ambiguous strict", 4, it);
     it = sentIndex.subiterator(bigBound, true, false);
-    assertCount("Subiteratover over sent ambiguous", 5, it);
+    assertCount("Subiteratover over sent ambiguous", 9, it);
     it = sentIndex.subiterator(bigBound, false, false);
     assertCount("Subiteratover over sent unambiguous", 1, it); 
     
@@ -447,12 +471,26 @@ public class AnnotationIteratorTest exte
     assertCountLimit("Following", 2, select_it);
     
     select_it = fsa.<AnnotationFS>select(sentenceType).fsIterator();
-    assertCount("select source array", 11, select_it);
+    assertCount("select source array", 21, select_it);
     select_it = fslhead.<AnnotationFS>select(sentenceType).fsIterator();
-    assertCount("select source array", 11, select_it);
+    assertCount("select source array", 21, select_it);
     
-
+    /** covering **/
+    cas.<AnnotationFS>select(sentenceType).covering(20, 30).forEachOrdered(f ->  
+        System.out.format("found fs start at %d end %d%n", Integer.valueOf(f.getBegin()), Integer.valueOf(f.getEnd())));
     
+    cas.<AnnotationFS>select(sentenceType).covering(15, 19).forEachOrdered(f ->  
+        System.out.format("covering 15, 19:   %s:%d   %d -  %d%n", f.getType().getShortName(), Integer.valueOf(f._id()), Integer.valueOf(f.getBegin()), Integer.valueOf(f.getEnd())));
+
+    cas.<AnnotationFS>select(sentenceType).covering(37, 39).forEachOrdered(f ->  
+        System.out.format("covering sentences 37, 39:   %s:%d   %d -  %d%n", f.getType().getShortName(), Integer.valueOf(f._id()), Integer.valueOf(f.getBegin()), Integer.valueOf(f.getEnd())));
+
+    cas.<AnnotationFS>select(phraseType).covering(15, 19).forEachOrdered(f ->  
+       System.out.format("covering phrases 15, 19:   %s:%d   %d -  %d%n", f.getType().getShortName(), Integer.valueOf(f._id()), Integer.valueOf(f.getBegin()), Integer.valueOf(f.getEnd())));
+
+    cas.<AnnotationFS>select(phraseType).covering(37, 39).forEachOrdered(f ->  
+       System.out.format("covering phrases 37, 39:   %s:%d   %d -  %d%n", f.getType().getShortName(), Integer.valueOf(f._id()), Integer.valueOf(f.getBegin()), Integer.valueOf(f.getEnd())));
+
   }
   
   private String flatStateMsg(String s) {

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java?rev=1763809&r1=1763808&r2=1763809&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java Fri Oct  7 18:56:18 2016
@@ -36,6 +36,8 @@ public class CASTestSetup  implements An
 
   // Type system constants.
   public static final String TOKEN_TYPE = "Token";
+  
+  public static final String PHRASE_TYPE = "Phrase";
 
   public static final String TOKEN_TYPE_FEAT = "type";
 
@@ -130,6 +132,7 @@ public class CASTestSetup  implements An
    *   ArrayFSwithSubtype
    *   Annotation
    *     Sentence [SEN_LEN_FEAT(int)
+   *       Phrase (subtype of sentence)
    *     Token  TOKEN_TYPE [TOKEN_TYPE_FEAT(TOKEN_TYPE_TYPE), TOKEN_FLOAT_FEAT, LEMMA_FEAT(string), LEMMA_LIST_FEAT[stringArray]
    *   String
    *     Group1
@@ -143,7 +146,8 @@ public class CASTestSetup  implements An
     Type topType = tsm.getTopType();
     Type annotType = tsm.getType(CAS.TYPE_NAME_ANNOTATION);
     // assert(annotType != null);
-    tsm.addType(SENT_TYPE, annotType);
+    Type sentenceType = tsm.addType(SENT_TYPE, annotType);
+    tsm.addType(PHRASE_TYPE, sentenceType);
     Type tokenType = tsm.addType(TOKEN_TYPE, annotType);
     Type tokenTypeType = tsm.addType(TOKEN_TYPE_TYPE, topType);
     tsm.addType(WORD_TYPE, tokenTypeType);