JAL-3490 match count independent of contiguous matches count
[jalview.git] / src / jalview / datamodel / SearchResults.java
index 0074d2a..7c3bba7 100755 (executable)
@@ -33,6 +33,7 @@ import java.util.List;
  */
 public class SearchResults implements SearchResultsI
 {
+  private int count;
 
   private List<SearchResultMatchI> matches = new ArrayList<>();
 
@@ -168,11 +169,30 @@ public class SearchResults implements SearchResultsI
     if (!matches.contains(m))
     {
       matches.add(m);
+      count++;
     }
     return m;
   }
 
   @Override
+  public void addResult(SequenceI seq, int[] positions)
+  {
+    /*
+     * we only increment the match count by 1 - or not at all,
+     * if the matches are all duplicates of existing
+     */
+    int beforeCount = count;
+    for (int i = 0; i < positions.length - 1; i += 2)
+    {
+      addResult(seq, positions[i], positions[i + 1]);
+    }
+    if (count > beforeCount)
+    {
+      count = beforeCount + 1;
+    }
+  }
+
+  @Override
   public boolean involvesSequence(SequenceI sequence)
   {
     final int start = sequence.getStart();
@@ -286,9 +306,9 @@ public class SearchResults implements SearchResultsI
   }
 
   @Override
-  public int getSize()
+  public int getCount()
   {
-    return matches.size();
+    return count;
   }
 
   @Override