From 0deec7b2a446ca489b7c3eba8f8296f57cdabf4a Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Thu, 27 Jun 2019 14:33:11 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Add=20=E2=80=98ComponentConfig#matc?= =?UTF-8?q?hingComponentName=E2=80=99=20static=20method=20(OFBIZ-11101)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../ofbiz/base/component/ComponentConfig.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java index 78682c4275..e02629cb5a 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java @@ -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 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 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 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()); }