You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/02/13 16:14:22 UTC

svn commit: r507042 - in /incubator/uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java test/java/org/apache/uima/cas/test/GetAllIndexedTest.java

Author: twgoetz
Date: Tue Feb 13 07:14:22 2007
New Revision: 507042

URL: http://svn.apache.org/viewvc?view=rev&rev=507042
Log:
Jira UIMA-297: fix bugs uncovered by unit tests; check in unit tests.

https://issues.apache.org/jira/browse/UIMA-297

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java?view=diff&rev=507042&r1=507041&r2=507042
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java Tue Feb 13 07:14:22 2007
@@ -498,16 +498,15 @@
     }
 
     public Object copy() {
-      // PointerIterator it = new PointerIterator();
-      // it.indexes = new
-      // ComparableIntPointerIterator[this.indexes.length];
-      // for (int i = 0; i < indexes.length; i++) {
-      // it.indexes[i] = (ComparableIntPointerIterator)
-      // this.indexes[i].copy();
-      // }
-      // it.numIndexes = it.indexes.length;
-      // return it;
-      return new PointerIterator(this.iicp, this.get());
+      // If this.isValid(), return a copy pointing to the same element.
+      if (this.isValid()) {
+        return new PointerIterator(this.iicp, this.get());
+      }
+      // Else, create a copy that is also not valid.
+      PointerIterator pi = new PointerIterator(this.iicp);
+      pi.moveToFirst();
+      pi.moveToPrevious();
+      return pi;
     }
 
     /**
@@ -1362,7 +1361,7 @@
   private static final String getAutoIndexNameForType(Type type) {
     return "_" + type.getName() + "_GeneratedIndex";
   }
-  
+
   public void ll_removeFS(int fsRef) {
     final int typeCode = this.cas.ll_getFSRefType(fsRef);
     incrementIllegalIndexUpdateDetector(typeCode);
@@ -1383,14 +1382,14 @@
     getAllIndexedFS(type, iteratorList);
     return new FSIteratorAggregate(iteratorList);
   }
-  
+
   private final void getAllIndexedFS(Type type, List iteratorList) {
-    // Start by looking for an auto-index.  If one exists, no other index exists.
+    // Start by looking for an auto-index. If one exists, no other index exists.
     FSIndex autoIndex = getIndex(getAutoIndexNameForType(type));
     if (autoIndex != null) {
       iteratorList.add(autoIndex.iterator());
-      // We found one of the special auto-indexes which don't inherit down the tree.  So, we
-      // manually need to traverse the inheritance tree to look for more indexes.  Note that
+      // We found one of the special auto-indexes which don't inherit down the tree. So, we
+      // manually need to traverse the inheritance tree to look for more indexes. Note that
       // this is not necessary when we have a regular index
       List subtypes = this.typeSystem.getDirectSubtypes(type);
       for (int i = 0; i < subtypes.size(); i++) {
@@ -1424,14 +1423,13 @@
       iteratorList.add(setIndex.iterator());
       return;
     }
-    // No index for this type was found at all.  Since the auto-indexes are created on demand for
-    // each type, there may be gaps in the inheritance chain.  So keep descending the inheritance
+    // No index for this type was found at all. Since the auto-indexes are created on demand for
+    // each type, there may be gaps in the inheritance chain. So keep descending the inheritance
     // tree looking for relevant indexes.
     List subtypes = this.typeSystem.getDirectSubtypes(type);
     for (int i = 0; i < subtypes.size(); i++) {
       getAllIndexedFS((Type) subtypes.get(i), iteratorList);
     }
   }
-
 
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java?view=diff&rev=507042&r1=507041&r2=507042
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java Tue Feb 13 07:14:22 2007
@@ -141,7 +141,9 @@
       }
       --this.iteratorIndex;
     }
-    // If we get here, the iterator is no longer valid, there are no more elements.
+    // If we get here, the iterator is no longer valid, there are no more elements.  Set internal
+    // counter to the invalid position.
+    this.iteratorIndex = this.iterators.size();
   }
 
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java?view=diff&rev=507042&r1=507041&r2=507042
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java Tue Feb 13 07:14:22 2007
@@ -27,7 +27,6 @@
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.FSIndexRepository;
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.cas.Type;
@@ -155,13 +154,21 @@
     assertTrue(getIteratorSize(getAllIndexed()) == this.fsCount);
   }
   
+  private final FeatureStructure createAnnot(int from, int to) {
+    return this.cas.createAnnotation(this.annotationType, from, to);
+  }
+  
+  private final void initTest() {
+    this.cas.reset();
+    this.fsCount = 0;
+  }
+  
   /**
    * Test driver.
    */
   public void testGetAllIndexed() throws Exception {
-    this.fsCount = 0;
-    this.cas.reset();
-  	FeatureStructure docAnnotation = this.cas.getDocumentAnnotation();
+    initTest();
+    FeatureStructure docAnnotation = this.cas.getDocumentAnnotation();
   	assertNotNull(docAnnotation);
     ++this.fsCount;
     assertTrue(getIteratorSize(getAllIndexed()) == this.fsCount);
@@ -173,6 +180,29 @@
     addFS(annotationBaseFS);
     addFS(this.cas.createFS(this.cas.getTypeSystem().getTopType()));
     assertTrue(getIteratorSize(this.cas.getAnnotationIndex().iterator()) == 2);
+    addFS(createAnnot(0, 1));
+    addFS(createAnnot(1, 2));
+    addFS(createAnnot(2, 3));
+    addFS(createAnnot(3, 4));
+    
+    // Iterate backwards, check only that it returns correct number of FSs
+    FSIterator it = getAllIndexed();
+    int down = this.fsCount;
+    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
+      --down;
+    }
+    assertTrue(down == 0);
+
+    // Get all indexed, create copy and iterate in parallel.
+    it = getAllIndexed();
+    FSIterator copy = it.copy();
+    copy.moveToFirst();
+    for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
+      assertTrue(copy.isValid());
+      assertTrue(it.get().equals(copy.get()));
+      copy.moveToNext();
+    }
+    assertFalse(copy.isValid());
   }
 
   public static void main(String[] args) {