groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/2] groovy git commit: Fixes issue GROOVY-8537
Date Wed, 11 Apr 2018 06:39:51 GMT
Fixes issue GROOVY-8537

Ensures no combination is returned if any of the input iterables to
GroovyCollections.combinations() is empty.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c1eda75b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c1eda75b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c1eda75b

Branch: refs/heads/GROOVY_2_6_X
Commit: c1eda75ba1b47227be59b31a45f8d35ff9e70322
Parents: 83391ce
Author: Venkatesh-Prasad Ranganath <rvprasad@ksu.edu>
Authored: Sun Apr 8 12:45:18 2018 -0500
Committer: Paul King <paulk@asert.com.au>
Committed: Wed Apr 11 16:39:25 2018 +1000

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GroovyCollections.java | 3 +++
 src/test/groovy/util/GroovyCollectionsTest.groovy  | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c1eda75b/src/main/groovy/groovy/util/GroovyCollections.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/GroovyCollections.java b/src/main/groovy/groovy/util/GroovyCollections.java
index dff062d..3f637ef 100644
--- a/src/main/groovy/groovy/util/GroovyCollections.java
+++ b/src/main/groovy/groovy/util/GroovyCollections.java
@@ -118,6 +118,9 @@ public class GroovyCollections {
                 }
                 collectedCombos = newCombos;
             }
+
+            if (collectedCombos.isEmpty()) 
+                break;
         }
         return collectedCombos;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/c1eda75b/src/test/groovy/util/GroovyCollectionsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GroovyCollectionsTest.groovy b/src/test/groovy/util/GroovyCollectionsTest.groovy
index d605e20..1678f5b 100644
--- a/src/test/groovy/util/GroovyCollectionsTest.groovy
+++ b/src/test/groovy/util/GroovyCollectionsTest.groovy
@@ -50,6 +50,11 @@ public class GroovyCollectionsTest extends GroovyTestCase {
         // collection versions should match Collection
         assert GroovyCollections.combinations(input) as Set == expected
         assert combinations(input) as Set == expected
+
+        // an empty iterable should result in no combination
+        assert combinations([[]] + input).isEmpty()
+        assert combinations(input + [[]]).isEmpty()
+        assert combinations(input + [[]] + input).isEmpty()
     }
 
     void testTranspose() {
@@ -114,4 +119,4 @@ public class GroovyCollectionsTest extends GroovyTestCase {
     void testHashCodeCollisionInMinus() {
         assert ([[1:2],[2:3]]-[["b":"a"]]) == [[1:2],[2:3]]
     }
-}
\ No newline at end of file
+}


Mime
View raw message