You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2005/02/04 02:21:20 UTC

svn commit: r151282 - in jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/ClassUtils.java test/org/apache/commons/lang/ClassUtilsTest.java

Author: bayard
Date: Thu Feb  3 17:21:19 2005
New Revision: 151282

URL: http://svn.apache.org/viewcvs?view=rev&rev=151282
Log:
rolling the forName method out for the 2.1 release

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ClassUtilsTest.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java?view=diff&r1=151281&r2=151282
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java Thu Feb  3 17:21:19 2005
@@ -31,7 +31,7 @@
  * @author Gary Gregory
  * @author Norm Deane
  * @since 2.0
- * @version $Id: ClassUtils.java,v 1.35 2005/01/27 06:45:11 bayard Exp $
+ * @version $Id$
  */
 public class ClassUtils {
 
@@ -481,79 +481,6 @@
         return convertedClasses;
     }
 
-    /**
-     * <p>Enhanced version of java.lang.Class.forName(String) that can handle 
-     * primitive types and arrays using the Foo[] notation. 
-     *
-     * @param name the fully qualified name of the class to create
-     * @return the desired class
-     * @since 2.1
-     */
-    public static Class forName(String name) throws ClassNotFoundException {
-        String fixedName = name;
-        if(name.endsWith("[]")) {
-            fixedName = "[L" + name.substring(0, name.length() - "[]".length()) + ";";
-        }
-        try {
-            return Class.forName(fixedName);
-        } catch(ClassNotFoundException cnfe) {
-            // try primitives
-            if("boolean".equals(name)) {
-                return boolean.class;
-            } else
-            if("char".equals(name)) {
-                return char.class;
-            } else
-            if("byte".equals(name)) {
-                return byte.class;
-            } else
-            if("short".equals(name)) {
-                return short.class;
-            } else
-            if("int".equals(name)) {
-                return int.class;
-            } else
-            if("long".equals(name)) {
-                return long.class;
-            } else
-            if("float".equals(name)) {
-                return float.class;
-            } else
-            if("double".equals(name)) {
-                return double.class;
-            }
-
-            // try primitive arrays
-            if("boolean[]".equals(name)) {
-                return boolean[].class;
-            } else
-            if("char[]".equals(name)) {
-                return char[].class;
-            } else
-            if("byte[]".equals(name)) {
-                return byte[].class;
-            } else
-            if("short[]".equals(name)) {
-                return short[].class;
-            } else
-            if("int[]".equals(name)) {
-                return int[].class;
-            } else
-            if("long[]".equals(name)) {
-                return long[].class;
-            } else
-            if("float[]".equals(name)) {
-                return float[].class;
-            } else
-            if("double[]".equals(name)) {
-                return double[].class;
-            }
-
-            throw cnfe;
-        }
-
-    }
-    
     // Inner class
     // ----------------------------------------------------------------------
     /**

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ClassUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ClassUtilsTest.java?view=diff&r1=151281&r2=151282
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ClassUtilsTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ClassUtilsTest.java Thu Feb  3 17:21:19 2005
@@ -32,7 +32,7 @@
  *
  * @author Stephen Colebourne
  * @author Gary D. Gregory
- * @version $Id: ClassUtilsTest.java,v 1.15 2005/01/27 06:45:11 bayard Exp $
+ * @version $Id$
  */
 public class ClassUtilsTest extends TestCase {
 
@@ -387,35 +387,6 @@
         };
         // This used to return the exact same array, but no longer does.
         assertNotSame("unmodified", noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives));
-    }
-
-    public void testForName() {
-        String[] names = new String[] {
-            "boolean", "char", "byte", "short", "int", "long", "float", "double", 
-            "boolean[]", "char[]", "byte[]", "short[]", "int[]", "long[]", "float[]", "double[]", 
-            "java.lang.Object[]", "java.lang.String", "java.lang.String[]"
-        };
-
-        Class[] classes = new Class[] {
-            boolean.class, char.class, byte.class, short.class, int.class, long.class, float.class, double.class, 
-            boolean[].class, char[].class, byte[].class, short[].class, int[].class, long[].class, float[].class, double[].class, 
-            Object[].class, String.class, String[].class
-        };
-
-        for(int i=0; i<names.length; i++) {
-            try {
-                assertEquals( "Incorrect class found. ", classes[i], ClassUtils.forName(names[i]) );
-            } catch(ClassNotFoundException cnfe) {
-                fail("Failed to find class for '" + names[i] + "'");
-            }
-        }
-
-        try {
-            ClassUtils.forName("SomeSillyMadeUpClassName");
-            fail("Non-existent classname should have thrown an exception. ");
-        } catch(ClassNotFoundException cnfe) {
-            // should fail
-        }
     }
 
     public static ClassLoader newSystemClassLoader() throws  SecurityException, IllegalArgumentException {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org