From: Jim Procter Date: Wed, 2 Nov 2016 14:07:42 +0000 (+0000) Subject: JAL-354 JAL-1738 add returns SearchResultMatchI instance so it can be cached X-Git-Tag: Release_2_10_1~10^2~6^2~1^2~10 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d4b4cffe60c2fc80b7f9a56aa9c497f8077d6bed;p=jalview.git JAL-354 JAL-1738 add returns SearchResultMatchI instance so it can be cached --- diff --git a/src/jalview/datamodel/SearchResults.java b/src/jalview/datamodel/SearchResults.java index 58f8517..8cdf446 100755 --- a/src/jalview/datamodel/SearchResults.java +++ b/src/jalview/datamodel/SearchResults.java @@ -178,9 +178,11 @@ public class SearchResults implements SearchResultsI * @see jalview.datamodel.SearchResultsI#addResult(jalview.datamodel.SequenceI, int, int) */ @Override - public void addResult(SequenceI seq, int start, int end) + public SearchResultMatchI addResult(SequenceI seq, int start, int end) { - matches.add(new Match(seq, start, end)); + Match m = new Match(seq, start, end); + matches.add(m); + return m; } /* (non-Javadoc) diff --git a/src/jalview/datamodel/SearchResultsI.java b/src/jalview/datamodel/SearchResultsI.java index bc62a66..f90832a 100644 --- a/src/jalview/datamodel/SearchResultsI.java +++ b/src/jalview/datamodel/SearchResultsI.java @@ -18,8 +18,10 @@ public interface SearchResultsI * int * @param end * int + * @return SearchResultMatchI instance created for this instance */ - public abstract void addResult(SequenceI seq, int start, int end); + public abstract SearchResultMatchI addResult(SequenceI seq, int start, + int end); /** * Quickly check if the given sequence is referred to in the search results diff --git a/test/jalview/datamodel/SearchResultsTest.java b/test/jalview/datamodel/SearchResultsTest.java index a08c577..addf68e 100644 --- a/test/jalview/datamodel/SearchResultsTest.java +++ b/test/jalview/datamodel/SearchResultsTest.java @@ -27,6 +27,7 @@ import static org.testng.AssertJUnit.assertTrue; import java.util.BitSet; +import org.junit.Assert; import org.testng.annotations.Test; public class SearchResultsTest @@ -208,8 +209,13 @@ public class SearchResultsTest SearchResultsI sr = new SearchResults(); BitSet bs = new BitSet(); - sr.addResult(seq1, 1,1); - sr.addResult(seq2, 1,2); + SearchResultMatchI srm = null; + srm = sr.addResult(seq1, 1, 1); + Assert.assertNotNull("addResult didn't return Match", srm); + srm = sr.addResult(seq2, 1, 2); + assertEquals("Sequence reference not set", seq2, srm.getSequence()); + assertEquals("match start incorrect", 1, srm.getStart()); + assertEquals("match end incorrect", 2, srm.getEnd()); // set start/end range for groups to cover matches