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 491b090  Trivial refactoring: remove duplicated code
491b090 is described below

commit 491b090adf44c6afb6ee8c2057bdb252decd32d4
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Dec 12 14:18:52 2020 +0800

    Trivial refactoring: remove duplicated code
---
 .../collection/runtime/QueryableCollection.java    | 33 +++++++++-------------
 1 file changed, 14 insertions(+), 19 deletions(-)

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 d0ad714..a73c276 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
@@ -104,16 +104,7 @@ class QueryableCollection<T> implements Queryable<T>, 
Serializable {
                     hashTableHolder.getObject(hashTableSupplier);
 
             // probe the hash table
-            final Object otherFields = fieldsExtractor1.apply(p);
-            return hashTable.entrySet().stream()
-                    .filter(entry -> hash(otherFields).equals(entry.getKey()))
-                    .flatMap(entry -> {
-                        List<U> candidateList = entry.getValue();
-                        return candidateList.stream()
-                                .filter(c -> Objects.equals(otherFields, 
fieldsExtractor2.apply(c)))
-                                .map(c -> tuple(p, c));
-                    });
-
+            return probeHashTable(hashTable, p, fieldsExtractor1, 
fieldsExtractor2);
         });
 
         return from(stream);
@@ -389,17 +380,9 @@ class QueryableCollection<T> implements Queryable<T>, 
Serializable {
                     hashTableHolder.getObject(hashTableSupplier);
 
             // probe the hash table
-            final Object otherFields = fieldsExtractor1.apply(p);
             List<Tuple2<T, U>> joinResultList =
                     null == p ? Collections.emptyList()
-                                : hashTable.entrySet().stream()
-                                            .filter(entry -> 
hash(otherFields).equals(entry.getKey()))
-                                            .flatMap(entry -> {
-                                                List<U> candidateList = 
entry.getValue();
-                                                return candidateList.stream()
-                                                        .filter(c -> 
Objects.equals(otherFields, fieldsExtractor2.apply(c)))
-                                                        .map(c -> tuple((T) p, 
(U) c));
-                                            }).collect(Collectors.toList());
+                                : probeHashTable(hashTable, (T) p, 
fieldsExtractor1, fieldsExtractor2).collect(Collectors.toList());
 
             return joinResultList.isEmpty() ? Stream.of(tuple(p, null)) : 
joinResultList.stream();
         });
@@ -407,6 +390,18 @@ class QueryableCollection<T> implements Queryable<T>, 
Serializable {
         return from(stream);
     }
 
+    private static <T, U> Stream<Tuple2<T, U>> probeHashTable(Map<Integer, 
List<U>> hashTable, T p, Function<? super T, ?> fieldsExtractor1, Function<? 
super U, ?> fieldsExtractor2) {
+        final Object otherFields = fieldsExtractor1.apply(p);
+        return hashTable.entrySet().stream()
+                .filter(entry -> hash(otherFields).equals(entry.getKey()))
+                .flatMap(entry -> {
+                    List<U> candidateList = entry.getValue();
+                    return candidateList.stream()
+                            .filter(c -> Objects.equals(otherFields, 
fieldsExtractor2.apply(c)))
+                            .map(c -> tuple(p, c));
+                });
+    }
+
     @Override
     public List<T> toList() {
         if (sourceIterable instanceof List) {

Reply via email to