Author: mthl
Date: Sat Mar 2 17:35:23 2019
New Revision: 1854659
URL:
http://svn.apache.org/viewvc?rev=1854659&view=revLog:
Improved: Rewrite ‘AbstractEngine#createLocationMap’ (OFBIZ-10810)
This adds some documentation and uses the ‘forEach’ method instead of
a ‘for’ loop.
Modified:
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/engine/AbstractEngine.java
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/engine/AbstractEngine.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/engine/AbstractEngine.java?rev=1854659&r1=1854658&r2=1854659&view=diff==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/engine/AbstractEngine.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/engine/AbstractEngine.java Sat Mar 2 17:35:23 2019
@@ -37,32 +37,33 @@ import org.apache.ofbiz.service.config.m
public abstract class AbstractEngine implements GenericEngine {
public static final String module = AbstractEngine.class.getName();
+ /** Map containing aliases for service implementation locations. */
protected static final Map<String, String> locationMap = createLocationMap();
- protected ServiceDispatcher dispatcher = null;
+ protected ServiceDispatcher dispatcher;
protected AbstractEngine(ServiceDispatcher dispatcher) {
this.dispatcher = dispatcher;
}
- // creates the location alias map
+ /**
+ * Instantiates the location map.
+ *
+ * @return an immutable location map.
+ */
protected static Map<String, String> createLocationMap() {
- Map<String, String> tmpMap = new HashMap<>();
-
- List<ServiceLocation> locationsList = null;
+ Map<String, String> tmp = new HashMap<>();
+ List<ServiceLocation> locations;
try {
- locationsList = ServiceConfigUtil.getServiceEngine().getServiceLocations();
+ locations = ServiceConfigUtil.getServiceEngine().getServiceLocations();
} catch (GenericConfigException e) {
// FIXME: Refactor API so exceptions can be thrown and caught.
Debug.logError(e, module);
throw new RuntimeException(e.getMessage());
}
- for (ServiceLocation e: locationsList) {
- tmpMap.put(e.getName(), e.getLocation());
- }
-
- Debug.logInfo("Loaded Service Locations: " + tmpMap, module);
- return Collections.unmodifiableMap(tmpMap);
+ locations.forEach(loc -> tmp.put(loc.getName(), loc.getLocation()));
+ Debug.logInfo("Loaded Service Locations: " + tmp, module);
+ return Collections.unmodifiableMap(tmp);
}
/**