From 745806901cdcda04d9b5c496cb5249a03af19971 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 13 Mar 2018 14:30:03 +0000 Subject: [PATCH] JAL-2839 addResult ignores duplicates --- src/jalview/datamodel/SearchResults.java | 23 ++++------------------- src/jalview/datamodel/SearchResultsI.java | 5 +---- test/jalview/datamodel/SearchResultsTest.java | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/jalview/datamodel/SearchResults.java b/src/jalview/datamodel/SearchResults.java index 63a87a8..e87b5f0 100755 --- a/src/jalview/datamodel/SearchResults.java +++ b/src/jalview/datamodel/SearchResults.java @@ -161,20 +161,17 @@ public class SearchResults implements SearchResultsI } } - /* (non-Javadoc) - * @see jalview.datamodel.SearchResultsI#addResult(jalview.datamodel.SequenceI, int, int) - */ @Override public SearchResultMatchI addResult(SequenceI seq, int start, int end) { Match m = new Match(seq, start, end); - matches.add(m); + if (!matches.contains(m)) + { + matches.add(m); + } return m; } - /* (non-Javadoc) - * @see jalview.datamodel.SearchResultsI#involvesSequence(jalview.datamodel.SequenceI) - */ @Override public boolean involvesSequence(SequenceI sequence) { @@ -190,9 +187,6 @@ public class SearchResults implements SearchResultsI return false; } - /* (non-Javadoc) - * @see jalview.datamodel.SearchResultsI#getResults(jalview.datamodel.SequenceI, int, int) - */ @Override public int[] getResults(SequenceI sequence, int start, int end) { @@ -284,27 +278,18 @@ public class SearchResults implements SearchResultsI return count; } - /* (non-Javadoc) - * @see jalview.datamodel.SearchResultsI#getSize() - */ @Override public int getSize() { return matches.size(); } - /* (non-Javadoc) - * @see jalview.datamodel.SearchResultsI#isEmpty() - */ @Override public boolean isEmpty() { return matches.isEmpty(); } - /* (non-Javadoc) - * @see jalview.datamodel.SearchResultsI#getResults() - */ @Override public List getResults() { diff --git a/src/jalview/datamodel/SearchResultsI.java b/src/jalview/datamodel/SearchResultsI.java index c3dc0e8..3c3ad4e 100644 --- a/src/jalview/datamodel/SearchResultsI.java +++ b/src/jalview/datamodel/SearchResultsI.java @@ -31,14 +31,11 @@ public interface SearchResultsI { /** - * Adds one region to the results + * Adds one region to the results (unless already added, to avoid duplicates) * * @param seq - * Sequence * @param start - * int * @param end - * int * @return */ SearchResultMatchI addResult(SequenceI seq, int start, int end); diff --git a/test/jalview/datamodel/SearchResultsTest.java b/test/jalview/datamodel/SearchResultsTest.java index 1168af2..349b5d1 100644 --- a/test/jalview/datamodel/SearchResultsTest.java +++ b/test/jalview/datamodel/SearchResultsTest.java @@ -287,4 +287,20 @@ public class SearchResultsTest "Didn't set expected number of columns in total for two successive marks", 2, tbs.cardinality()); } + + /** + * Test to verify adding doesn't create duplicate results + */ + @Test(groups = { "Functional" }) + public void testAddResult() + { + SequenceI seq1 = new Sequence("", "abcdefghijklm"); + SearchResultsI sr = new SearchResults(); + sr.addResult(seq1, 3, 5); + assertEquals(1, sr.getSize()); + sr.addResult(seq1, 3, 5); + assertEquals(1, sr.getSize()); + sr.addResult(seq1, 3, 6); + assertEquals(2, sr.getSize()); + } } -- 1.7.10.2