Skip to content
Permalink
Browse files

Improved: Add ‘ComponentConfig#matchingComponentName’ static method

(OFBIZ-11101)

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


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1862225 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jun 27, 2019
1 parent 84468dd commit 0deec7b2a446ca489b7c3eba8f8296f57cdabf4a
Showing with 14 additions and 2 deletions.
  1. +14 −2 framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
@@ -30,6 +30,7 @@
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;
@@ -63,6 +64,17 @@ public static Boolean componentExists(String componentName) {
return componentConfigCache.fromGlobalName(componentName) != null;
}

/**
* 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.
*
@@ -102,7 +114,7 @@ public static Boolean componentExists(String componentName) {
*/
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 static Boolean componentExists(String componentName) {
*/
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());
}

0 comments on commit 0deec7b

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