JAL-4062 revert to ArrayList and integrate check for 'contained' ranges in sweepsearch
[jalview.git] / src / jalview / datamodel / SearchResults.java
index 9daa752..d6545ee 100755 (executable)
@@ -23,8 +23,6 @@ package jalview.datamodel;
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 /**
  * Holds a list of search result matches, where each match is a contiguous
@@ -37,7 +35,7 @@ public class SearchResults implements SearchResultsI
 {
   private int count;
 
-  private SortedSet<SearchResultMatchI> matches = new TreeSet<>();
+  private ArrayList<SearchResultMatchI> matches = new ArrayList<>();
 
   /**
    * One match consists of a sequence reference, start and end positions.
@@ -233,12 +231,7 @@ public class SearchResults implements SearchResultsI
   {
 
     Match m = new Match(sequence, start, end);
-    Match toAdd=null;
     
-    if (matches.contains(m))
-    {
-      return false;
-    }
     boolean appending=false;
     
     // we dynamically maintain an interval to add as we test each range in the list
@@ -249,6 +242,11 @@ public class SearchResults implements SearchResultsI
     {
       if (thatm.getSequence()==sequence)
       {
+        if (thatm.contains(sequence,cstart,cend))
+        {
+          // found a match containing the current range. nothing else to do except report if we operated on the list
+          return appending;
+        }
         if (thatm.adjacent(sequence, cstart, cend))
         {
           // update the match to add with the adjacent start/end
@@ -403,7 +401,7 @@ public class SearchResults implements SearchResultsI
   @Override
   public List<SearchResultMatchI> getResults()
   {
-    return List.copyOf(matches);
+    return matches;
   }
 
   /**