Skip to content
Permalink
Browse files

Improved: Extract ‘intersects’ predicate in a method

(OFBIZ-11099)

The lambda expression was a bit too long, so it is preferable to
extract it in a dedicated method.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1860956 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jun 10, 2019
1 parent 266e0d0 commit ddbc034d36a0a95a13d5608dcc9a68be9d4e21b8
Showing with 13 additions and 4 deletions.
  1. +13 −4 framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java
@@ -94,13 +94,22 @@ public synchronized void load(Config config, List<StartupCommand> ofbizCommands)
private static List<ContainerConfig.Configuration> filterContainersHavingMatchingLoaders(List<String> loaders,
Collection<ContainerConfig.Configuration> containerConfigs) {
return containerConfigs.stream()
.filter(containerCfg ->
UtilValidate.isEmpty(containerCfg.loaders) &&
UtilValidate.isEmpty(loaders) ||
containerCfg.loaders.stream().anyMatch(loader -> loaders.contains(loader)))
.filter(cfg -> intersects(cfg.loaders, loaders))
.collect(Collectors.toList());
}

/**
* Checks if two collections have an intersection or are both empty.
*
* @param a the first collection which can be {@code null}
* @param b the second collection which can be {@code null}
* @return {@code true} if {@code a} and {@code b} have an intersection or are both empty.
*/
private static boolean intersects(Collection<?> a, Collection<?> b) {
return UtilValidate.isEmpty(a) && UtilValidate.isEmpty(b)
|| !Collections.disjoint(a, b);
}

private static List<Container> loadContainersFromConfigurations(List<ContainerConfig.Configuration> containerConfigs,
Config config, List<StartupCommand> ofbizCommands) throws StartupException {

0 comments on commit ddbc034

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