svn commit: r1860956 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1860956 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java

mthl
Author: mthl
Date: Mon Jun 10 15:24:14 2019
New Revision: 1860956

URL: http://svn.apache.org/viewvc?rev=1860956&view=rev
Log:
Improved: Extract ‘intersects’ predicate in a method
(OFBIZ-11099)

The lambda expression was a bit too long, so it is preferable to
extract it in a dedicated method.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java?rev=1860956&r1=1860955&r2=1860956&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java Mon Jun 10 15:24:14 2019
@@ -94,13 +94,22 @@ public class ContainerLoader {
     private static List<ContainerConfig.Configuration> filterContainersHavingMatchingLoaders(List<String> loaders,
             Collection<ContainerConfig.Configuration> containerConfigs) {
         return containerConfigs.stream()
-                .filter(containerCfg ->
-                    UtilValidate.isEmpty(containerCfg.loaders) &&
-                    UtilValidate.isEmpty(loaders) ||
-                    containerCfg.loaders.stream().anyMatch(loader -> loaders.contains(loader)))
+                .filter(cfg -> intersects(cfg.loaders, loaders))
                 .collect(Collectors.toList());
     }
 
+    /**
+     * Checks if two collections have an intersection or are both empty.
+     *
+     * @param a the first collection which can be {@code null}
+     * @param b the second collection which can be {@code null}
+     * @return {@code true} if {@code a} and {@code b} have an intersection or are both empty.
+     */
+    private static boolean intersects(Collection<?> a, Collection<?> b) {
+        return UtilValidate.isEmpty(a) && UtilValidate.isEmpty(b)
+                || !Collections.disjoint(a, b);
+    }
+
     private static List<Container> loadContainersFromConfigurations(List<ContainerConfig.Configuration> containerConfigs,
             Config config, List<StartupCommand> ofbizCommands) throws StartupException {