You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mt...@apache.org on 2019/06/27 14:32:15 UTC

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

Author: mthl
Date: Thu Jun 27 14:32:15 2019
New Revision: 1862224

URL: http://svn.apache.org/viewvc?rev=1862224&view=rev
Log:
Improved: Rewrite ‘ComponentConfig#getAllEntityResourceInfos’
(OFBIZ-11101)

It now has a stream based implementation.

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=1862224&r1=1862223&r2=1862224&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:32:15 2019
@@ -93,23 +93,19 @@ public final class ComponentConfig {
         return getAllEntityResourceInfos(type, null);
     }
 
-    public static List<EntityResourceInfo> getAllEntityResourceInfos(String type, String componentName) {
-        List<EntityResourceInfo> entityInfos = new ArrayList<>();
-        for (ComponentConfig cc : getAllComponents()) {
-            if (componentName == null || componentName.equals(cc.getComponentName())) {
-                List<EntityResourceInfo> ccEntityInfoList = cc.getEntityResourceInfos();
-                if (UtilValidate.isEmpty(type)) {
-                    entityInfos.addAll(ccEntityInfoList);
-                } else {
-                    for (EntityResourceInfo entityResourceInfo : ccEntityInfoList) {
-                        if (type.equals(entityResourceInfo.type)) {
-                            entityInfos.add(entityResourceInfo);
-                        }
-                    }
-                }
-            }
-        }
-        return entityInfos;
+    /**
+     * Provides the list of all the entity resource information matching a type.
+     *
+     * @param type  the service resource type to match
+     * @param name  the name of the component to match
+     * @return a list of entity resource information
+     */
+    public static List<EntityResourceInfo> getAllEntityResourceInfos(String type, String name) {
+        return getAllComponents().stream()
+                .filter(cc -> name == null || name.equals(cc.getComponentName()))
+                .flatMap(cc -> cc.getEntityResourceInfos().stream())
+                .filter(eri -> UtilValidate.isEmpty(type) || type.equals(eri.type))
+                .collect(Collectors.toList());
     }
 
     /**