You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/04/11 06:38:48 UTC

[1/2] groovy git commit: Fixes issue GROOVY-8537

Repository: groovy
Updated Branches:
  refs/heads/master 297189289 -> e6a0efdbf


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/93ecc0ad
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/93ecc0ad
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/93ecc0ad

Branch: refs/heads/master
Commit: 93ecc0ad47b613e76c47689afc7b93afea6a371b
Parents: 2971892
Author: Venkatesh-Prasad Ranganath <rv...@ksu.edu>
Authored: Sun Apr 8 12:45:18 2018 -0500
Committer: Paul King <pa...@asert.com.au>
Committed: Wed Apr 11 16:24:07 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/93ecc0ad/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/93ecc0ad/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
+}


[2/2] groovy git commit: GROOVY-8537: GroovyCollections.combinations should return an empty list if one of the source collections is empty (closes #682)

Posted by pa...@apache.org.
GROOVY-8537: GroovyCollections.combinations should return an empty list if one of the source collections is empty (closes #682)


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

Branch: refs/heads/master
Commit: e6a0efdbf2c8ec836949f01a208a569fc325fafc
Parents: 93ecc0a
Author: Paul King <pa...@asert.com.au>
Authored: Wed Apr 11 16:38:41 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Wed Apr 11 16:38:41 2018 +1000

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GroovyCollections.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/e6a0efdb/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 3f637ef..19bef50 100644
--- a/src/main/groovy/groovy/util/GroovyCollections.java
+++ b/src/main/groovy/groovy/util/GroovyCollections.java
@@ -91,6 +91,7 @@ public class GroovyCollections {
      * is <code>[['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]</code>.
      * If a non-collection item is given, it is treated as a singleton collection,
      * i.e. <code>combinations([[1, 2], 'x'])</code> is <code>[[1, 'x'], [2, 'x']]</code>.
+     * If an empty collection is found within the given collections, the result will be an empty list.
      *
      * @param collections the Iterable of given collections
      * @return a List of the combinations found