This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dac569  Tweak `fulljoin` to support stream
2dac569 is described below

commit 2dac569bdf9c9534cc9140ca9f4d509f238f1e6b
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Nov 21 22:52:07 2020 +0800

    Tweak `fulljoin` to support stream
---
 .../groovy/ginq/provider/collection/runtime/Queryable.java   |  6 +-----
 .../provider/collection/runtime/QueryableCollection.java     | 12 ++++++++++++
 .../collection/runtime/QueryableCollectionTest.groovy        |  8 ++++++++
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
index 57d3298..e9d71f6 100644
--- 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
+++ 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
@@ -128,11 +128,7 @@ public interface Queryable<T> {
      * @return the join result
      * @since 4.0.0
      */
-    default <U> Queryable<Tuple2<T, U>> fullJoin(Queryable<? extends U> 
queryable, BiPredicate<? super T, ? super U> joiner) {
-        Queryable<Tuple2<T, U>> lj = this.leftJoin(queryable, joiner);
-        Queryable<Tuple2<T, U>> rj = this.rightJoin(queryable, joiner);
-        return lj.union(rj);
-    }
+    <U> Queryable<Tuple2<T, U>> fullJoin(Queryable<? extends U> queryable, 
BiPredicate<? super T, ? super U> joiner);
 
     /**
      * Cross join another {@link Queryable} instance, similar to SQL's {@code 
cross join}
diff --git 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
index 057239e..5ec3010 100644
--- 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
+++ 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
@@ -95,6 +95,18 @@ class QueryableCollection<T> implements Queryable<T>, 
Serializable {
     }
 
     @Override
+    public <U> Queryable<Tuple2<T, U>> fullJoin(Queryable<? extends U> 
queryable, BiPredicate<? super T, ? super U> joiner) {
+        if (queryable instanceof QueryableCollection) {
+            ((QueryableCollection) queryable).makeReusable();
+        }
+        this.makeReusable();
+
+        Queryable<Tuple2<T, U>> lj = this.leftJoin(queryable, joiner);
+        Queryable<Tuple2<T, U>> rj = this.rightJoin(queryable, joiner);
+        return lj.union(rj);
+    }
+
+    @Override
     public <U> Queryable<Tuple2<T, U>> crossJoin(Queryable<? extends U> 
queryable) {
         Stream<Tuple2<T, U>> stream =
                 this.stream()
diff --git 
a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
 
b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
index e37720a..965f3d4 100644
--- 
a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
+++ 
b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
@@ -248,6 +248,14 @@ class QueryableCollectionTest {
     }
 
     @Test
+    void testFullJoin2() {
+        def nums1 = [1, 2, 3].stream()
+        def nums2 = [2, 3, 4].stream()
+        def result = from(nums1).fullJoin(from(nums2), (a, b) -> a == 
b).toList()
+        assert [[1, null], [2, 2], [3, 3], [null, 4]] == result
+    }
+
+    @Test
     void testCrossJoin() {
         def nums1 = [1, 2, 3]
         def nums2 = [3, 4, 5]

Reply via email to