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 2020/05/11 19:34:43 UTC

svn commit: r1877605 - in /uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta: ./ expression/ expression/feature/ rule/

Author: rec
Date: Mon May 11 19:34:43 2020
New Revision: 1877605

URL: http://svn.apache.org/viewvc?rev=1877605&view=rev
Log:
[UIMA-6231] Reducing memory pressure generated by UIMA Ruta

- Merge remaining changes from master (v2)


Modified:
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationTypeMatcher.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
    uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,9 @@
 
 package org.apache.uima.ruta;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptySet;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -102,9 +105,9 @@ public class RutaStream {
 
   private Type basicType;
 
-  private NavigableMap<Integer, RutaBasic> beginAnchors = new TreeMap<Integer, RutaBasic>();
+  private NavigableMap<Integer, RutaBasic> beginAnchors = new TreeMap<>();
 
-  private NavigableMap<Integer, RutaBasic> endAnchors = new TreeMap<Integer, RutaBasic>();
+  private NavigableMap<Integer, RutaBasic> endAnchors = new TreeMap<>();
 
   private FilterManager filter;
 
@@ -220,7 +223,7 @@ public class RutaStream {
       reindexTypeList = removeSubsumedTypes(Arrays.asList(reindexOnly), cas.getTypeSystem());
     }
 
-    final List<AnnotationFS> allAnnotations = new LinkedList<AnnotationFS>();
+    final List<AnnotationFS> allAnnotations = new LinkedList<>();
     for (Type type : reindexTypeList) {
       AnnotationIndex<AnnotationFS> annotationIndex = null;
       if (StringUtils.equals(type.getName(), CAS.TYPE_NAME_ANNOTATION)) {
@@ -236,7 +239,7 @@ public class RutaStream {
     }
 
     if (basicIndex.size() == 0) {
-      TreeSet<Integer> anchors = new TreeSet<Integer>();
+      TreeSet<Integer> anchors = new TreeSet<>();
       for (AnnotationFS a : allAnnotations) {
         anchors.add(a.getBegin());
         anchors.add(a.getEnd());
@@ -548,7 +551,7 @@ public class RutaStream {
   }
 
   public List<AnnotationFS> getOverappingAnnotations(AnnotationFS window, Type type) {
-    List<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    List<AnnotationFS> result = new ArrayList<>();
     AnnotationFS newWindow = cas.createAnnotation(type, window.getBegin(), window.getEnd() - 1);
     FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(type).iterator(newWindow);
     if (!iterator.isValid()) {
@@ -568,7 +571,7 @@ public class RutaStream {
   }
 
   public List<Annotation> getAnnotationsFollowing(Annotation annotation) {
-    List<Annotation> result = new ArrayList<Annotation>();
+    List<Annotation> result = new ArrayList<>();
     moveTo(annotation);
     while (currentIt.isValid()) {
       currentIt.moveToNext();
@@ -598,7 +601,7 @@ public class RutaStream {
   }
 
   public List<AnnotationFS> getAllofType(Type type) {
-    List<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    List<AnnotationFS> result = new ArrayList<>();
     FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(type).iterator();
     while (iterator.isValid()) {
       FeatureStructure featureStructure = iterator.get();
@@ -613,34 +616,32 @@ public class RutaStream {
     if (windowAnnotation == null || type == null) {
       return Collections.emptyList();
     }
-    TypeSystem typeSystem = this.getCas().getTypeSystem();
-    List<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    TypeSystem typeSystem = getCas().getTypeSystem();
+    List<AnnotationFS> result = new ArrayList<>();
     if (typeSystem.subsumes(type, windowAnnotation.getType())) {
       result.add(windowAnnotation);
     }
-    result.addAll(CasUtil.selectCovered(this.cas, type, windowAnnotation));
+    result.addAll(CasUtil.selectCovered(cas, type, windowAnnotation));
     return result;
   }
 
   public Collection<RutaBasic> getAllBasicsInWindow(AnnotationFS windowAnnotation) {
     if (windowAnnotation.getBegin() >= windowAnnotation.getEnd()) {
-      return Collections.emptySet();
+      return emptySet();
     }
+
     RutaBasic beginAnchor = getBeginAnchor(windowAnnotation.getBegin());
     if (beginAnchor != null && beginAnchor.getEnd() == windowAnnotation.getEnd()) {
-      Collection<RutaBasic> result = new ArrayList<RutaBasic>(1);
-      result.add(beginAnchor);
-      return result;
+      return asList(beginAnchor);
     }
-    Collection<RutaBasic> subSet = null;
+
     if (windowAnnotation.getEnd() == cas.getDocumentAnnotation().getEnd()
             && windowAnnotation.getBegin() == 0) {
-      subSet = beginAnchors.values();
-    } else {
-      subSet = beginAnchors
-              .subMap(windowAnnotation.getBegin(), true, windowAnnotation.getEnd(), false).values();
+      return beginAnchors.values();
     }
-    return subSet;
+
+    return beginAnchors.subMap(windowAnnotation.getBegin(), true, windowAnnotation.getEnd(), false)
+            .values();
   }
 
   public RutaBasic getBasicNextTo(boolean before, AnnotationFS annotation) {
@@ -687,7 +688,7 @@ public class RutaStream {
   }
 
   public List<RutaBasic> getBasicsInWindow(AnnotationFS windowAnnotation) {
-    List<RutaBasic> result = new ArrayList<RutaBasic>();
+    List<RutaBasic> result = new ArrayList<>();
     if (windowAnnotation instanceof RutaBasic) {
       result.add((RutaBasic) windowAnnotation);
       return result;
@@ -726,7 +727,7 @@ public class RutaStream {
     if (annotation != null) {
       return getBasicsInWindow(annotation);
     } else {
-      return new ArrayList<RutaBasic>();
+      return new ArrayList<>();
     }
   }
 
@@ -834,7 +835,7 @@ public class RutaStream {
   }
 
   public void setGreedyRuleElement(Boolean greedyAnchoring) {
-    this.greedyRuleElement = greedyAnchoring;
+    greedyRuleElement = greedyAnchoring;
   }
 
   public boolean isGreedyRule() {
@@ -842,7 +843,7 @@ public class RutaStream {
   }
 
   public void setGreedyRule(Boolean greedyAnchoring) {
-    this.greedyRule = greedyAnchoring;
+    greedyRule = greedyAnchoring;
   }
 
   public void setIndexPenalty(double indexPenalty) {
@@ -954,7 +955,7 @@ public class RutaStream {
   }
 
   public Collection<AnnotationFS> getAnnotations(Type type) {
-    Collection<AnnotationFS> result = new LinkedList<AnnotationFS>();
+    Collection<AnnotationFS> result = new LinkedList<>();
     AnnotationFS windowAnnotation = filter.getWindowAnnotation();
     if (windowAnnotation != null
             && (windowAnnotation.getBegin() != cas.getDocumentAnnotation().getBegin()
@@ -1136,7 +1137,7 @@ public class RutaStream {
       AnnotationTypeExpression ate = (AnnotationTypeExpression) value;
       if (range.isArray()) {
         List<AnnotationFS> annotations = ate.getAnnotationList(context, this);
-        annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), annotations));
+        annotation.setFeatureValue(feature, UIMAUtils.toFSArray(getJCas(), annotations));
       } else {
         AnnotationFS a = ate.getAnnotation(context, this);
         annotation.setFeatureValue(feature, a);
@@ -1155,7 +1156,7 @@ public class RutaStream {
       if (range.isArray()) {
         List<FeatureStructure> c = new ArrayList<>();
         c.add(a);
-        annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), c));
+        annotation.setFeatureValue(feature, UIMAUtils.toFSArray(getJCas(), c));
       } else {
         annotation.setFeatureValue(feature, a);
       }
@@ -1164,7 +1165,7 @@ public class RutaStream {
       List<AnnotationFS> annotations = ale.getAnnotationList(context, this);
       if (annotations != null) {
         if (range.isArray()) {
-          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), annotations));
+          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(getJCas(), annotations));
         } else {
           if (annotations.isEmpty()) {
             annotation.setFeatureValue(feature, null);
@@ -1182,7 +1183,7 @@ public class RutaStream {
     } else if (value instanceof GenericFeatureExpression && !range.isPrimitive()) {
       FeatureExpression fe = ((GenericFeatureExpression) value).getFeatureExpression();
       Type t = fe.getInitialType(context, this);
-      List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), t);
+      List<AnnotationFS> inWindow = getAnnotationsInWindow(context.getAnnotation(), t);
       if (fe instanceof SimpleFeatureExpression) {
         SimpleFeatureExpression sfe = (SimpleFeatureExpression) fe;
         List<? extends FeatureStructure> featureAnnotations = null;
@@ -1193,15 +1194,14 @@ public class RutaStream {
           featureAnnotations = inWindow;
         }
         if (range.isArray()) {
-          annotation.setFeatureValue(feature,
-                  UIMAUtils.toFSArray(this.getJCas(), featureAnnotations));
+          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(getJCas(), featureAnnotations));
         } else if (!featureAnnotations.isEmpty()) {
           FeatureStructure a = featureAnnotations.get(0);
           annotation.setFeatureValue(feature, a);
         }
       } else {
         if (range.isArray()) {
-          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), inWindow));
+          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(getJCas(), inWindow));
         } else {
           AnnotationFS a = inWindow.get(0);
           annotation.setFeatureValue(feature, a);
@@ -1213,9 +1213,9 @@ public class RutaStream {
   private void assignAnnotationByTypeInWindow(FeatureStructure annotation, Feature feature,
           MatchContext context, Type type) {
 
-    List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), type);
+    List<AnnotationFS> inWindow = getAnnotationsInWindow(context.getAnnotation(), type);
     if (feature.getRange().isArray()) {
-      annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), inWindow));
+      annotation.setFeatureValue(feature, UIMAUtils.toFSArray(getJCas(), inWindow));
     } else {
       if (inWindow != null && !inWindow.isEmpty()) {
         AnnotationFS a = inWindow.get(0);
@@ -1326,7 +1326,7 @@ public class RutaStream {
   }
 
   public AnnotationFS getSingleAnnotationByTypeInContext(Type type, MatchContext context) {
-    List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), type);
+    List<AnnotationFS> inWindow = getAnnotationsInWindow(context.getAnnotation(), type);
     if (inWindow != null && !inWindow.isEmpty()) {
       return inWindow.get(0);
     }
@@ -1334,12 +1334,12 @@ public class RutaStream {
   }
 
   public List<AnnotationFS> getAnnotationsByTypeInContext(Type type, MatchContext context) {
-    List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), type);
+    List<AnnotationFS> inWindow = getAnnotationsInWindow(context.getAnnotation(), type);
     return inWindow;
   }
 
   public List<AnnotationFS> getBestGuessedAnnotationsAt(AnnotationFS window, Type type) {
-    List<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    List<AnnotationFS> result = new ArrayList<>();
     if (window == null || type == null) {
       return result;
     }
@@ -1444,8 +1444,8 @@ public class RutaStream {
 
   public RutaAnnotation getRutaAnnotationFor(AnnotationFS annotation, boolean create,
           RutaStream stream) {
-    Type heuristicType = this.cas.getTypeSystem().getType(RutaAnnotation.class.getName());
-    List<AnnotationFS> ras = CasUtil.selectAt(this.cas, heuristicType, annotation.getBegin(),
+    Type heuristicType = cas.getTypeSystem().getType(RutaAnnotation.class.getName());
+    List<AnnotationFS> ras = CasUtil.selectAt(cas, heuristicType, annotation.getBegin(),
             annotation.getEnd());
     for (AnnotationFS each : ras) {
       if (((RutaAnnotation) each).getAnnotation() == annotation) {
@@ -1471,10 +1471,10 @@ public class RutaStream {
   }
 
   public long getMaxRuleMatches() {
-    return this.maxRuleMatches;
+    return maxRuleMatches;
   }
 
   public long getMaxRuleElementMatches() {
-    return this.maxRuleElementMatches;
+    return maxRuleElementMatches;
   }
 }

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,9 @@
 
 package org.apache.uima.ruta.expression;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -74,10 +77,8 @@ public class AnnotationTypeExpression ex
     if (annotationExpression != null) {
       AnnotationFS annotation = annotationExpression.getAnnotation(context, stream);
       if (featureExpression != null) {
-        List<AnnotationFS> annotations = new ArrayList<>(1);
-        annotations.add(annotation);
-        Collection<? extends AnnotationFS> result = featureExpression.getAnnotations(annotations,
-                true, context, stream);
+        Collection<? extends AnnotationFS> result = featureExpression
+                .getAnnotations(asList(annotation), true, context, stream);
         if (result != null && !result.isEmpty()) {
           return result.iterator().next();
         }
@@ -110,11 +111,9 @@ public class AnnotationTypeExpression ex
         types = typeListExpression.getTypeList(context, stream);
       } else {
         Type type = getType(context, stream);
-        types = new ArrayList<>(1);
-        if (type != null) {
-          types.add(type);
-        }
+        types = type != null ? asList(type) : emptyList();
       }
+
       for (Type type : types) {
 
         if (type != null) {
@@ -131,8 +130,8 @@ public class AnnotationTypeExpression ex
             bestGuessedAnnotations = stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
                     type);
             if (bestGuessedAnnotations.isEmpty()) {
-              bestGuessedAnnotations = new ArrayList<>(1);
-              bestGuessedAnnotations.add(stream.getSingleAnnotationByTypeInContext(type, context));
+              bestGuessedAnnotations = asList(
+                      stream.getSingleAnnotationByTypeInContext(type, context));
             }
           }
 
@@ -215,8 +214,7 @@ public class AnnotationTypeExpression ex
       }
     } else if (annotationExpression != null) {
       AnnotationFS annotation = annotationExpression.getAnnotation(context, stream);
-      List<AnnotationFS> result = new ArrayList<AnnotationFS>(1);
-      result.add(annotation);
+      List<AnnotationFS> result = asList(annotation);
       if (featureExpression != null) {
         return new ArrayList<>(featureExpression.getAnnotations(result, true, context, stream));
       } else {
@@ -228,9 +226,7 @@ public class AnnotationTypeExpression ex
       if (typeListExpression != null) {
         types = typeListExpression.getTypeList(context, stream);
       } else {
-        Type type = getType(context, stream);
-        types = new ArrayList<>(1);
-        types.add(type);
+        types = asList(getType(context, stream));
       }
 
       List<AnnotationFS> annotations = new ArrayList<>();

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,8 +19,9 @@
 
 package org.apache.uima.ruta.expression.feature;
 
+import static java.util.Arrays.asList;
+
 import java.math.BigDecimal;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -148,10 +149,8 @@ public class FeatureMatchExpression exte
       FeatureStructure featureValue = fs.getFeatureValue(feature);
       if (!feature.getRange().isPrimitive() && getArg() instanceof FeatureExpression) {
         FeatureExpression fe = (FeatureExpression) getArg();
-        List<FeatureStructure> list = new ArrayList<>(1);
-        list.add(fs);
-        Collection<? extends FeatureStructure> featureAnnotations = fe.getFeatureStructures(list,
-                false, context, stream);
+        Collection<? extends FeatureStructure> featureAnnotations = fe
+                .getFeatureStructures(asList(fs), false, context, stream);
         return compare(featureValue, featureAnnotations);
       } else if (!feature.getRange().isPrimitive() && getArg() instanceof IAnnotationExpression) {
         IAnnotationExpression ae = (IAnnotationExpression) getArg();

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,8 @@
 
 package org.apache.uima.ruta.rule;
 
+import static java.util.Arrays.asList;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -68,10 +70,10 @@ public abstract class AbstractRuleElemen
     this.container = container;
     this.parent = parent;
     if (this.conditions == null) {
-      this.conditions = new ArrayList<AbstractRutaCondition>();
+      this.conditions = new ArrayList<>();
     }
     if (this.actions == null) {
-      this.actions = new ArrayList<AbstractRutaAction>();
+      this.actions = new ArrayList<>();
     }
     if (this.quantifier == null) {
       this.quantifier = new NormalQuantifier();
@@ -82,7 +84,7 @@ public abstract class AbstractRuleElemen
   public List<RuleMatch> continueSideStep(boolean after, RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     boolean newDirection = !after;
     List<AnnotationFS> matchedAnnotationsOf = ruleMatch.getMatchedAnnotationsOfElement(this);
     AnnotationFS annotation = null;
@@ -251,13 +253,11 @@ public abstract class AbstractRuleElemen
 
   @Override
   public List<Integer> getSelfIndexList() {
-    List<Integer> result = new ArrayList<Integer>(1);
     if (getContainer() == null) {
       return null;
     }
-    int indexOf = getContainer().getRuleElements().indexOf(this);
-    result.add(indexOf + 1);
-    return result;
+
+    return asList(getContainer().getRuleElements().indexOf(this) + 1);
   }
 
   @Override
@@ -364,7 +364,7 @@ public abstract class AbstractRuleElemen
 
   @Override
   public void setStartAnchor(boolean start) {
-    this.startAnchor = start;
+    startAnchor = start;
   }
 
   @Override
@@ -384,7 +384,7 @@ public abstract class AbstractRuleElemen
 
   @Override
   public void addInlinedConditionRules(List<RutaStatement> innerRules) {
-    this.inlinedConditionRuleBlocks.add(innerRules);
+    inlinedConditionRuleBlocks.add(innerRules);
   }
 
   @Override
@@ -394,7 +394,7 @@ public abstract class AbstractRuleElemen
 
   @Override
   public void addInlinedActionRules(List<RutaStatement> innerRules) {
-    this.inlinedActionRuleBlocks.add(innerRules);
+    inlinedActionRuleBlocks.add(innerRules);
   }
 
   @Override

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,8 @@
 
 package org.apache.uima.ruta.rule;
 
+import static java.util.Arrays.asList;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
@@ -56,7 +58,7 @@ public class ComposedRuleElement extends
           RuleElementContainer container, RutaBlock parent) {
     super(quantifier, conditions, actions, container, parent);
     this.elements = elements;
-    this.caretaker = new RuleElementCaretaker(this);
+    caretaker = new RuleElementCaretaker(this);
   }
 
   @Override
@@ -69,7 +71,7 @@ public class ComposedRuleElement extends
   public List<RuleMatch> startMatch(RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     if (conjunct == null) {
       ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
               stream);
@@ -78,7 +80,7 @@ public class ComposedRuleElement extends
               crowd);
     } else if (!conjunct) {
       // disjunctive
-      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new LinkedHashMap<RuleMatch, ComposedRuleElementMatch>();
+      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new LinkedHashMap<>();
       for (RuleElement each : elements) {
         ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
         RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, true);
@@ -114,7 +116,7 @@ public class ComposedRuleElement extends
       }
     } else if (conjunct) {
       // conjunctive
-      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new LinkedHashMap<RuleMatch, ComposedRuleElementMatch>();
+      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new LinkedHashMap<>();
       RuleElement anchoringRuleElement = getAnchoringRuleElement(stream);
 
       ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
@@ -188,7 +190,7 @@ public class ComposedRuleElement extends
   public List<RuleMatch> continueMatch(boolean after, AnnotationFS annotation, RuleMatch ruleMatch,
           RuleApply ruleApply, ComposedRuleElementMatch containerMatch, RuleElement sideStepOrigin,
           RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     if (conjunct == null) {
       // inner next sequential
       RuleElement nextElement = getNextElement(after, this);
@@ -203,7 +205,7 @@ public class ComposedRuleElement extends
       }
     } else if (!conjunct) {
       // disjunctive
-      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<RuleMatch, ComposedRuleElementMatch>();
+      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<>();
       for (RuleElement each : elements) {
         ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
         RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
@@ -238,7 +240,7 @@ public class ComposedRuleElement extends
       }
     } else if (conjunct) {
       // conjunctive
-      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<RuleMatch, ComposedRuleElementMatch>();
+      Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<>();
 
       RuleElement anchoringRuleElement = getAnchoringRuleElement(stream);
       ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
@@ -325,7 +327,7 @@ public class ComposedRuleElement extends
           Map<RuleMatch, ComposedRuleElementMatch> ruleMatches, boolean direction,
           RutaStream stream) {
     // TODO hotfix: this needs a correct implementation
-    Map<RuleMatch, ComposedRuleElementMatch> result = new TreeMap<RuleMatch, ComposedRuleElementMatch>(
+    Map<RuleMatch, ComposedRuleElementMatch> result = new TreeMap<>(
             ruleMatchComparator);
     Set<Entry<RuleMatch, ComposedRuleElementMatch>> entrySet = ruleMatches.entrySet();
     Entry<RuleMatch, ComposedRuleElementMatch> largestEntry = null;
@@ -365,7 +367,7 @@ public class ComposedRuleElement extends
           RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch,
           RuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     if (!stream.isSimpleGreedyForComposed()) {
       result = continueMatch(after, annotation, ruleMatch, ruleApply, containerMatch,
               sideStepOrigin, entryPoint, stream, crowd);
@@ -415,10 +417,10 @@ public class ComposedRuleElement extends
           RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch,
           RuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     RuleElementContainer container = getContainer();
     doMatch(after, annotation, ruleMatch, containerMatch, isStartAnchor(), stream, crowd);
-    if (this.equals(entryPoint) && ruleApply == null) {
+    if (equals(entryPoint) && ruleApply == null) {
       result.add(ruleMatch);
     } else if (container == null) {
       result = fallback(after, failed, annotation, ruleMatch, ruleApply, containerMatch,
@@ -456,7 +458,7 @@ public class ComposedRuleElement extends
                     sideStepOrigin, entryPoint, stream, crowd);
           }
         } else {
-          if (this.equals(entryPoint)) {
+          if (equals(entryPoint)) {
             // hotfix for UIMA-3820
             result.add(ruleMatch);
           } else {
@@ -515,22 +517,22 @@ public class ComposedRuleElement extends
           RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch,
           RuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
     RuleElementContainer parentContainer = getContainer();
     if (parentContainer instanceof ComposedRuleElement) {
       ComposedRuleElement parentElement = (ComposedRuleElement) parentContainer;
-      result = parentElement.fallbackContinue(after, failed, annotation, ruleMatch, ruleApply,
+      return parentElement.fallbackContinue(after, failed, annotation, ruleMatch, ruleApply,
               containerMatch, sideStepOrigin, entryPoint, stream, crowd);
-    } else if (sideStepOrigin != null && !failed) {
-      result = sideStepOrigin.continueSideStep(after, ruleMatch, ruleApply, containerMatch,
+    }
+
+    if (sideStepOrigin != null && !failed) {
+      return sideStepOrigin.continueSideStep(after, ruleMatch, ruleApply, containerMatch,
               entryPoint, stream, crowd);
-    } else {
-      // take care that failed matches wont be applied
-      ruleMatch.setMatched(ruleMatch.matched && !failed);
-      result.add(ruleMatch);
-      doneMatching(ruleMatch, ruleApply, stream, crowd);
     }
-    return result;
+
+    // take care that failed matches wont be applied
+    ruleMatch.setMatched(ruleMatch.matched && !failed);
+    doneMatching(ruleMatch, ruleApply, stream, crowd);
+    return asList(ruleMatch);
   }
 
   private void includeMatch(RuleMatch ruleMatch, ComposedRuleElementMatch containerMatch,
@@ -563,7 +565,7 @@ public class ComposedRuleElement extends
     RutaEnvironment environment = context.getParent().getEnvironment();
     environment.addMatchToVariable(ruleMatch, this, context, stream);
 
-    List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
+    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(
             conditions.size());
     for (AbstractRutaCondition condition : conditions) {
       crowd.beginVisit(condition, null);
@@ -652,7 +654,7 @@ public class ComposedRuleElement extends
   @Override
   public RuleElement getNextElement(boolean after, RuleElement ruleElement) {
     // return caretaker.getNextElement(after, ruleElement);
-    if (conjunct == null || this.equals(ruleElement)) {
+    if (conjunct == null || equals(ruleElement)) {
       return caretaker.getNextElement(after, ruleElement);
     } else {
       return null;

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationTypeMatcher.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationTypeMatcher.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationTypeMatcher.java Mon May 11 19:34:43 2020
@@ -19,10 +19,14 @@
 
 package org.apache.uima.ruta.rule;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.uima.cas.CAS;
@@ -48,55 +52,54 @@ public class RutaAnnotationTypeMatcher i
   @Override
   public Collection<? extends AnnotationFS> getMatchingAnnotations(RutaBlock parent,
           RutaStream stream) {
-    Collection<AnnotationFS> result = null;
     MatchContext context = new MatchContext(parent);
     // just for forcing expression top initialize
     // TODO this is maybe a bit expensive sometimes
     expression.getType(context, stream);
     if (expression.getAnnotationListExpression() != null) {
-      result = expression.getAnnotationList(context, stream);
-      if (result == null) {
-        // avoid null lists here
-        result = Collections.emptyList();
-      }
-    } else if (expression.getAnnotationExpression() != null) {
-      result = new ArrayList<>(1);
-      result.add(expression.getAnnotation(context, stream));
+      Collection<AnnotationFS> result = expression.getAnnotationList(context, stream);
+      // avoid null lists here
+      return result != null ? result : emptyList();
+    }
+    
+    if (expression.getAnnotationExpression() != null) {
+      return asList(expression.getAnnotation(context, stream));
+    }
+    
+    // TODO defer to getter of expression?
+    List<Type> types;
+    if (expression.getTypeListExpression() != null) {
+      types = expression.getTypeListExpression().getTypeList(context, stream);
     } else {
-
-      // TODO defer to getter of expression?
-      List<Type> types = null;
-      if (expression.getTypeListExpression() != null) {
-        types = expression.getTypeListExpression().getTypeList(context, stream);
+      types = asList(getType(context.getParent(), stream));
+    }
+    
+    Collection<AnnotationFS> result = new ArrayList<>();
+    for (Type type : types) {
+      if (type == null) {
+        continue;
+      }
+
+      Type overallDAType = stream.getCas().getDocumentAnnotation().getType();
+      String name = type.getName();
+      if (CAS.TYPE_NAME_DOCUMENT_ANNOTATION.equals(name)
+              || "org.apache.uima.ruta.type.Document".equals(name)
+              || overallDAType.equals(type)) {
+        // TODO what about dynamic windowing?
+        result.add(stream.getDocumentAnnotation());
       } else {
-        Type type = getType(context.getParent(), stream);
-        types = new ArrayList<>(1);
-        if (type != null) {
-          types.add(type);
-        }
+        result.addAll(stream.getAnnotations(type));
       }
-      result = new ArrayList<>();
-      for (Type type : types) {
-        if (type != null) {
-
-          Type overallDAType = stream.getCas().getDocumentAnnotation().getType();
-          String name = type.getName();
-          if (StringUtils.equals(CAS.TYPE_NAME_DOCUMENT_ANNOTATION, name)
-                  || "org.apache.uima.ruta.type.Document".equals(name)
-                  || overallDAType.equals(type)) {
-            // TODO what about dynamic windowing?
-            result.add(stream.getDocumentAnnotation());
-          } else {
-            result.addAll(stream.getAnnotations(type));
-          }
-          if (expression.getFeatureExpression() != null) {
-            result = new ArrayList<>(expression.getFeatureExpression().getAnnotations(result,
-                    CHECK_ON_FEATURE, context, stream));
-          }
-        }
+      
+      // TODO: Throwing away the result so far in this for loop seems odd
+      if (expression.getFeatureExpression() != null) {
+        @SuppressWarnings("unchecked")
+        Collection<AnnotationFS> r = (Collection<AnnotationFS>) expression.getFeatureExpression()
+                .getAnnotations(result, CHECK_ON_FEATURE, context, stream);
+        result = r;
       }
-
     }
+    
     return result;
   }
 
@@ -294,5 +297,4 @@ public class RutaAnnotationTypeMatcher i
 
     return null;
   }
-
 }

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,9 @@
 
 package org.apache.uima.ruta.rule;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -62,15 +65,13 @@ public class RutaOptionalRuleElement ext
           InferenceCrowd crowd) {
     RuleElementMatch result = new RuleElementMatch(this, containerMatch);
     result.setRuleAnchor(ruleAnchor);
-    List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
+    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(
             conditions.size());
     boolean base = true;
     MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
 
-    List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
-    if (annotation != null) {
-      textsMatched.add(annotation);
-    }
+    List<AnnotationFS> textsMatched = annotation != null ? asList(annotation) : emptyList();
+
     // already set the matched text and inform others
     result.setMatchInfo(base, textsMatched, stream);
     RutaEnvironment environment = context.getParent().getEnvironment();

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,9 @@
 
 package org.apache.uima.ruta.rule;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -56,7 +59,7 @@ public class RutaRuleElement extends Abs
   public List<RuleMatch> startMatch(RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     Collection<? extends AnnotationFS> anchors = getAnchors(stream);
     boolean useAlternatives = anchors.size() != 1;
     for (AnnotationFS eachAnchor : anchors) {
@@ -72,7 +75,7 @@ public class RutaRuleElement extends Abs
         extendedMatch = ruleMatch.copy(extendedContainerMatch, true);
       }
       doMatch(true, eachAnchor, extendedMatch, extendedContainerMatch, true, stream, crowd);
-      if (this.equals(entryPoint) && ruleApply == null) {
+      if (equals(entryPoint) && ruleApply == null) {
         result.add(extendedMatch);
       } else if (extendedMatch.matched()) {
         RuleElement after = getContainer().getNextElement(true, this);
@@ -129,7 +132,7 @@ public class RutaRuleElement extends Abs
           RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch,
           RuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
           InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     MatchContext context = new MatchContext(this, ruleMatch, after);
     if (quantifier.continueMatch(after, context, annotation, containerMatch, stream, crowd)) {
       boolean stopMatching = false;
@@ -156,7 +159,7 @@ public class RutaRuleElement extends Abs
           lastAnchor = eachAnchor;
           eachAnchor = nextAnnotations.iterator().next();
           doMatch(after, eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
-          if (this.equals(entryPoint)) {
+          if (equals(entryPoint)) {
             result.add(extendedMatch);
           } else if (extendedMatch.matched()) {
             if (quantifier.continueMatch(after, context, eachAnchor, extendedContainerMatch, stream,
@@ -189,7 +192,7 @@ public class RutaRuleElement extends Abs
           AnnotationFS eachAnchor, RuleMatch extendedMatch, RuleApply ruleApply,
           ComposedRuleElementMatch extendedContainerMatch, RuleElement sideStepOrigin,
           RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     RuleElement nextRuleElement = getContainer().getNextElement(after, this);
     if (nextRuleElement != null) {
       result = nextRuleElement.continueMatch(after, eachAnchor, extendedMatch, ruleApply,
@@ -206,7 +209,7 @@ public class RutaRuleElement extends Abs
   public List<RuleMatch> continueMatch(boolean after, AnnotationFS annotation, RuleMatch ruleMatch,
           RuleApply ruleApply, ComposedRuleElementMatch containerMatch, RuleElement sideStepOrigin,
           RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     // if() for really lazy quantifiers
     MatchContext context = new MatchContext(this, ruleMatch, after);
     if (quantifier.continueMatch(after, context, annotation, containerMatch, stream, crowd)) {
@@ -231,7 +234,7 @@ public class RutaRuleElement extends Abs
         }
         doMatch(after, eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
 
-        if (this.equals(entryPoint) && ruleApply == null) {
+        if (equals(entryPoint) && ruleApply == null) {
           result.add(extendedMatch);
         } else if (extendedMatch.matched()) {
           context = new MatchContext(this, extendedMatch, after);
@@ -247,7 +250,7 @@ public class RutaRuleElement extends Abs
             result.addAll(continueMatchSomewhereElse);
           }
         } else {
-          if (this.equals(entryPoint)) {
+          if (equals(entryPoint)) {
             // hotfix for UIMA-3820
             result.add(extendedMatch);
           } else {
@@ -272,8 +275,8 @@ public class RutaRuleElement extends Abs
           RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch,
           RuleElement sideStepOrigin, RutaStream stream, InferenceCrowd crowd,
           RuleElement entryPoint) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
-    if (this.equals(entryPoint) && ruleApply == null) {
+    List<RuleMatch> result = new ArrayList<>();
+    if (equals(entryPoint) && ruleApply == null) {
       result.add(ruleMatch);
       return result;
     }
@@ -332,16 +335,14 @@ public class RutaRuleElement extends Abs
           InferenceCrowd crowd) {
     RuleElementMatch result = new RuleElementMatch(this, containerMatch);
     result.setRuleAnchor(ruleAnchor);
-    List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
+    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(
             conditions.size());
     // boolean base = matcher.match(annotation, stream, getParent());
     boolean base = true;
     MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
 
-    List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
-    if (annotation != null) {
-      textsMatched.add(annotation);
-    }
+    List<AnnotationFS> textsMatched = annotation != null ? asList(annotation) : emptyList();
+
     // already set the matched text and inform others
     result.setMatchInfo(base, textsMatched, stream);
     RutaEnvironment environment = context.getParent().getEnvironment();

Modified: uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1877605&r1=1877604&r2=1877605&view=diff
==============================================================================
--- uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original)
+++ uima/ruta/branches/trunk-v3/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Mon May 11 19:34:43 2020
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,9 @@
 
 package org.apache.uima.ruta.rule;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -86,14 +89,14 @@ public class WildCardRuleElement extends
     if (nextElement == null) {
       nextDepth = 0;
     }
-    return new ImmutablePair<RuleElement, Integer>(nextElement, Integer.valueOf(nextDepth));
+    return new ImmutablePair<>(nextElement, Integer.valueOf(nextDepth));
   }
 
   private List<RuleMatch> tryWithNextRuleElement(RuleElement nextElement, boolean after,
           AnnotationFS annotation, RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, int nextDepth, RuleElement sideStepOrigin,
           RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     // what is the next stuff that should match?
     if (nextElement == null) {
       AnnotationFS afs = getCoveredByWildCard(after, annotation, null, stream);
@@ -130,7 +133,7 @@ public class WildCardRuleElement extends
           ComposedRuleElement cre, RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, int nextDepth, RuleElement sideStepOrigin,
           RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     AnnotationFS nextOne = annotation;
     boolean doneHere = false;
     while (!doneHere
@@ -207,7 +210,7 @@ public class WildCardRuleElement extends
     } else if (conjunct != null && !conjunct) {
       // disjunctive
       List<RuleElement> ruleElements = cre.getRuleElements();
-      List<AnnotationFS> nextPostions = new ArrayList<AnnotationFS>();
+      List<AnnotationFS> nextPostions = new ArrayList<>();
       for (RuleElement ruleElement : ruleElements) {
         if (ruleElement instanceof ComposedRuleElement) {
           AnnotationFS nextPositionForComposed = getNextPositionForComposed(
@@ -304,7 +307,7 @@ public class WildCardRuleElement extends
           RuleElement nextElement, Type defaultType, RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, int nextDepth, RuleElement sideStepOrigin,
           RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     FSIterator<AnnotationFS> iterator = getIterator(after, annotation, nextElement, defaultType,
             stream);
     // already matched something maybe, but now at the end of the document
@@ -599,7 +602,7 @@ public class WildCardRuleElement extends
           RutaRuleElement nextElement, RuleMatch ruleMatch, RuleApply ruleApply,
           ComposedRuleElementMatch containerMatch, int nextDepth, RuleElement sideStepOrigin,
           RutaStream stream, InferenceCrowd crowd) {
-    List<RuleMatch> result = new ArrayList<RuleMatch>();
+    List<RuleMatch> result = new ArrayList<>();
     RutaLiteralMatcher matcher = (RutaLiteralMatcher) nextElement.getMatcher();
     if (matcher == null) {
       return result;
@@ -742,16 +745,14 @@ public class WildCardRuleElement extends
 
     RuleElementMatch result = new RuleElementMatch(this, containerMatch);
     result.setRuleAnchor(ruleAnchor);
-    List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
+    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(
             conditions.size());
     boolean base = true;
 
     MatchContext context = new MatchContext(annotation, this, ruleMatch, true);
 
-    List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
-    if (annotation != null) {
-      textsMatched.add(annotation);
-    }
+    List<AnnotationFS> textsMatched = annotation != null ? asList(annotation) : emptyList();
+
     result.setMatchInfo(base, textsMatched, stream);
     RutaEnvironment environment = context.getParent().getEnvironment();
     environment.addMatchToVariable(ruleMatch, this, context, stream);