JAL-2808 tweak to use Iterable for set of matchers
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 7 Nov 2017 11:16:37 +0000 (11:16 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 7 Nov 2017 11:16:37 +0000 (11:16 +0000)
src/jalview/util/matcher/KeyedMatcherSet.java
src/jalview/util/matcher/KeyedMatcherSetI.java
test/jalview/util/matcher/KeyedMatcherSetTest.java

index adc04ba..35a41c2 100644 (file)
@@ -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<KeyedMatcherI> getMatchers()
+  public Iterable<KeyedMatcherI> getMatchers()
   {
-    return matchConditions.iterator();
+    return matchConditions;
   }
 
   @Override
index 7cbebab..25dc96e 100644 (file)
@@ -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<KeyedMatcherI> getMatchers();
+  Iterable<KeyedMatcherI> getMatchers();
 
   /**
    * Answers true if this object contains no conditions
index b7ff006..3018cb6 100644 (file)
@@ -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<KeyedMatcherI> 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());
+  }
 }