svn commit: r1862225 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java

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

svn commit: r1862225 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java

mthl
Author: mthl
Date: Thu Jun 27 14:33:11 2019
New Revision: 1862225

URL: http://svn.apache.org/viewvc?rev=1862225&view=rev
Log:
Improved: Add ‘ComponentConfig#matchingComponentName’ static method
(OFBIZ-11101)

This factorizes the construction of a predicate filtering components by
their names.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java?rev=1862225&r1=1862224&r2=1862225&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java Thu Jun 27 14:33:11 2019
@@ -30,6 +30,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.function.BiFunction;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 import org.apache.ofbiz.base.container.ContainerConfig;
@@ -64,6 +65,17 @@ public final class ComponentConfig {
     }
 
     /**
+     * Constructs a component predicate checking if it corresponds to a specific name.
+     *
+     * @param cname  the name of the component to match which can be {@code null}
+     *               which means "any" component
+     * @return a component predicate for matching a specific component name.
+     */
+    private static Predicate<ComponentConfig> matchingComponentName(String cname) {
+        return cc -> cname == null || cname.equals(cc.getComponentName());
+    }
+
+    /**
      * Provides the list of all the classpath information available in components.
      *
      * @return a list of classpath information
@@ -102,7 +114,7 @@ public final class ComponentConfig {
      */
     public static List<EntityResourceInfo> getAllEntityResourceInfos(String type, String name) {
         return getAllComponents().stream()
-                .filter(cc -> name == null || name.equals(cc.getComponentName()))
+                .filter(matchingComponentName(name))
                 .flatMap(cc -> cc.getEntityResourceInfos().stream())
                 .filter(eri -> UtilValidate.isEmpty(type) || type.equals(eri.type))
                 .collect(Collectors.toList());
@@ -140,7 +152,7 @@ public final class ComponentConfig {
      */
     public static List<TestSuiteInfo> getAllTestSuiteInfos(String name) {
         return getAllComponents().stream()
-                .filter(cc -> name == null || name.equals(cc.getComponentName()))
+                .filter(matchingComponentName(name))
                 .flatMap(cc -> cc.getTestSuiteInfos().stream())
                 .collect(Collectors.toList());
     }