Skip to content

Commit

Permalink
Improved: Add ‘ComponentConfig#matchingComponentName’ static method
Browse files Browse the repository at this point in the history
(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 0deec7b
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -102,7 +114,7 @@ public static List<EntityResourceInfo> getAllEntityResourceInfos(String type) {
*/
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());
Expand Down Expand Up @@ -140,7 +152,7 @@ public static List<ServiceResourceInfo> getAllServiceResourceInfos(String type)
*/
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());
}
Expand Down

0 comments on commit 0deec7b

Please sign in to comment.