svn commit: r1775238 - /ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1775238 - /ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java

Taher Alkhateeb
Author: taher
Date: Tue Dec 20 09:35:11 2016
New Revision: 1775238

URL: http://svn.apache.org/viewvc?rev=1775238&view=rev
Log:
Improved: properly implement the Optional interface for retrieving portoffset

Modified:
    ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java

Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java?rev=1775238&r1=1775237&r2=1775238&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java Tue Dec 20 09:35:11 2016
@@ -27,8 +27,6 @@ import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
-import java.util.Optional;
 import java.util.Properties;
 import java.util.TimeZone;
 
@@ -178,19 +176,16 @@ public final class Config {
     }
 
     private int getPortOffsetValue(List<StartupCommand> ofbizCommands) throws StartupException {
-        int extractedPortOffset = 0;
-        Optional<StartupCommand> portOffsetCommand = ofbizCommands.stream()
-                .filter(command -> command.getName().equals(StartupCommandUtil.StartupOption.PORTOFFSET.getName()))
-                .findFirst();
-        if(portOffsetCommand.isPresent()) {
-            Map<String,String> commandArgs = portOffsetCommand.get().getProperties();
-            try {
-                extractedPortOffset = Integer.parseInt(commandArgs.keySet().iterator().next());
-            } catch(NumberFormatException e) {
-                throw new StartupException("invalid portoffset number", e);
-            }
+        String extractedPortOffset = ofbizCommands.stream()
+            .filter(command -> command.getName().equals(StartupCommandUtil.StartupOption.PORTOFFSET.getName()))
+            .findFirst()
+                .map(ofbizCommand -> ofbizCommand.getProperties().keySet().iterator().next())
+                .orElse("0");
+        try {
+            return Integer.parseInt(extractedPortOffset);
+        } catch(NumberFormatException e) {
+            throw new StartupException("invalid portoffset number: " + extractedPortOffset, e);
         }
-        return extractedPortOffset;
     }
 
     private InetAddress getAdminAddress(Properties props) throws StartupException {