X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSearchResults.java;h=9d357c8e2f3c2a5a09125858d3910ee89d9198ec;hb=refs%2Fheads%2Fimprovement%2FJAL-4381_dynamic_value_colouring_of_annotations;hp=8bca20d1726e42c07779dce43c977615d2aae9c8;hpb=2989fded65d7eb892018bcf783425fe23bc679d9;p=jalview.git diff --git a/src/jalview/datamodel/SearchResults.java b/src/jalview/datamodel/SearchResults.java index 8bca20d..9d357c8 100755 --- a/src/jalview/datamodel/SearchResults.java +++ b/src/jalview/datamodel/SearchResults.java @@ -22,12 +22,7 @@ package jalview.datamodel; import java.util.ArrayList; import java.util.BitSet; -import java.util.Collections; import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import com.google.common.collect.Lists; /** * Holds a list of search result matches, where each match is a contiguous @@ -40,13 +35,14 @@ public class SearchResults implements SearchResultsI { private int count; - private SortedSet matches = new TreeSet<>(); + private ArrayList matches = new ArrayList<>(); /** * 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 + public class Match + implements SearchResultMatchI, Comparable { final SequenceI sequence; @@ -165,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 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 toRemove = new ArrayList<>(); + for (SearchResultMatchI thatm : matches) { - if (thatm.getSequence()==sequence) + 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 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; } } @@ -273,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) { @@ -355,7 +358,8 @@ public class SearchResults implements SearchResultsI else { // debug - // System.err.println("Outwith bounds!" + matchStart+">"+end +" or " + // jalview.bin.Console.errPrintln("Outwith bounds!" + + // matchStart+">"+end +" or " // + matchEnd+"<"+start); } } @@ -406,7 +410,7 @@ public class SearchResults implements SearchResultsI @Override public List getResults() { - return List.copyOf(matches); + return matches; } /**