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
This commit is contained in:
@@ -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;
|
||||
@@ -63,6 +64,17 @@ public final class ComponentConfig {
|
||||
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 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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user