UIMA-6281: Ruta: use uimaFIT instead of CAS.select().coveredBy() internally

- refactoring and TODO comments
diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java b/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java
index 855ff9b..8dc7110 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java
@@ -194,6 +194,7 @@
 

   public FSIterator<AnnotationFS> createFilteredIterator(CAS cas, Type basicType) {

     if (windowAnnotation != null) {

+      // TODO: UIMA-6281 replace select

       FSIterator<AnnotationFS> windowIt = cas.getAnnotationIndex(basicType).select()

               .coveredBy(windowAnnotation).fsIterator();

 //     was: FSIterator<AnnotationFS> windowIt = cas.getAnnotationIndex(basicType)

diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java b/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
index 2b49ea5..1cdd40c 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
@@ -203,6 +203,7 @@
   private void updateIterators(CAS cas, Type basicType, FilterManager filter,

           AnnotationFS additionalWindow) {

     if (additionalWindow != null) {

+      // TODO UIMA-6281 replace select

       this.basicIt = cas.getAnnotationIndex(basicType).select().coveredBy(additionalWindow)

               .fsIterator();

       // was: this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow);

@@ -783,16 +784,7 @@
 

   public List<AnnotationFS> getAnnotationsInWindow(AnnotationFS windowAnnotation, Type type) {

 

-    if (windowAnnotation == null || type == null) {

-      return Collections.emptyList();

-    }

-    TypeSystem typeSystem = getCas().getTypeSystem();

-    List<AnnotationFS> result = new ArrayList<>();

-    if (typeSystem.subsumes(type, windowAnnotation.getType())) {

-      result.add(windowAnnotation);

-    }

-    result.addAll(CasUtil.selectCovered(cas, type, windowAnnotation));

-    return result;

+    return getAnnotationsInWindow(type, windowAnnotation, false);

   }

 

   public Collection<RutaBasic> getAllBasicsInWindow(AnnotationFS windowAnnotation) {

@@ -864,6 +856,7 @@
       return result;

     }

     FSMatchConstraint defaultConstraint = filter.getDefaultConstraint();

+    // TODO UIMA-6281 replace select

     FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(

             cas.getAnnotationIndex(basicType).select().coveredBy(windowAnnotation).fsIterator(),

             defaultConstraint);

@@ -1131,18 +1124,7 @@
             && (windowAnnotation.getBegin() != cas.getDocumentAnnotation().getBegin()

                     || windowAnnotation.getEnd() != cas.getDocumentAnnotation().getEnd())) {

 

-      List<AnnotationFS> selectCovered = CasUtil.selectCovered(cas, type, windowAnnotation);

-      if (cas.getTypeSystem().subsumes(type, windowAnnotation.getType())) {

-        if (isVisible(windowAnnotation)) {

-          result.add(windowAnnotation);

-        }

-      }

-

-      for (AnnotationFS each : selectCovered) {

-        if (isVisible(each)) {

-          result.add(each);

-        }

-      }

+      return getAnnotationsInWindow(type, windowAnnotation, true);

     } else {

       AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex(type);

       for (AnnotationFS each : annotationIndex) {

@@ -1154,6 +1136,26 @@
     return result;

   }

 

+  public List<AnnotationFS> getAnnotationsInWindow(Type type, AnnotationFS windowAnnotation,

+          boolean sensitiveToVisibility) {

+

+    List<AnnotationFS> result = new LinkedList<>();

+

+    if (cas.getTypeSystem().subsumes(type, windowAnnotation.getType())) {

+      if (!sensitiveToVisibility || isVisible(windowAnnotation)) {

+        result.add(windowAnnotation);

+      }

+    }

+

+    List<AnnotationFS> selectCovered = CasUtil.selectCovered(cas, type, windowAnnotation);

+    for (AnnotationFS each : selectCovered) {

+      if (!sensitiveToVisibility || isVisible(each)) {

+        result.add(each);

+      }

+    }

+    return result;

+  }

+

   public String getVisibleCoveredText(AnnotationFS annotationFS) {

     StringBuilder result = new StringBuilder();

     List<RutaBasic> basicsInWindow = getBasicsInWindow(annotationFS);

diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java b/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
index dde4543..347b400 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
@@ -565,7 +565,7 @@
         }

       }

     } else {

-

+      // TODO UIMA-6281 replace select and rewrite complete block

       result = cas.getAnnotationIndex(type).select().coveredBy(stream.getDocumentAnnotation())

               .fsIterator();

       if (annotation == null) {

@@ -745,8 +745,7 @@
 

     RuleElementMatch result = new RuleElementMatch(this, containerMatch);

     result.setRuleAnchor(ruleAnchor);

-    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(

-            conditions.size());

+    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(conditions.size());

     boolean base = true;

 

     MatchContext context = new MatchContext(annotation, this, ruleMatch, true);