JAL-4090 JAL-1551 spotlessApply
[jalview.git] / src / jalview / datamodel / SearchResults.java
index 546dd6f..9d357c8 100755 (executable)
@@ -41,7 +41,8 @@ public class SearchResults implements SearchResultsI
    * One match consists of a sequence reference, start and end positions.
    * Discontiguous ranges in a sequence require two or more Match objects.
    */
-  public class Match implements SearchResultMatchI, Comparable<SearchResultMatchI>
+  public class Match
+          implements SearchResultMatchI, Comparable<SearchResultMatchI>
   {
     final SequenceI sequence;
 
@@ -160,16 +161,19 @@ public class SearchResults implements SearchResultsI
     {
       return (sequence == seq && start <= from && end >= to);
     }
+
     @Override
     public boolean adjacent(SequenceI seq, int from, int to)
     {
-      return (sequence == seq && ((start <= from && end >= to) || (from<=(end+1) && to >=(end+1)) || (from<=(start-1) && to>=(start-1))));
+      return (sequence == seq && ((start <= from && end >= to)
+              || (from <= (end + 1) && to >= (end + 1))
+              || (from <= (start - 1) && to >= (start - 1))));
     }
 
     @Override
     public int compareTo(SearchResultMatchI o)
     {
-      if (start<o.getStart())
+      if (start < o.getStart())
       {
         return -1;
       }
@@ -185,14 +189,14 @@ public class SearchResults implements SearchResultsI
       {
         return +1;
       }
-      if (sequence!=o.getSequence())
+      if (sequence != o.getSequence())
       {
-        int hashc =sequence.hashCode(),oseq=o.getSequence().hashCode();
+        int hashc = sequence.hashCode(), oseq = o.getSequence().hashCode();
         return (hashc < oseq) ? -1 : 1;
       }
       return 0;
     }
-    
+
   }
 
   @Override
@@ -224,27 +228,28 @@ public class SearchResults implements SearchResultsI
       count = beforeCount + 1;
     }
   }
-  
 
   @Override
   public boolean appendResult(SequenceI sequence, int start, int end)
   {
 
     Match m = new Match(sequence, start, end);
-    
-    boolean appending=false;
-    
-    // we dynamically maintain an interval to add as we test each range in the list
-    
-    int cstart=start,cend=end;
-    List<SearchResultMatchI> toRemove=new ArrayList<>();
-    for (SearchResultMatchI thatm:matches)
+
+    boolean appending = false;
+
+    // we dynamically maintain an interval to add as we test each range in the
+    // list
+
+    int cstart = start, cend = end;
+    List<SearchResultMatchI> toRemove = new ArrayList<>();
+    for (SearchResultMatchI thatm : matches)
     {
-      if (thatm.getSequence()==sequence)
+      if (thatm.getSequence() == sequence)
       {
-        if (thatm.contains(sequence,cstart,cend))
+        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
+          // 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))
@@ -253,14 +258,16 @@ public class SearchResults implements SearchResultsI
           start = Math.min(m.start, thatm.getStart());
           end = Math.max(m.end, thatm.getEnd());
           // and check if we keep or remove the old one
-          if (thatm.getStart()!=start || thatm.getEnd()!=end)
-          { 
+          if (thatm.getStart() != start || thatm.getEnd() != end)
+          {
             toRemove.add(thatm);
             count--;
             cstart = start;
             cend = end;
-            appending=true;
-          } else {
+            appending = true;
+          }
+          else
+          {
             return false;
           }
         }
@@ -268,11 +275,12 @@ public class SearchResults implements SearchResultsI
     }
     matches.removeAll(toRemove);
     {
-      matches.add(new Match(sequence,cstart,cend));
+      matches.add(new Match(sequence, cstart, cend));
       count++;
     }
     return appending;
   }
+
   @Override
   public boolean involvesSequence(SequenceI sequence)
   {
@@ -350,7 +358,8 @@ public class SearchResults implements SearchResultsI
         else
         {
           // debug
-          // jalview.bin.Console.errPrintln("Outwith bounds!" + matchStart+">"+end +" or "
+          // jalview.bin.Console.errPrintln("Outwith bounds!" +
+          // matchStart+">"+end +" or "
           // + matchEnd+"<"+start);
         }
       }