svn commit: r1804636 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container: ComponentContainer.java ContainerConfig.java

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

svn commit: r1804636 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container: ComponentContainer.java ContainerConfig.java

jleroux@apache.org
Author: jleroux
Date: Thu Aug 10 07:10:55 2017
New Revision: 1804636

URL: http://svn.apache.org/viewvc?rev=1804636&view=rev
Log:
Improved: [FB] Package org.apache.ofbiz.base.container
(OFBIZ-9563)

Fixes some diamond operators

ComponentContainer.java
  deleted multiple unnecessary nullchecks
  added nullcheck, because sortedComponentNames could possibly be assigned as
    null through the method list()

ContainerConfig.java
  deleted multiple unnecessary else-blocks
  deleted two initializations to shorten the code and return the value directly

Thanks: Dennis Balkir

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java?rev=1804636&r1=1804635&r2=1804636&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java Thu Aug 10 07:10:55 2017
@@ -53,7 +53,7 @@ public class ComponentContainer implemen
 
     private String name;
     private final AtomicBoolean loaded = new AtomicBoolean(false);
-    private final List<Classpath> componentsClassPath = new ArrayList<Classpath>();
+    private final List<Classpath> componentsClassPath = new ArrayList<>();
 
     @Override
     public void init(List<StartupCommand> ofbizCommands, String name, String configFile) throws ContainerException {
@@ -89,7 +89,7 @@ public class ComponentContainer implemen
      * @throws ContainerException
      */
     private void loadClassPathForAllComponents(List<Classpath> componentsClassPath) throws ContainerException {
-        List<URL> allComponentUrls = new ArrayList<URL>();
+        List<URL> allComponentUrls = new ArrayList<>();
         for(Classpath classPath : componentsClassPath) {
             try {
                 allComponentUrls.addAll(Arrays.asList(classPath.getUrls()));
@@ -137,7 +137,7 @@ public class ComponentContainer implemen
         File directoryPath = FileUtil.getFile(directoryName);
         if (directoryPath.exists() && directoryPath.isDirectory()) {
             File componentLoadFile = new File(directoryPath, ComponentLoaderConfig.COMPONENT_LOAD_XML_FILENAME);
-            if (componentLoadFile != null && componentLoadFile.exists()) {
+            if (componentLoadFile.exists()) {
                 loadComponentsInDirectoryUsingLoadFile(directoryPath, componentLoadFile);
             } else {
                 loadComponentsInDirectory(directoryPath);
@@ -162,10 +162,8 @@ public class ComponentContainer implemen
         try {
             configUrl = componentLoadFile.toURI().toURL();
             List<ComponentLoaderConfig.ComponentDef> componentsToLoad = ComponentLoaderConfig.getComponentsFromConfig(configUrl);
-            if (componentsToLoad != null) {
-                for (ComponentLoaderConfig.ComponentDef def: componentsToLoad) {
-                    loadComponentFromConfig(directoryPath.toString(), def);
-                }
+            for (ComponentLoaderConfig.ComponentDef def: componentsToLoad) {
+                loadComponentFromConfig(directoryPath.toString(), def);
             }
         } catch (MalformedURLException e) {
             Debug.logError(e, "Unable to locate URL for component loading file: " + componentLoadFile.getAbsolutePath(), module);
@@ -184,6 +182,9 @@ public class ComponentContainer implemen
      */
     private void loadComponentsInDirectory(File directoryPath) throws IOException {
         String[] sortedComponentNames = directoryPath.list();
+        if (sortedComponentNames == null) {
+            throw new IllegalArgumentException("sortedComponentNames is null, directory path is invalid " + directoryPath.getPath());
+        }
         Arrays.sort(sortedComponentNames);
 
         for (String componentName: sortedComponentNames) {

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java?rev=1804636&r1=1804635&r2=1804636&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java Thu Aug 10 07:10:55 2017
@@ -47,7 +47,7 @@ public class ContainerConfig {
 
     public static final String module = ContainerConfig.class.getName();
 
-    private static Map<String, Configuration> configurations = new LinkedHashMap<String, Configuration>();
+    private static Map<String, Configuration> configurations = new LinkedHashMap<>();
 
     public static Configuration getConfiguration(String containerName, String configFile) throws ContainerException {
         Configuration configuration = configurations.get(containerName);
@@ -89,23 +89,19 @@ public class ContainerConfig {
         ContainerConfig.Configuration.Property prop = parentProp.getProperty(name);
         if (prop == null || UtilValidate.isEmpty(prop.value)) {
             return defaultValue;
-        } else {
-            return prop.value;
         }
+        return prop.value;
     }
 
     public static int getPropertyValue(ContainerConfig.Configuration parentProp, String name, int defaultValue) {
         ContainerConfig.Configuration.Property prop = parentProp.getProperty(name);
         if (prop == null || UtilValidate.isEmpty(prop.value)) {
             return defaultValue;
-        } else {
-            int num = defaultValue;
-            try {
-                num = Integer.parseInt(prop.value);
-            } catch (Exception e) {
-                return defaultValue;
-            }
-            return num;
+        }
+        try {
+            return Integer.parseInt(prop.value);
+        } catch (Exception e) {
+            return defaultValue;
         }
     }
 
@@ -113,32 +109,27 @@ public class ContainerConfig {
         ContainerConfig.Configuration.Property prop = parentProp.getProperty(name);
         if (prop == null || UtilValidate.isEmpty(prop.value)) {
             return defaultValue;
-        } else {
-            return "true".equalsIgnoreCase(prop.value);
         }
+        return "true".equalsIgnoreCase(prop.value);
     }
 
     public static String getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, String defaultValue) {
         ContainerConfig.Configuration.Property prop = parentProp.getProperty(name);
         if (prop == null || UtilValidate.isEmpty(prop.value)) {
             return defaultValue;
-        } else {
-            return prop.value;
         }
+        return prop.value;
     }
 
     public static int getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, int defaultValue) {
         ContainerConfig.Configuration.Property prop = parentProp.getProperty(name);
         if (prop == null || UtilValidate.isEmpty(prop.value)) {
             return defaultValue;
-        } else {
-            int num = defaultValue;
-            try {
-                num = Integer.parseInt(prop.value);
-            } catch (Exception e) {
-                return defaultValue;
-            }
-            return num;
+        }
+        try {
+            return Integer.parseInt(prop.value);
+        } catch (Exception e) {
+            return defaultValue;
         }
     }
 
@@ -146,9 +137,8 @@ public class ContainerConfig {
         ContainerConfig.Configuration.Property prop = parentProp.getProperty(name);
         if (prop == null || UtilValidate.isEmpty(prop.value)) {
             return defaultValue;
-        } else {
-            return "true".equalsIgnoreCase(prop.value);
         }
+        return "true".equalsIgnoreCase(prop.value);
     }
 
     private static Collection<Configuration> getConfigurationPropsFromXml(URL xmlUrl) throws ContainerException {
@@ -159,7 +149,7 @@ public class ContainerConfig {
             throw new ContainerException("Error reading the container config file: " + xmlUrl, e);
         }
         Element root = containerDocument.getDocumentElement();
-        List<Configuration> result = new ArrayList<Configuration>();
+        List<Configuration> result = new ArrayList<>();
         for (Element curElement: UtilXml.childElementList(root, "container")) {
             result.add(new Configuration(curElement));
         }
@@ -177,7 +167,7 @@ public class ContainerConfig {
             this.className = element.getAttribute("class");
             this.loaders = StringUtil.split(element.getAttribute("loaders"), ",");
 
-            properties = new LinkedHashMap<String, Property>();
+            properties = new LinkedHashMap<>();
             for (Element curElement: UtilXml.childElementList(element, "property")) {
                 Property property = new Property(curElement);
                 properties.put(property.name, property);
@@ -189,7 +179,7 @@ public class ContainerConfig {
         }
 
         public List<Property> getPropertiesWithValue(String value) {
-            List<Property> props = new LinkedList<Property>();
+            List<Property> props = new LinkedList<>();
             if (UtilValidate.isNotEmpty(properties)) {
                 for (Property p: properties.values()) {
                     if (p != null && value.equals(p.value)) {
@@ -212,7 +202,7 @@ public class ContainerConfig {
                     this.value = UtilXml.childElementValue(element, "property-value");
                 }
 
-                properties = new LinkedHashMap<String, Property>();
+                properties = new LinkedHashMap<>();
                 for (Element curElement: UtilXml.childElementList(element, "property")) {
                     Property property = new Property(curElement);
                     properties.put(property.name, property);
@@ -224,7 +214,7 @@ public class ContainerConfig {
             }
 
             public List<Property> getPropertiesWithValue(String value) {
-                List<Property> props = new LinkedList<Property>();
+                List<Property> props = new LinkedList<>();
                 if (UtilValidate.isNotEmpty(properties)) {
                     for (Property p: properties.values()) {
                         if (p != null && value.equals(p.value)) {