org.apache.commons.lang
クラス ClassUtils

java.lang.Object
  拡張org.apache.commons.lang.ClassUtils

public class ClassUtils
extends Object

Operates on classes without using reflection.

This class handles invalid null inputs as best it can. Each method documents its behaviour in more detail.

導入されたバージョン:
2.0
バージョン:
$Id: ClassUtils.java,v 1.1.1.1 2004/02/13 10:02:05 hioki Exp $
作成者:
Stephen Colebourne, Gary Gregory

フィールドの概要
static String INNER_CLASS_SEPARATOR
          The inner class separator String: $.
static char INNER_CLASS_SEPARATOR_CHAR
          The inner class separator character: $.
static String PACKAGE_SEPARATOR
          The package separator String: ..
static char PACKAGE_SEPARATOR_CHAR
          The package separator character: ..
 
コンストラクタの概要
ClassUtils()
          ClassUtils instances should NOT be constructed in standard programming.
 
メソッドの概要
static List convertClassesToClassNames(List classes)
          Given a List of Class objects, this method converts them into class names.
static List convertClassNamesToClasses(List classNames)
          Given a List of class names, this method converts them into classes.
static List getAllInterfaces(Class cls)
          Gets a List of all interfaces implemented by the given class and its superclasses.
static List getAllSuperclasses(Class cls)
          Gets a List of superclasses for the given class.
static String getPackageName(Class cls)
          Gets the package name of a Class.
static String getPackageName(Object object, String valueIfNull)
          Gets the package name of an Object.
static String getPackageName(String className)
          Gets the package name from a String.
static String getShortClassName(Class cls)
          Gets the class name minus the package name from a Class.
static String getShortClassName(Object object, String valueIfNull)
          Gets the class name minus the package name for an Object.
static String getShortClassName(String className)
          Gets the class name minus the package name from a String.
static boolean isAssignable(Class[] classArray, Class[] toClassArray)
          Checks if an array of Classes can be assigned to another array of Classes.
static boolean isAssignable(Class cls, Class toClass)
          Checks if one Class can be assigned to a variable of another Class.
static boolean isInnerClass(Class cls)
          Is the specified class an inner class or static nested class.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

PACKAGE_SEPARATOR_CHAR

public static final char PACKAGE_SEPARATOR_CHAR

The package separator character: ..

関連項目:
定数フィールド値

PACKAGE_SEPARATOR

public static final String PACKAGE_SEPARATOR

The package separator String: ..


INNER_CLASS_SEPARATOR_CHAR

public static final char INNER_CLASS_SEPARATOR_CHAR

The inner class separator character: $.

関連項目:
定数フィールド値

INNER_CLASS_SEPARATOR

public static final String INNER_CLASS_SEPARATOR

The inner class separator String: $.

コンストラクタの詳細

ClassUtils

public ClassUtils()

ClassUtils instances should NOT be constructed in standard programming. Instead, the class should be used as ClassUtils.getShortClassName(cls).

This constructor is public to permit tools that require a JavaBean instance to operate.

メソッドの詳細

getShortClassName

public static String getShortClassName(Object object,
                                       String valueIfNull)

Gets the class name minus the package name for an Object.

パラメータ:
object - the class to get the short name for, may be null
valueIfNull - the value to return if null
戻り値:
the class name of the object without the package name, or the null value

getShortClassName

public static String getShortClassName(Class cls)

Gets the class name minus the package name from a Class.

パラメータ:
cls - the class to get the short name for, must not be null
戻り値:
the class name without the package name
例外:
IllegalArgumentException - if the class is null

getShortClassName

public static String getShortClassName(String className)

Gets the class name minus the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

パラメータ:
className - the className to get the short name for, must not be empty or null
戻り値:
the class name of the class without the package name
例外:
IllegalArgumentException - if the className is empty

getPackageName

public static String getPackageName(Object object,
                                    String valueIfNull)

Gets the package name of an Object.

パラメータ:
object - the class to get the package name for, may be null
valueIfNull - the value to return if null
戻り値:
the package name of the object, or the null value

getPackageName

public static String getPackageName(Class cls)

Gets the package name of a Class.

パラメータ:
cls - the class to get the package name for, must not be null
戻り値:
the package name
例外:
IllegalArgumentException - if the class is null

getPackageName

public static String getPackageName(String className)

Gets the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

パラメータ:
className - the className to get the package name for, must not be empty or null
戻り値:
the package name
例外:
IllegalArgumentException - if the className is empty

getAllSuperclasses

public static List getAllSuperclasses(Class cls)

Gets a List of superclasses for the given class.

パラメータ:
cls - the class to look up, must not be null
戻り値:
the List of superclasses in order going up from this one null if null input

getAllInterfaces

public static List getAllInterfaces(Class cls)

Gets a List of all interfaces implemented by the given class and its superclasses.

The order is determined by looking through each interface in turn as declared in the source file and following its hieracrchy up. Then each superclass is considered in the same way. Later duplicates are ignored, so the order is maintained.

パラメータ:
cls - the class to look up, must not be null
戻り値:
the List of interfaces in order, null if null input

convertClassNamesToClasses

public static List convertClassNamesToClasses(List classNames)

Given a List of class names, this method converts them into classes.

A new List is returned. If the class name cannot be found, null is stored in the List. If the class name in the List is null, null is stored in the output List.

パラメータ:
classNames - the classNames to change
戻り値:
a List of Class objects corresponding to the class names, null if null input
例外:
ClassCastException - if classNames contains a non String entry

convertClassesToClassNames

public static List convertClassesToClassNames(List classes)

Given a List of Class objects, this method converts them into class names.

A new List is returned. null objects will be copied into the returned list as null.

パラメータ:
classes - the classes to change
戻り値:
a List of Class objects corresponding to the class names, null if null input
例外:
ClassCastException - if classNames contains a non Class or null entry

isAssignable

public static boolean isAssignable(Class[] classArray,
                                   Class[] toClassArray)

Checks if an array of Classes can be assigned to another array of Classes.

This method calls isAssignable for each Class pair in the input arrays. It can be used to check if a set of arguments (the first parameter) are suitably compatable with a set of method parameter types (the second parameter).

Unlike the Class.isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.

Null may be assigned to any reference type. This method will return true if null is passed in and the toClass is non-primitive.

Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.

パラメータ:
classArray - the array of Classes to check, may be null
toClassArray - the array of Classes to try to assign into, may be null
戻り値:
true if assignment possible

isAssignable

public static boolean isAssignable(Class cls,
                                   Class toClass)

Checks if one Class can be assigned to a variable of another Class.

Unlike the Class.isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.

Null may be assigned to any reference type. This method will return true if null is passed in and the toClass is non-primitive.

Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.

パラメータ:
cls - the Class to check, may be null
toClass - the Class to try to assign into, returns false if null
戻り値:
true if assignment possible

isInnerClass

public static boolean isInnerClass(Class cls)

Is the specified class an inner class or static nested class.

パラメータ:
cls - the class to check
戻り値:
true if the class is an inner or static nested class, false if not or null


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation