From 0015b488f6f8c9da98b3d30a45b34e58c46ae7f6 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 7 Nov 2017 11:16:37 +0000 Subject: [PATCH] JAL-2808 tweak to use Iterable for set of matchers --- src/jalview/util/matcher/KeyedMatcherSet.java | 5 ++- src/jalview/util/matcher/KeyedMatcherSetI.java | 3 +- test/jalview/util/matcher/KeyedMatcherSetTest.java | 33 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/jalview/util/matcher/KeyedMatcherSet.java b/src/jalview/util/matcher/KeyedMatcherSet.java index adc04ba..35a41c2 100644 --- a/src/jalview/util/matcher/KeyedMatcherSet.java +++ b/src/jalview/util/matcher/KeyedMatcherSet.java @@ -1,7 +1,6 @@ package jalview.util.matcher; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.function.Function; @@ -91,9 +90,9 @@ public class KeyedMatcherSet implements KeyedMatcherSetI } @Override - public Iterator getMatchers() + public Iterable getMatchers() { - return matchConditions.iterator(); + return matchConditions; } @Override diff --git a/src/jalview/util/matcher/KeyedMatcherSetI.java b/src/jalview/util/matcher/KeyedMatcherSetI.java index 7cbebab..25dc96e 100644 --- a/src/jalview/util/matcher/KeyedMatcherSetI.java +++ b/src/jalview/util/matcher/KeyedMatcherSetI.java @@ -1,6 +1,5 @@ package jalview.util.matcher; -import java.util.Iterator; import java.util.function.Function; /** @@ -54,7 +53,7 @@ public interface KeyedMatcherSetI * * @return */ - Iterator getMatchers(); + Iterable getMatchers(); /** * Answers true if this object contains no conditions diff --git a/test/jalview/util/matcher/KeyedMatcherSetTest.java b/test/jalview/util/matcher/KeyedMatcherSetTest.java index b7ff006..3018cb6 100644 --- a/test/jalview/util/matcher/KeyedMatcherSetTest.java +++ b/test/jalview/util/matcher/KeyedMatcherSetTest.java @@ -2,8 +2,10 @@ package jalview.util.matcher; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; +import java.util.Iterator; import java.util.function.Function; import org.testng.annotations.Test; @@ -121,4 +123,35 @@ public class KeyedMatcherSetTest kms.and(km); assertFalse(kms.isEmpty()); } + + @Test + public void testGetMatchers() + { + KeyedMatcherSetI kms = new KeyedMatcherSet(); + + /* + * empty iterable: + */ + Iterator iterator = kms.getMatchers().iterator(); + assertFalse(iterator.hasNext()); + + /* + * one matcher: + */ + KeyedMatcherI km1 = new KeyedMatcher("AF", Condition.GE, -2F); + kms.and(km1); + iterator = kms.getMatchers().iterator(); + assertSame(km1, iterator.next()); + assertFalse(iterator.hasNext()); + + /* + * two matchers: + */ + KeyedMatcherI km2 = new KeyedMatcher("AF", Condition.LT, 8F); + kms.and(km2); + iterator = kms.getMatchers().iterator(); + assertSame(km1, iterator.next()); + assertSame(km2, iterator.next()); + assertFalse(iterator.hasNext()); + } } -- 1.7.10.2