commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r792051 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/EnumUtils.java test/org/apache/commons/lang/EnumUtilsTest.java
Date Wed, 08 Jul 2009 06:45:02 GMT
Author: bayard
Date: Wed Jul  8 06:45:02 2009
New Revision: 792051

URL: http://svn.apache.org/viewvc?rev=792051&view=rev
Log:
Applying Ivan Bilenjkij's patch from LANG-513, improving the generics of the getEnumMap method

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/EnumUtils.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/EnumUtilsTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/EnumUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/EnumUtils.java?rev=792051&r1=792050&r2=792051&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/EnumUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/EnumUtils.java Wed Jul  8 06:45:02
2009
@@ -39,10 +39,13 @@
      * @param enumClass the class of the <code>enum</code> to get
      * @return the enum Map
      */
-    public static Map<String, Enum<?>> getEnumMap(Class enumClass) {
-        Map<String, Enum<?>> map = new LinkedHashMap<String, Enum<?>>();
-        Iterator<? extends Enum<?>> itr = EnumSet.allOf(enumClass).iterator();
-        while(itr.hasNext()) { Enum<?> enm = itr.next(); map.put( enm.name(), enm );
}
+    public static <E extends Enum<E>> Map<String, Enum<E>> getEnumMap(Class<E>
enumClass) {
+        Map<String, Enum<E>> map = new LinkedHashMap<String, Enum<E>>();
+
+        for (E e: EnumSet.allOf(enumClass)) {
+            map.put(e.name(), e);
+        }
+
         return map;
     }
     

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/EnumUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EnumUtilsTest.java?rev=792051&r1=792050&r2=792051&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/EnumUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/EnumUtilsTest.java Wed Jul
 8 06:45:02 2009
@@ -36,18 +36,6 @@
     }
 
     public void testGetEnumMap() {
-        try {
-            EnumUtils.getEnumMap(null);
-            fail("NullPointerException expected");
-        } catch(NullPointerException npe) {
-            // expected
-        }
-        try {
-            EnumUtils.getEnumMap(getClass());
-            fail("ClassCastException expected");
-        } catch(ClassCastException cce) {
-            // expected
-        }
         String toString = EnumUtils.getEnumMap(Traffic.class).toString(); 
         assertEquals( "getEnumMap not created correctly", "{RED=RED, AMBER=AMBER, GREEN=GREEN}",
toString);
     }



Mime
View raw message