commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r983137 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
Date Fri, 06 Aug 2010 22:44:39 GMT
Author: jcarman
Date: Fri Aug  6 22:44:38 2010
New Revision: 983137

URL: http://svn.apache.org/viewvc?rev=983137&view=rev
Log:
Generifying toMap() method (adding in possibility for type inference on return type).

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java?rev=983137&r1=983136&r2=983137&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Fri Aug
 6 22:44:38 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.lang3;
 
+import java.awt.Color;
 import java.lang.reflect.Array;
 import java.util.HashMap;
 import java.util.Map;
@@ -222,16 +223,17 @@ public class ArrayUtils {
      * @throws IllegalArgumentException  if the array contains elements other
      *  than {@link java.util.Map.Entry} and an Array
      */
-    public static Map<Object, Object> toMap(Object[] array) {
+    @SuppressWarnings("unchecked")
+    public static <K,V> Map<K, V> toMap(Object[] array) {
         if (array == null) {
             return null;
         }
-        final Map<Object, Object> map = new HashMap<Object, Object>((int) (array.length
* 1.5));
+        final Map<K, V> map = new HashMap<K, V>((int) (array.length * 1.5));
         for (int i = 0; i < array.length; i++) {
             Object object = array[i];
             if (object instanceof Map.Entry<?, ?>) {
                 Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
-                map.put(entry.getKey(), entry.getValue());
+                map.put((K)entry.getKey(), (V)entry.getValue());
             } else if (object instanceof Object[]) {
                 Object[] entry = (Object[]) object;
                 if (entry.length < 2) {
@@ -239,7 +241,7 @@ public class ArrayUtils {
                         + object
                         + "', has a length less than 2");
                 }
-                map.put(entry[0], entry[1]);
+                map.put((K)entry[0], (V)entry[1]);
             } else {
                 throw new IllegalArgumentException("Array element " + i + ", '"
                         + object



Mime
View raw message