Skip to content

Commit

Permalink
Improved: Add ‘ComponentConfig#components’ static method
Browse files Browse the repository at this point in the history
(OFBIZ-11101)

This factorizes the construction of a stream for the collection of
components.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1862226 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jun 27, 2019
1 parent 0deec7b commit ae90412
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.ofbiz.base.container.ContainerConfig;
import org.apache.ofbiz.base.container.ContainerConfig.Configuration;
Expand Down Expand Up @@ -81,7 +82,7 @@ private static Predicate<ComponentConfig> matchingComponentName(String cname) {
* @return a list of classpath information
*/
public static List<ClasspathInfo> getAllClasspathInfos() {
return getAllComponents().stream()
return components()
.flatMap(cc -> cc.getClasspathInfos().stream())
.collect(Collectors.toList());
}
Expand All @@ -90,13 +91,17 @@ public static Collection<ComponentConfig> getAllComponents() {
return componentConfigCache.values();
}

public static Stream<ComponentConfig> components() {
return componentConfigCache.values().stream();
}

/**
* Provides the list of all the container configuration elements available in components.
*
* @return a list of container configuration elements
*/
public static List<ContainerConfig.Configuration> getAllConfigurations() {
return getAllComponents().stream()
return components()
.flatMap(cc -> cc.getConfigurations().stream())
.collect(Collectors.toList());
}
Expand All @@ -113,7 +118,7 @@ public static List<EntityResourceInfo> getAllEntityResourceInfos(String type) {
* @return a list of entity resource information
*/
public static List<EntityResourceInfo> getAllEntityResourceInfos(String type, String name) {
return getAllComponents().stream()
return components()
.filter(matchingComponentName(name))
.flatMap(cc -> cc.getEntityResourceInfos().stream())
.filter(eri -> UtilValidate.isEmpty(type) || type.equals(eri.type))
Expand All @@ -126,7 +131,7 @@ public static List<EntityResourceInfo> getAllEntityResourceInfos(String type, St
* @return a list of keystore information
*/
public static List<KeystoreInfo> getAllKeystoreInfos() {
return getAllComponents().stream()
return components()
.flatMap(cc -> cc.getKeystoreInfos().stream())
.collect(Collectors.toList());
}
Expand All @@ -138,7 +143,7 @@ public static List<KeystoreInfo> getAllKeystoreInfos() {
* @return a list of service resource information
*/
public static List<ServiceResourceInfo> getAllServiceResourceInfos(String type) {
return getAllComponents().stream()
return components()
.flatMap(cc -> cc.getServiceResourceInfos().stream())
.filter(sri -> UtilValidate.isEmpty(type) || type.equals(sri.type))
.collect(Collectors.toList());
Expand All @@ -151,7 +156,7 @@ public static List<ServiceResourceInfo> getAllServiceResourceInfos(String type)
* @return a list of test-suite information
*/
public static List<TestSuiteInfo> getAllTestSuiteInfos(String name) {
return getAllComponents().stream()
return components()
.filter(matchingComponentName(name))
.flatMap(cc -> cc.getTestSuiteInfos().stream())
.collect(Collectors.toList());
Expand All @@ -163,7 +168,7 @@ public static List<TestSuiteInfo> getAllTestSuiteInfos(String name) {
* @return a list of web-app information
*/
public static List<WebappInfo> getAllWebappResourceInfos() {
return getAllComponents().stream()
return components()
.flatMap(cc -> cc.getWebappInfos().stream())
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -211,7 +216,7 @@ public static String getFullLocation(String componentName, String resourceLoader
* @return the first key-store matching both {@code componentName} and {@code keystoreName}.
*/
public static KeystoreInfo getKeystoreInfo(String componentName, String keystoreName) {
return getAllComponents().stream()
return components()
.filter(cc -> componentName != null && componentName.equals(cc.getComponentName()))
.flatMap(cc -> cc.getKeystoreInfos().stream())
.filter(ks -> keystoreName != null && keystoreName.equals(ks.getName()))
Expand Down

0 comments on commit ae90412

Please sign in to comment.