svn commit: r1863497 - in /ofbiz/ofbiz-framework/trunk/framework: base/src/main/java/org/apache/ofbiz/base/util/ base/src/test/java/org/apache/ofbiz/base/conversion/ widget/src/main/java/org/apache/ofbiz/widget/model/ widget/src/main/java/org/apache/of...

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

svn commit: r1863497 - in /ofbiz/ofbiz-framework/trunk/framework: base/src/main/java/org/apache/ofbiz/base/util/ base/src/test/java/org/apache/ofbiz/base/conversion/ widget/src/main/java/org/apache/ofbiz/widget/model/ widget/src/main/java/org/apache/of...

mthl
Author: mthl
Date: Sat Jul 20 16:29:52 2019
New Revision: 1863497

URL: http://svn.apache.org/viewvc?rev=1863497&view=rev
Log:
Improved: Inline ‘UtilGenerics#toMap’
(OFBIZ-11141)

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestJSONConverters.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java Sat Jul 20 16:29:52 2019
@@ -92,11 +92,4 @@ public final class UtilGenerics {
     public static <T> List<T> toList(Object obj) {
         return (obj instanceof List) ? cast(obj) : null;
     }
-
-    /** Returns the Object argument as a parameterized Map if the Object argument
-     * is an instance of Map. Otherwise returns null.
-     */
-    public static <K, V> Map<K, V> toMap(Object obj) {
-        return (obj instanceof Map) ? cast(obj) : null;
-    }
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestJSONConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestJSONConverters.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestJSONConverters.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestJSONConverters.java Sat Jul 20 16:29:52 2019
@@ -45,7 +45,8 @@ public class TestJSONConverters {
         map = new HashMap<>();
         map.put("field1", "value1");
         JSON json = JSON.from(map);
-        convertedMap = UtilGenerics.toMap(converter.convert(json));
+        Object obj = converter.convert(json);
+        convertedMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
         assertEquals("JSON to Map", map, convertedMap);
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java Sat Jul 20 16:29:52 2019
@@ -685,7 +685,8 @@ public abstract class AbstractModelActio
                     DispatchContext dc = WidgetWorker.getDispatcher(context).getDispatchContext();
                     // try a map called "parameters", try it first so values from here are overriden by values in the main context
                     Map<String, Object> combinedMap = new HashMap<>();
-                    Map<String, Object> parametersObj = UtilGenerics.toMap(context.get("parameters"));
+                    Object obj = context.get("parameters");
+                    Map<String, Object> parametersObj = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
                     if (parametersObj != null) {
                         combinedMap.putAll(parametersObj);
                     }
@@ -693,7 +694,8 @@ public abstract class AbstractModelActio
                     serviceContext = dc.makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, combinedMap);
                 } else if (UtilValidate.isNotEmpty(autoFieldMapString) && !"false".equals(autoFieldMapString)) {
                     FlexibleMapAccessor<Object> fieldFma = FlexibleMapAccessor.getInstance(autoFieldMapString);
-                    Map<String, Object> autoFieldMap = UtilGenerics.toMap(fieldFma.get(context));
+                    Object obj = fieldFma.get(context);
+                    Map<String, Object> autoFieldMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
                     if (autoFieldMap != null) {
                         serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext()
                                 .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, autoFieldMap);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java Sat Jul 20 16:29:52 2019
@@ -583,7 +583,8 @@ public abstract class AbstractModelCondi
                     Debug.logWarning("No permission service-name specified!", module);
                     return false;
                 }
-                Map<String, Object> serviceContext = UtilGenerics.toMap(context.get(contextMap));
+                Object obj = context.get(contextMap);
+                Map<String, Object> serviceContext = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
                 if (serviceContext != null) {
                     // copy the required internal fields
                     serviceContext.put("userLogin", context.get("userLogin"));

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java Sat Jul 20 16:29:52 2019
@@ -245,7 +245,8 @@ public class IterateSectionWidget extend
         }
 
         Map<String, Object> inputFields = UtilGenerics.checkMap(context.get("requestParameters"));
-        Map<String, Object> queryStringMap = UtilGenerics.toMap(context.get("queryStringMap"));
+        Object obj = context.get("queryStringMap");
+        Map<String, Object> queryStringMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
         if (UtilValidate.isNotEmpty(queryStringMap)) {
             inputFields.putAll(queryStringMap);
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java Sat Jul 20 16:29:52 2019
@@ -65,7 +65,8 @@ public final class ModelScreenCondition
 
         @Override
         public boolean eval(Map<String, Object> context) {
-            Map<String, Object> sectionsMap = UtilGenerics.toMap(context.get("sections"));
+            Object obj = context.get("sections");
+            Map<String, Object> sectionsMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
             return !sectionsMap.containsKey(this.sectionExdr.expandString(context));
         }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java Sat Jul 20 16:29:52 2019
@@ -467,7 +467,8 @@ public abstract class ModelWidgetConditi
                     Debug.logWarning("No permission service-name specified!", module);
                     return false;
                 }
-                Map<String, Object> serviceContext = UtilGenerics.toMap(context.get(contextMap));
+                Object obj = context.get(contextMap);
+                Map<String, Object> serviceContext = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
                 if (serviceContext != null) {
                     // copy the required internal fields
                     serviceContext.put("userLogin", context.get("userLogin"));

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java Sat Jul 20 16:29:52 2019
@@ -151,7 +151,8 @@ public class HtmlMenuWrapper {
     }
 
     public void putInContext(String menuItemName, String valueName,  Object value) {
-        Map<String, Object> valueMap = UtilGenerics.toMap(context.get(menuItemName));
+        Object obj = context.get(menuItemName);
+        Map<String, Object> valueMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
         if (valueMap == null) {
             valueMap = new HashMap<>();
             context.put(menuItemName, valueMap);
@@ -164,7 +165,8 @@ public class HtmlMenuWrapper {
     }
 
     public Object getFromContext(String menuItemName, String valueName) {
-        Map<String, Object> valueMap = UtilGenerics.toMap(context.get(menuItemName));
+        Object obj = context.get(menuItemName);
+        Map<String, Object> valueMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
         if (valueMap == null) {
             valueMap = new HashMap<>();
             context.put(menuItemName, valueMap);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java Sat Jul 20 16:29:52 2019
@@ -1510,7 +1510,8 @@ public final class MacroFormRenderer imp
     @Override
     public void renderFormatListWrapperOpen(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
         Map<String, Object> inputFields = UtilGenerics.checkMap(context.get("requestParameters"));
-        Map<String, Object> queryStringMap = UtilGenerics.toMap(context.get("queryStringMap"));
+        Object obj = context.get("queryStringMap");
+        Map<String, Object> queryStringMap = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
         if (UtilValidate.isNotEmpty(queryStringMap)) {
             inputFields.putAll(queryStringMap);
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java?rev=1863497&r1=1863496&r2=1863497&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java Sat Jul 20 16:29:52 2019
@@ -764,8 +764,9 @@ public class MacroScreenRenderer impleme
         }
 
         RequestHandler rh = RequestHandler.from(request);
+        Object obj = context.get("requestParameters");
 
-        Map<String, Object> inputFields = UtilGenerics.toMap(context.get("requestParameters"));
+        Map<String, Object> inputFields = (obj instanceof Map) ? UtilGenerics.cast(obj) : null;
         // strip out any multi form fields if the form is of type multi
         if ("multi".equals(modelForm.getType())) {
             inputFields = UtilHttp.removeMultiFormParameters(inputFields);