svn commit: r1863498 - in /ofbiz/ofbiz-framework/trunk/framework: base/src/main/java/org/apache/ofbiz/base/util/ base/src/test/java/org/apache/ofbiz/base/conversion/ common/src/main/java/org/apache/ofbiz/common/ widget/src/main/java/org/apache/ofbiz/wi...

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

svn commit: r1863498 - in /ofbiz/ofbiz-framework/trunk/framework: base/src/main/java/org/apache/ofbiz/base/util/ base/src/test/java/org/apache/ofbiz/base/conversion/ common/src/main/java/org/apache/ofbiz/common/ widget/src/main/java/org/apache/ofbiz/wi...

mthl
Author: mthl
Date: Sat Jul 20 16:30:45 2019
New Revision: 1863498

URL: http://svn.apache.org/viewvc?rev=1863498&view=rev
Log:
Improved: Inline ‘UtilGenerics#toList’
(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/common/src/main/java/org/apache/ofbiz/common/FindServices.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/ModelScreenWidget.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTree.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroTreeRenderer.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=1863498&r1=1863497&r2=1863498&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:30:45 2019
@@ -85,11 +85,4 @@ public final class UtilGenerics {
     public static <T> Set<T> checkSet(Object object) {
         return cast(object);
     }
-
-    /** Returns the Object argument as a parameterized List if the Object argument
-     * is an instance of List. Otherwise returns null.
-     */
-    public static <T> List<T> toList(Object obj) {
-        return (obj instanceof List) ? 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=1863498&r1=1863497&r2=1863498&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:30:45 2019
@@ -58,7 +58,8 @@ public class TestJSONConverters {
         list.add("field1");
         list.add("field2");
         JSON json = JSON.from(list);
-        convertedList = UtilGenerics.toList(converter.convert(json));
+        Object obj = converter.convert(json);
+        convertedList = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
         assertEquals("JSON to List", list, convertedList);
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java?rev=1863498&r1=1863497&r2=1863498&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java Sat Jul 20 16:30:45 2019
@@ -366,7 +366,8 @@ public class FindServices {
                 fieldOp = entityOperators.get(operation);
             }
         } else {
-            if (UtilValidate.isNotEmpty(UtilGenerics.toList(fieldValue))) {
+            List<Object> fieldList = (fieldValue instanceof List) ? UtilGenerics.cast(fieldValue) : null;
+            if (UtilValidate.isNotEmpty(fieldList)) {
                 fieldOp = EntityOperator.IN;
             } else {
                 fieldOp = EntityOperator.EQUALS;

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=1863498&r1=1863497&r2=1863498&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:30:45 2019
@@ -772,7 +772,8 @@ public abstract class AbstractModelActio
         public Object getInMemoryPersistedFromField(Object storeAgent, Map<String, Object> context) {
             Object newValue = null;
             String originalName = this.fromField.getOriginalName();
-            List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
+            Object obj = context.get("_WIDGETTRAIL_");
+            List<String> currentWidgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
             List<String> trailList = new ArrayList<>();
             if (currentWidgetTrail != null) {
                 trailList.addAll(currentWidgetTrail);
@@ -869,7 +870,8 @@ public abstract class AbstractModelActio
             }
             if (this.toScope != null && "user".equals(this.toScope)) {
                 String originalName = this.field.getOriginalName();
-                List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
+                Object obj = context.get("_WIDGETTRAIL_");
+                List<String> currentWidgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
                 String newKey = "";
                 if (currentWidgetTrail != null) {
                     newKey = StringUtil.join(currentWidgetTrail, "|");
@@ -885,7 +887,8 @@ public abstract class AbstractModelActio
                 }
             } else if (this.toScope != null && "application".equals(this.toScope)) {
                 String originalName = this.field.getOriginalName();
-                List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
+                Object obj = context.get("_WIDGETTRAIL_");
+                List<String> currentWidgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
                 String newKey = "";
                 if (currentWidgetTrail != null) {
                     newKey = StringUtil.join(currentWidgetTrail, "|");

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java?rev=1863498&r1=1863497&r2=1863498&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java Sat Jul 20 16:30:45 2019
@@ -771,9 +771,10 @@ public abstract class ModelScreenWidget
                 }
 
                 UtilGenerics.<MapStack<String>>cast(context).push();
+                Object obj = context.get("_WIDGETTRAIL_");
 
                 // build the widgetpath
-                List<String> widgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
+                List<String> widgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
                 if (widgetTrail == null) {
                     widgetTrail = new LinkedList<>();
                 }

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTree.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTree.java?rev=1863498&r1=1863497&r2=1863498&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTree.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTree.java Sat Jul 20 16:30:45 2019
@@ -549,7 +549,8 @@ public class ModelTree extends ModelWidg
                 }
             }
             if (passed) {
-                List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
+                Object obj = context.get("currentNodeTrail");
+                List<String> currentNodeTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
                 context.put("processChildren", Boolean.TRUE);
                 // this action will usually obtain the "current" entity
                 ModelTreeAction.runSubActions(this.actions, context);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java?rev=1863498&r1=1863497&r2=1863498&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java Sat Jul 20 16:30:45 2019
@@ -273,13 +273,15 @@ public class ScreenRenderer {
         String externalKeyParam = externalLoginKey == null ? "" : "&amp;externalLoginKey=" + externalLoginKey;
         context.put("externalLoginKey", externalLoginKey);
         context.put("externalKeyParam", externalKeyParam);
+        Object obj = request.getAttribute("eventMessageList");
 
         // setup message lists
-        List<String> eventMessageList = UtilGenerics.toList(request.getAttribute("eventMessageList"));
+        List<String> eventMessageList = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
         if (eventMessageList == null) {
             eventMessageList = new LinkedList<>();
         }
-        List<String> errorMessageList = UtilGenerics.toList(request.getAttribute("errorMessageList"));
+        Object obj1 = request.getAttribute("errorMessageList");
+        List<String> errorMessageList = (obj1 instanceof List) ? UtilGenerics.cast(obj1) : null;
         if (errorMessageList == null) {
             errorMessageList = new LinkedList<>();
         }
@@ -288,7 +290,8 @@ public class ScreenRenderer {
             eventMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_EVENT_MESSAGE_"), "\n", "<br/>"));
             request.removeAttribute("_EVENT_MESSAGE_");
         }
-        List<String> msgList = UtilGenerics.toList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
+        Object obj2 = request.getAttribute("_EVENT_MESSAGE_LIST_");
+        List<String> msgList = (obj2 instanceof List) ? UtilGenerics.cast(obj2) : null;
         if (msgList != null) {
             eventMessageList.addAll(msgList);
             request.removeAttribute("_EVENT_MESSAGE_LIST_");
@@ -301,7 +304,8 @@ public class ScreenRenderer {
             errorMessageList.add(UtilFormatOut.replaceString((String) session.getAttribute("_ERROR_MESSAGE_"), "\n", "<br/>"));
             session.removeAttribute("_ERROR_MESSAGE_");
         }
-        msgList = UtilGenerics.toList(request.getAttribute("_ERROR_MESSAGE_LIST_"));
+        Object obj3 = request.getAttribute("_ERROR_MESSAGE_LIST_");
+        msgList = (obj3 instanceof List) ? UtilGenerics.cast(obj3) : null;
         if (msgList != null) {
             errorMessageList.addAll(msgList);
             request.removeAttribute("_ERROR_MESSAGE_LIST_");

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java?rev=1863498&r1=1863497&r2=1863498&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java Sat Jul 20 16:30:45 2019
@@ -57,7 +57,8 @@ public class HtmlTreeRenderer extends Ht
     @Override
     public void renderNodeBegin(Appendable writer, Map<String, Object> context, ModelTree.ModelNode node, int depth) throws IOException {
         String currentNodeTrailPiped = null;
-        List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
+        Object obj = context.get("currentNodeTrail");
+        List<String> currentNodeTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
         if (node.isRootNode()) {
             appendWhitespace(writer);
             this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context);
@@ -80,7 +81,8 @@ public class HtmlTreeRenderer extends Ht
         // check to see if this node needs to be expanded.
         if (hasChildren && node.isExpandCollapse()) {
             String targetEntityId = null;
-            List<String> targetNodeTrail = UtilGenerics.toList(context.get("targetNodeTrail"));
+            Object obj1 = context.get("targetNodeTrail");
+            List<String> targetNodeTrail = (obj1 instanceof List) ? UtilGenerics.cast(obj1) : null;
             if (depth < targetNodeTrail.size()) {
                 targetEntityId = targetNodeTrail.get(depth);
             }

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroTreeRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroTreeRenderer.java?rev=1863498&r1=1863497&r2=1863498&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroTreeRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroTreeRenderer.java Sat Jul 20 16:30:45 2019
@@ -118,7 +118,8 @@ public class MacroTreeRenderer implement
     @Override
     public void renderNodeBegin(Appendable writer, Map<String, Object> context, ModelTree.ModelNode node, int depth) throws IOException {
         String currentNodeTrailPiped = null;
-        List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
+        Object obj = context.get("currentNodeTrail");
+        List<String> currentNodeTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
 
         String style = "";
         if (node.isRootNode()) {
@@ -151,7 +152,8 @@ public class MacroTreeRenderer implement
             // FIXME: Using a widget model in this way is an ugly hack.
             ModelTree.ModelNode.Link expandCollapseLink = null;
             String targetEntityId = null;
-            List<String> targetNodeTrail = UtilGenerics.toList(context.get("targetNodeTrail"));
+            Object obj1 = context.get("targetNodeTrail");
+            List<String> targetNodeTrail = (obj1 instanceof List) ? UtilGenerics.cast(obj1) : null;
             if (depth < targetNodeTrail.size()) {
                 targetEntityId = targetNodeTrail.get(depth);
             }