JAL-3187 clunky sort by renderorder in findComplementFeaturesAtResidue
[jalview.git] / src / jalview / viewmodel / seqfeatures / FeatureRendererModel.java
index 7faf7ea..2324a64 100644 (file)
@@ -1157,7 +1157,8 @@ public abstract class FeatureRendererModel
   /**
    * Answers a (possibly empty) list of features in this alignment at a position
    * (or range) which is mappable from the given sequence residue position in a
-   * mapped alignment.
+   * mapped alignment. Features are returned in render order of feature type (on
+   * top last), with order within feature type undefined.
    * 
    * @param sequence
    * @param pos
@@ -1166,7 +1167,7 @@ public abstract class FeatureRendererModel
   public List<SequenceFeature> findComplementFeaturesAtResidue(SequenceI sequence, int pos)
   {
     SequenceI ds = sequence.getDatasetSequence();
-    List<SequenceFeature> result = new ArrayList<>();
+    List<SequenceFeature> found = new ArrayList<>();
     List<AlignedCodonFrame> mappings = this.av.getAlignment()
             .getCodonFrame(sequence);
 
@@ -1192,9 +1193,27 @@ public abstract class FeatureRendererModel
                 match.getSequence(), fromRes, toRes);
         for (SequenceFeature sf : fs)
         {
-          if (!result.contains(sf))
+          if (!found.contains(sf))
+          {
+            found.add(sf);
+          }
+        }
+      }
+    }
+    /*
+     * sort by renderorder, inefficiently
+     */
+    List<SequenceFeature> result = new ArrayList<>();
+    for (String type : renderOrder)
+    {
+      for (SequenceFeature sf : found)
+      {
+        if (type.equals(sf.getType()))
+        {
+          result.add(sf);
+          if (result.size() == found.size())
           {
-            result.add(sf);
+            return result;
           }
         }
       }