You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/04/30 08:27:06 UTC

svn commit: r1477482 - in /uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util: CasUtil.java JCasUtil.java

Author: rec
Date: Tue Apr 30 06:27:05 2013
New Revision: 1477482

URL: http://svn.apache.org/r1477482
Log:
[UIMA-2830] Expose FSIterator via (J)CasUtil.select*() methods where applicable
- Slight re-routing of calls between (J)CasUtil and FSCollectionFactory to work out better where getAllIndexedFS() is required.

Modified:
    uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java
    uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java

Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java?rev=1477482&r1=1477481&r2=1477482&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java Tue Apr 30 06:27:05 2013
@@ -74,7 +74,7 @@ public final class CasUtil {
    */
   @SuppressWarnings("unchecked")
   public static <T extends FeatureStructure> Iterator<T> iteratorFS(CAS cas, Type type) {
-    return ((FSIterator<T>) cas.getIndexRepository().getAllIndexedFS(type));
+    return (Iterator<T>) FSCollectionFactory.create(cas, type).iterator();
   }
 
   /**
@@ -243,7 +243,7 @@ public final class CasUtil {
     if (!cas.getTypeSystem().subsumes(cas.getAnnotationType(), type)) {
       throw new IllegalArgumentException("Type [" + type.getName() + "] is not an annotation type");
     }
-    return (Collection) FSCollectionFactory.create(cas, type);
+    return (Collection) FSCollectionFactory.create(cas.getAnnotationIndex(type));
   }
 
   /**
@@ -680,40 +680,6 @@ public final class CasUtil {
    * and should not, in general be used outside the context of unit testing.
    * 
    * @param cas
-   *          a CAS containing the feature structure.
-   * @param type
-   *          a UIMA type.
-   * @param index
-   *          this can be either positive (0 corresponds to the first annotation of a type) or
-   *          negative (-1 corresponds to the last annotation of a type.)
-   * @return an annotation of the given type
-   */
-  public static FeatureStructure selectFSByIndex(CAS cas, Type type, int index) {
-    FSIterator<FeatureStructure> i = cas.getIndexRepository().getAllIndexedFS(type);
-    int n = index;
-    i.moveToFirst();
-    if (n > 0) {
-      while (n > 0 && i.isValid()) {
-        i.moveToNext();
-        n--;
-      }
-    }
-    if (n < 0) {
-      i.moveToLast();
-      while (n < -1 && i.isValid()) {
-        i.moveToPrevious();
-        n++;
-      }
-    }
-
-    return i.isValid() ? i.get() : null;
-  }
-
-  /**
-   * This method exists simply as a convenience method for unit testing. It is not very efficient
-   * and should not, in general be used outside the context of unit testing.
-   * 
-   * @param cas
    *          a CAS containing the annotation.
    * @param type
    *          a UIMA type.

Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java?rev=1477482&r1=1477481&r2=1477482&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java Tue Apr 30 06:27:05 2013
@@ -25,7 +25,6 @@ import java.util.Map;
 
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
-import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.impl.Subiterator;
 import org.apache.uima.cas.text.AnnotationFS;
@@ -86,7 +85,7 @@ public final class JCasUtil {
    */
   @SuppressWarnings({ "unchecked", "rawtypes" })
   public static <T extends TOP> Iterator<T> iterator(JCas jCas, Class<T> type) {
-    return (FSIterator) jCas.getIndexRepository().getAllIndexedFS(getType(jCas, type));
+    return (Iterator) FSCollectionFactory.create(jCas.getCas(), getType(jCas, type)).iterator();
   }
 
   /**
@@ -445,6 +444,10 @@ public final class JCasUtil {
   /**
    * This method exists simply as a convenience method for unit testing. It is not very efficient
    * and should not, in general be used outside the context of unit testing.
+   * <p>
+   * It is intentional that this method only allows annotation types. The CAS indexing mechanisms
+   * are not well defined for non-annotation types. There are no reliably, built-in indexes for
+   * non-annotation types.
    * 
    * @param <T>
    *          JCas wrapper type.
@@ -458,8 +461,8 @@ public final class JCasUtil {
    * @return an annotation of the given type
    */
   @SuppressWarnings("unchecked")
-  public static <T extends TOP> T selectByIndex(JCas jCas, Class<T> cls, int index) {
-    return (T) CasUtil.selectFSByIndex(jCas.getCas(), getType(jCas, cls), index);
+  public static <T extends Annotation> T selectByIndex(JCas jCas, Class<T> cls, int index) {
+    return (T) CasUtil.selectByIndex(jCas.getCas(), getType(jCas, cls), index);
   }
 
   /**