org.metasyntactic.core
Class ClassUtilities

java.lang.Object
  |
  +--org.metasyntactic.core.ClassUtilities

public class ClassUtilities
extends java.lang.Object

Java's Class class can fail you on occasion when dealing with the primitive classes. Case in point: Class.forName(String) fails when passed "int" or any of the other 8 primitive names. However, this is the value that getName() returns when called on any of the primitive classes!!

This class provides primitive savvy methods for dealing with classes of all types


Field Summary
static java.lang.String BOOLEAN_CLASS_NAME
          String representation of the primitive class boolean.
static java.lang.String BYTE_CLASS_NAME
          String representation of the primitive class byte.
static java.lang.String CHAR_CLASS_NAME
          String representation of the primitive class char.
static java.lang.String DOUBLE_CLASS_NAME
          String representation of the primitive class double.
static java.lang.String FLOAT_CLASS_NAME
          String representation of the primitive class float.
static java.lang.String INT_CLASS_NAME
          String representation of the primitive class int.
static java.lang.String LONG_CLASS_NAME
          String representation of the primitive class long.
static java.lang.String SHORT_CLASS_NAME
          String representation of the primitive class short.
static java.lang.String VOID_CLASS_NAME
          String representation of the primitive class void.
 
Method Summary
static java.lang.Class forName(java.lang.String name)
          This method is intended to replace Class.forName(), with an alternate that fully supports all java class names.
static java.lang.String getShortClassName(java.lang.Class type)
          generates a short class name for the given object.
static java.lang.String getShortClassName(java.lang.Object object)
          Generates a short class name for the given object.
static java.lang.String getShortClassName(java.lang.String className)
          Generates a short class name for the given classname.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT_CLASS_NAME

public static final java.lang.String INT_CLASS_NAME
String representation of the primitive class int. Should be "int" as of the latest java specification.


BYTE_CLASS_NAME

public static final java.lang.String BYTE_CLASS_NAME
String representation of the primitive class byte. Should be "byte" as of the latest java specification.


CHAR_CLASS_NAME

public static final java.lang.String CHAR_CLASS_NAME
String representation of the primitive class char. Should be "char" as of the latest java specification.


LONG_CLASS_NAME

public static final java.lang.String LONG_CLASS_NAME
String representation of the primitive class long. Should be "long" as of the latest java specification.


VOID_CLASS_NAME

public static final java.lang.String VOID_CLASS_NAME
String representation of the primitive class void. Should be "void" as of the latest java specification.


FLOAT_CLASS_NAME

public static final java.lang.String FLOAT_CLASS_NAME
String representation of the primitive class float. Should be "float" as of the latest java specification.


SHORT_CLASS_NAME

public static final java.lang.String SHORT_CLASS_NAME
String representation of the primitive class short. Should be "short" as of the latest java specification.


DOUBLE_CLASS_NAME

public static final java.lang.String DOUBLE_CLASS_NAME
String representation of the primitive class double. Should be "double" as of the latest java specification.


BOOLEAN_CLASS_NAME

public static final java.lang.String BOOLEAN_CLASS_NAME
String representation of the primitive class boolean. Should be "boolean" as of the latest java specification.

Method Detail

getShortClassName

public static java.lang.String getShortClassName(java.lang.Object object)
Generates a short class name for the given object.

Parameters:
object - The Oobject you want to get the short class name for
Returns:
The short string reprentation of this object's class
See Also:
getShortClassName(Class)

getShortClassName

public static java.lang.String getShortClassName(java.lang.Class type)
generates a short class name for the given object.
 instanceof            ->  result string
 --------------------      --------------------
 ClassName             ->  "ClassName"
 com.foo.ClassName     ->  "ClassName"
 ClassName;            ->  "ClassName[]"
 ClassName$1           ->  "ClassName.1"
 ClassName$InnerClass  ->  "ClassName.InnerClass"
 

Parameters:
type - The Class that you want to get a short name for
Returns:
A short string representation of this class

getShortClassName

public static java.lang.String getShortClassName(java.lang.String className)
Generates a short class name for the given classname.

Parameters:
className - The fully qualified class name that you want shortened
Returns:
The short version of this fully qualified class name
See Also:
getShortClassName(Class)

forName

public static java.lang.Class forName(java.lang.String name)
                               throws java.lang.ClassNotFoundException
This method is intended to replace Class.forName(), with an alternate that fully supports all java class names. Class.forName() is incapable of processing the names of primitive types and the special type 'void'

Parameters:
name - The fully qualified name of the class you wish to instantiate
Returns:
An instance of that class
Throws:
java.lang.ClassNotFoundException - If the given class could not be found
See Also:
Class.forName(java.lang.String)