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

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

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

jleroux@apache.org
Author: jleroux
Date: Mon Apr 30 13:30:35 2018
New Revision: 1830588

URL: http://svn.apache.org/viewvc?rev=1830588&view=rev
Log:
Improved: Generalize `toMap` to abitrary key types
(OFBIZ-10354)

The `toMap` static method doesn't use its 'K' generic type in its implementation

Thanks: Mathieu Lirzin

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java?rev=1830588&r1=1830587&r2=1830588&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java Mon Apr 30 13:30:35 2018
@@ -112,18 +112,18 @@ public final class UtilMisc {
      * @return The resulting Map
      */
     @SuppressWarnings("unchecked")
-    public static <K, V> Map<String, V> toMap(Object... data) {
+    public static <K, V> Map<K, V> toMap(Object... data) {
         if (data.length == 1 && data[0] instanceof Map) {
-            return UtilGenerics.<String, V>checkMap(data[0]);
+            return UtilGenerics.<K, V>checkMap(data[0]);
         }
         if (data.length % 2 == 1) {
             IllegalArgumentException e = new IllegalArgumentException("You must pass an even sized array to the toMap method (size = " + data.length + ")");
             Debug.logInfo(e, module);
             throw e;
         }
-        Map<String, V> map = new HashMap<>();
+        Map<K, V> map = new HashMap<>();
         for (int i = 0; i < data.length;) {
-            map.put((String) data[i++], (V) data[i++]);
+            map.put((K) data[i++], (V) data[i++]);
         }
         return map;
     }