org.jboss.lang
Class ClassRedirects

java.lang.Object
  extended by org.jboss.lang.ClassRedirects

public class ClassRedirects
extends Object

Implementations of java.lang.Class methods added in jdk5

Version:
$Revision: 227 $
Author:
Adrian Brock, Scott.Stark@jboss.org

Method Summary
static
<T> Class<? extends T>
asSubclass(Class<T> clazz, Class thisClazz)
           
static
<T> T
cast(Class<T> clazz, Object o)
          Cast an object
static boolean contains(String string, CharSequence s)
          Deprecated. As of release 1.1.0 replaced by StringRedirects.contains
static String getCanonicalName(Class clazz)
          Returns the canonical name of the the underlying class as defined by the Java Language Specification.
static Class<?> getEnclosingClass(Class clazz)
          This method cannot be implemented as it relies on native method info.
static Constructor<?> getEnclosingConstructor(Class clazz)
          This method cannot be implemented as it relies on native method info.
static Method getEnclosingMethod(Class clazz)
          This method cannot be implemented as it relies on native method info.
static
<T extends EnumImpl<T>>
T[]
getEnumConstants(Class<T> enumType)
          Get the enumeration constants
static Object[] getGenericInterfaces(Class clazz)
           
static Object getGenericSuperclass(Class clazz)
           
static String getSimpleName(Class clazz)
          Implementation of the jdk5 Class.getSimpleName() method.
static boolean isAnnotation(Class clazz)
          Whether the class is an annotation
static boolean isAnonymousClass(Class clazz)
          Returns true if and only if the underlying class is an anonymous class.
static boolean isEnum(Class clazz)
          Whether the class is an enum
static boolean isLocalClass(Class clazz)
           
static boolean isMemberClass(Class clazz)
           
static boolean isSynthetic(Class clazz)
           
static String quoteReplacement(String string)
          Deprecated. As of release 1.1.0 replaced by StringRedirects.quoteReplacement
static String replace(String string, CharSequence target, CharSequence replacement)
          Deprecated. As of release 1.1.0 replaced by StringRedirects.replace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isAnnotation

public static boolean isAnnotation(Class clazz)
Whether the class is an annotation

Parameters:
clazz - the class
Returns:
true when it is an annotation

isEnum

public static boolean isEnum(Class clazz)
Whether the class is an enum

Parameters:
clazz - the class
Returns:
true when it is an enum

getEnumConstants

public static <T extends EnumImpl<T>> T[] getEnumConstants(Class<T> enumType)
Get the enumeration constants

Type Parameters:
T - the enum type
Parameters:
enumType - the enum type
Returns:
the constants

cast

public static <T> T cast(Class<T> clazz,
                         Object o)
Cast an object

Type Parameters:
T - the expected type
Parameters:
clazz - the expected class
o - the object
Returns:
the cast object

asSubclass

public static <T> Class<? extends T> asSubclass(Class<T> clazz,
                                                Class thisClazz)
Parameters:
clazz -
thisClazz -
Returns:
thisClazz object, cast to represent a subclass of the specified class object.
Throws:
ClassCastException - if thisClazz object does not represent a subclass of the specified class (here "subclass" includes the class itself).

replace

public static String replace(String string,
                             CharSequence target,
                             CharSequence replacement)
Deprecated. As of release 1.1.0 replaced by StringRedirects.replace

Replace a character sequence

Parameters:
string - the string
target - the string to replace
replacement - the replacement text
Returns:
the result

contains

public static boolean contains(String string,
                               CharSequence s)
Deprecated. As of release 1.1.0 replaced by StringRedirects.contains

Whether the string contains the character sequence

Parameters:
string - the string
s - the character sequence
Returns:
true when it contains the sequence

quoteReplacement

public static String quoteReplacement(String string)
Deprecated. As of release 1.1.0 replaced by StringRedirects.quoteReplacement

Quote the replacement string

Parameters:
string - the quoted string

getSimpleName

public static String getSimpleName(Class clazz)
Implementation of the jdk5 Class.getSimpleName() method. Returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous.

The simple name of an array is the simple name of the component type with "[]" appended. In particular the simple name of an array whose component type is anonymous is "[]".

Parameters:
clazz - the Class instance
Returns:
the simple name of the underlying class

getCanonicalName

public static String getCanonicalName(Class clazz)
Returns the canonical name of the the underlying class as defined by the Java Language Specification. Returns null if the underlying class does not have a canonical name (i.e., if it is a local or anonymous class or an array whose component type does not have a canonical name). The difference between a fully qualified name and a canonical name can be seen in examples such as: package p; class O1 { class I{}} class O2 extends O1{}; In this example both p.O1.I and p.O2.I are fully qualified names that denote the same class, but only p.O1.I is its canonical name.

Parameters:
clazz - the Class instance
Returns:
the canonical name of the underlying class if it exists, and null otherwise.

isAnonymousClass

public static boolean isAnonymousClass(Class clazz)
Returns true if and only if the underlying class is an anonymous class.

Parameters:
clazz - the Class instance
Returns:
true if clazz is an anonymous class.
Since:
1.5

isSynthetic

public static boolean isSynthetic(Class clazz)
Parameters:
clazz -
Returns:
true if (clazz.getModifiers() & SYNTHETIC) != 0

isLocalClass

public static boolean isLocalClass(Class clazz)
Parameters:
clazz - the Class instance
Returns:
true if and only if this class is a local class.
Since:
1.5

isMemberClass

public static boolean isMemberClass(Class clazz)
Parameters:
clazz - the Class instance
Returns:
true if and only if this class is a member class.
Since:
1.5

getGenericSuperclass

public static Object getGenericSuperclass(Class clazz)
Parameters:
clazz -
Returns:
the superclass of the class represented by this object

getGenericInterfaces

public static Object[] getGenericInterfaces(Class clazz)
Parameters:
clazz -
Returns:
an array of interfaces implemented by this class

getEnclosingMethod

public static Method getEnclosingMethod(Class clazz)
This method cannot be implemented as it relies on native method info.

Parameters:
clazz -
Returns:
null

getEnclosingConstructor

public static Constructor<?> getEnclosingConstructor(Class clazz)
This method cannot be implemented as it relies on native method info.

Parameters:
clazz -
Returns:
null

getEnclosingClass

public static Class<?> getEnclosingClass(Class clazz)
This method cannot be implemented as it relies on native method info.

Parameters:
clazz -
Returns:
null


Copyright © 2005-2007 JBoss, a division of Red Hat, Inc. All Rights Reserved.