Author: mthl
Date: Thu Jun 27 14:31:14 2019
New Revision: 1862223
URL:
http://svn.apache.org/viewvc?rev=1862223&view=revLog:
Improved: Rewrite ‘ComponentConfig#getKeystoreInfo’
(OFBIZ-11101)
It now has a stream based implementation.
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java?rev=1862223&r1=1862222&r2=1862223&view=diff==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java Thu Jun 27 14:31:14 2019
@@ -195,17 +195,20 @@ public final class ComponentConfig {
return cc.getFullLocation(resourceLoaderName, location);
}
+ /**
+ * Provides the first key-store matching a name from a specific component.
+ *
+ * @param componentName the name of the component to match which can be {@code null}
+ * @param keystoreName the name of the key-store to match which can be {@code null}
+ * @return the first key-store matching both {@code componentName} and {@code keystoreName}.
+ */
public static KeystoreInfo getKeystoreInfo(String componentName, String keystoreName) {
- for (ComponentConfig cc : getAllComponents()) {
- if (componentName != null && componentName.equals(cc.getComponentName())) {
- for (KeystoreInfo ks : cc.getKeystoreInfos()) {
- if (keystoreName != null && keystoreName.equals(ks.getName())) {
- return ks;
- }
- }
- }
- }
- return null;
+ return getAllComponents().stream()
+ .filter(cc -> componentName != null && componentName.equals(cc.getComponentName()))
+ .flatMap(cc -> cc.getKeystoreInfos().stream())
+ .filter(ks -> keystoreName != null && keystoreName.equals(ks.getName()))
+ .findFirst()
+ .orElse(null);
}
public static String getRootLocation(String componentName) throws ComponentException {