svn commit: r1863496 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java

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

svn commit: r1863496 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java

mthl
Author: mthl
Date: Sat Jul 20 16:28:33 2019
New Revision: 1863496

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

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.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=1863496&r1=1863495&r2=1863496&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:28:33 2019
@@ -89,22 +89,14 @@ public final class UtilGenerics {
     /** Returns the Object argument as a parameterized List if the Object argument
      * is an instance of List. Otherwise returns null.
      */
-    @SuppressWarnings("unchecked")
-    public static <T> List<T> toList(Object object) {
-        if (object != null && !(object instanceof List)) {
-            return null;
-        }
-        return (List<T>) object;
+    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.
      */
-    @SuppressWarnings("unchecked")
-    public static <K, V> Map<K, V> toMap(Object object) {
-        if (object != null && !(object instanceof Map)) {
-            return null;
-        }
-        return (Map<K, V>) object;
+    public static <K, V> Map<K, V> toMap(Object obj) {
+        return (obj instanceof Map) ? cast(obj) : null;
     }
 }