jestr.generic.type
Class TypeName

java.lang.Object
  extended byjestr.generic.type.TypeName
All Implemented Interfaces:
java.io.Serializable

public class TypeName
extends java.lang.Object
implements java.io.Serializable

Used for printing type names a bit more descriptively than "Class.toString()". Supports both a Long form and a Short form; the former prints full class names, while the latter prints only the class name itself without the package. Short form is the default.

Also prints arrays in a more user friendly format than Java does, complete with component type, and includes the length of the array if available.

To use this class, call "new TypeName(X).toString()". "X" can be either a class or an instance. If you have the instance, it is better to pass that because arrays can print a bit more descriptively (with the array's length); otherwise just pass the java.lang.Class.

Author:
David Gilliland
See Also:
Serialized Form

Constructor Summary
TypeName()
           
TypeName(java.lang.Class c)
          Constructs a TypeName for printing the given class in Short form.
TypeName(java.lang.Class c, boolean longForm)
          Constructs a TypeName for printing the given type using the specified form.
TypeName(java.lang.Object o)
          Constructs a TypeName for printing the type of the given object in Short form.
TypeName(java.lang.Object o, boolean longForm)
          Constructs a TypeName for printing the type of the given object using the specified form.
 
Method Summary
protected  java.lang.String classBaseName(java.lang.String name)
           
protected  java.lang.String className(java.lang.Class c)
           
protected  java.lang.String formatTypeName(java.lang.Class theClass)
           
protected  java.lang.String formatTypeName(java.lang.Object obj)
           
 java.lang.Class getClazz()
          Returns the class we are printing.
 boolean getLongForm()
          Returns whether Long form is being used.
 java.lang.Object getObject()
          Returns the object we are printing.
 void setLongForm(boolean longForm)
          Sets whether Long form is to be used the next time toString() is invoked.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypeName

public TypeName()

TypeName

public TypeName(java.lang.Object o)
Constructs a TypeName for printing the type of the given object in Short form.


TypeName

public TypeName(java.lang.Class c)
Constructs a TypeName for printing the given class in Short form.


TypeName

public TypeName(java.lang.Object o,
                boolean longForm)
Constructs a TypeName for printing the type of the given object using the specified form. If longForm is true, Long form will be used; else Short form will be used.

Parameters:
o - - The object whose class should be printed. Can be null in which case toString will return the string "null".

TypeName

public TypeName(java.lang.Class c,
                boolean longForm)
Constructs a TypeName for printing the given type using the specified form. If longForm is true, Long form will be used; else Short form will be used.

Parameters:
c - - The class to print. Can be null in which case toString will return the string "null".
Method Detail

getLongForm

public boolean getLongForm()
Returns whether Long form is being used.


setLongForm

public void setLongForm(boolean longForm)
Sets whether Long form is to be used the next time toString() is invoked. Long or Short form can be specified in the constructor, or it can changed at any time by calling this method.


getClazz

public java.lang.Class getClazz()
Returns the class we are printing.


getObject

public java.lang.Object getObject()
Returns the object we are printing. If the Class constructor was used there will be no object and this method will return null.


classBaseName

protected java.lang.String classBaseName(java.lang.String name)

className

protected java.lang.String className(java.lang.Class c)

toString

public java.lang.String toString()

formatTypeName

protected java.lang.String formatTypeName(java.lang.Class theClass)

formatTypeName

protected java.lang.String formatTypeName(java.lang.Object obj)


Copyright (c) 2001-2003 - Apache Software Foundation