Skip to content
Permalink
Browse files

Improved: Rewrite ‘ComponentConfig#getAllEntityResourceInfos’

(OFBIZ-11101)

It now has a stream based implementation.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1862224 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jun 27, 2019
1 parent c28820e commit 84468dd604f1fc7590da36decb2c448eafa3b4e9
Showing with 13 additions and 17 deletions.
  1. +13 −17 framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
@@ -93,23 +93,19 @@ public static Boolean componentExists(String componentName) {
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());
}

/**

0 comments on commit 84468dd

Please sign in to comment.
You can’t perform that action at this time.