类 ClassUtils
- java.lang.Object
-
- io.microsphere.util.BaseUtils
-
- io.microsphere.util.ClassUtils
-
public abstract class ClassUtils extends BaseUtils
Class
utility class- 从以下版本开始:
- 1.0.0
- 版本:
- 1.0.0
- 作者:
- Mercy
- 另请参阅:
ClassUtils
-
-
字段概要
字段 修饰符和类型 字段 说明 static java.lang.String
ARRAY_SUFFIX
Suffix for array class names: "[]"static java.util.Set<java.lang.Class<?>>
PRIMITIVE_TYPES
static java.util.Set<java.lang.Class<?>>
SIMPLE_TYPES
Simple Types including:Void
Boolean
Character
Byte
Integer
Float
Double
String
BigDecimal
BigInteger
Date
Object
-
构造器概要
构造器 构造器 说明 ClassUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static boolean
arrayTypeEquals(java.lang.Class<?> oneArrayType, java.lang.Class<?> anotherArrayType)
static <T> T
cast(java.lang.Object object, java.lang.Class<T> castType)
Cast the given object to the specified typestatic java.lang.Object
convertPrimitive(java.lang.Class<?> type, java.lang.String value)
protected static java.util.Set<java.lang.String>
findClassNamesInArchiveDirectory(java.io.File classesDirectory, boolean recursive)
protected static java.util.Set<java.lang.String>
findClassNamesInArchiveFile(java.io.File jarFile, boolean recursive)
static java.util.Set<java.lang.String>
findClassNamesInClassPath(java.io.File archiveFile, boolean recursive)
Find all class names in class pathstatic java.util.Set<java.lang.String>
findClassNamesInClassPath(java.lang.String classPath, boolean recursive)
Find all class names in class pathprotected static java.util.Set<java.lang.String>
findClassNamesInDirectory(java.io.File classesDirectory, boolean recursive)
protected static java.util.Set<java.lang.String>
findClassNamesInJarFile(java.io.File jarFile, boolean recursive)
static java.util.Set<java.lang.Class<?>>
getAllClasses(java.lang.Class<?> type, boolean includedSelf, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
Get all classes(may include self type) from the specified type with filtersstatic java.util.Set<java.lang.Class<?>>
getAllClasses(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
Get all classes from the specified type with filtersstatic java.util.Set<java.lang.Class<?>>
getAllInheritedTypes(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... typeFilters)
Get all inherited types from the specified typestatic java.util.Set<java.lang.Class<?>>
getAllInterfaces(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... interfaceFilters)
Get all interfaces from the specified typestatic java.util.Set<java.lang.Class<?>>
getAllSuperClasses(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
Get all super classes from the specified typestatic java.lang.String
getSimpleName(java.lang.Class<?> type)
Get the simple name of the specified typestatic java.lang.Class<?>
getTopComponentType(java.lang.Class<?> arrayType)
static java.lang.Class<?>
getTopComponentType(java.lang.Object array)
static java.lang.String
getTypeName(java.lang.Class<?> type)
Get the name of the specified typestatic java.lang.Class[]
getTypes(java.lang.Object... values)
Resolve the types of the specified valuesstatic boolean
isAbstractClass(java.lang.Class<?> type)
Is the specified type a abstract class or not?static boolean
isAnnotation(int modifiers)
static boolean
isArray(java.lang.Class<?> type)
The specified type is array or not?static boolean
isAssignableFrom(java.lang.Class<?> superType, java.lang.Class<?> targetType)
the semantics is same asClass.isAssignableFrom(Class)
static boolean
isConcreteClass(java.lang.Class<?> type)
Is the specified type a concrete class or not?static boolean
isDerived(java.lang.Class<?> targetType, java.lang.Class<?>... superTypes)
the semantics is same asClass.isAssignableFrom(Class)
static boolean
isEnum(int modifiers)
static boolean
isFinal(java.lang.Class<?> type)
static boolean
isGeneralClass(java.lang.Class<?> type)
Is the specified type a general class or not?protected static boolean
isGeneralClass(java.lang.Class<?> type, java.lang.Boolean isAbstract)
Is the specified type a general class or not?static boolean
isGenericClass(java.lang.Class<?> type)
Is generic class or not?static boolean
isPrimitive(java.lang.Class<?> type)
The specified type is primitive type or simple typestatic boolean
isSimpleType(java.lang.Class<?> type)
The specified type is simple type or notstatic boolean
isSynthetic(int modifiers)
static boolean
isTopLevelClass(java.lang.Class<?> type)
static boolean
isWrapperType(java.lang.Class<?> type)
static <T> T
newInstance(java.lang.Class<T> type, java.lang.Object... args)
protected static java.lang.String
resolveClassName(java.io.File classesDirectory, java.io.File classFile)
static java.lang.String
resolveClassName(java.lang.String resourceName)
Resolve resource name to class namestatic java.lang.String
resolvePackageName(java.lang.String className)
Resolve package name under specified class namestatic java.lang.Class<?>
resolvePrimitiveClassName(java.lang.String name)
Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.static java.lang.Class<?>
resolvePrimitiveType(java.lang.Class<?> type)
Resolve the primitive class from the specified typestatic java.lang.Class<?>
resolveWrapperType(java.lang.Class<?> primitiveType)
Resolve the wrapper class from the primitive type
-
-
-
字段详细资料
-
ARRAY_SUFFIX
public static final java.lang.String ARRAY_SUFFIX
Suffix for array class names: "[]"- 另请参阅:
- 常量字段值
-
SIMPLE_TYPES
public static final java.util.Set<java.lang.Class<?>> SIMPLE_TYPES
Simple Types including:Void
Boolean
Character
Byte
Integer
Float
Double
String
BigDecimal
BigInteger
Date
Object
- 另请参阅:
SimpleType
-
PRIMITIVE_TYPES
public static final java.util.Set<java.lang.Class<?>> PRIMITIVE_TYPES
-
-
方法详细资料
-
isArray
public static boolean isArray(java.lang.Class<?> type)
The specified type is array or not?It's an optimized alternative for
Class.isArray()
).- 参数:
type
- the type to test- 返回:
true
if the specified type is an array class,false
otherwise- 另请参阅:
Class.isArray()
-
isConcreteClass
public static boolean isConcreteClass(java.lang.Class<?> type)
Is the specified type a concrete class or not?- 参数:
type
- type to check- 返回:
true
if concrete class,false
otherwise.
-
isAbstractClass
public static boolean isAbstractClass(java.lang.Class<?> type)
Is the specified type a abstract class or not?- 参数:
type
- the type- 返回:
- true if type is a abstract class, false otherwise.
-
isGeneralClass
public static boolean isGeneralClass(java.lang.Class<?> type)
Is the specified type a general class or not?- 参数:
type
- the type- 返回:
- true if type is a general class, false otherwise.
-
isGeneralClass
protected static boolean isGeneralClass(java.lang.Class<?> type, java.lang.Boolean isAbstract)
Is the specified type a general class or not?If
isAbstract
==null
, it will not checktype
is abstract or not.- 参数:
type
- the typeisAbstract
- optional abstract flag- 返回:
- true if type is a general (abstract) class, false otherwise.
-
isTopLevelClass
public static boolean isTopLevelClass(java.lang.Class<?> type)
-
isPrimitive
public static boolean isPrimitive(java.lang.Class<?> type)
The specified type is primitive type or simple typeIt's an optimized implementation for
Class.isPrimitive()
.- 参数:
type
- the type to test- 返回:
- 另请参阅:
Class.isPrimitive()
-
isFinal
public static boolean isFinal(java.lang.Class<?> type)
-
isSimpleType
public static boolean isSimpleType(java.lang.Class<?> type)
The specified type is simple type or not- 参数:
type
- the type to test- 返回:
- if
type
is one element ofSIMPLE_TYPES
, returntrue
, orfalse
- 另请参阅:
SIMPLE_TYPES
-
convertPrimitive
public static java.lang.Object convertPrimitive(java.lang.Class<?> type, java.lang.String value)
-
resolvePrimitiveType
public static java.lang.Class<?> resolvePrimitiveType(java.lang.Class<?> type)
Resolve the primitive class from the specified type- 参数:
type
- the specified type- 返回:
null
if not found
-
resolveWrapperType
public static java.lang.Class<?> resolveWrapperType(java.lang.Class<?> primitiveType)
Resolve the wrapper class from the primitive type- 参数:
primitiveType
- the primitive type- 返回:
null
if not found
-
isWrapperType
public static boolean isWrapperType(java.lang.Class<?> type)
-
arrayTypeEquals
public static boolean arrayTypeEquals(java.lang.Class<?> oneArrayType, java.lang.Class<?> anotherArrayType)
-
resolvePrimitiveClassName
public static java.lang.Class<?> resolvePrimitiveClassName(java.lang.String name)
Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.Also supports the JVM's internal class names for primitive arrays. Does not support the "[]" suffix notation for primitive arrays; this is only supported by
#forName
.- 参数:
name
- the name of the potentially primitive class- 返回:
- the primitive class, or
null
if the name does not denote a primitive class or primitive array class
-
isAnnotation
public static boolean isAnnotation(int modifiers)
- 参数:
modifiers
-Class.getModifiers()
- 返回:
- true if this class's modifiers represents an annotation type; false otherwise
- 另请参阅:
Class.isAnnotation()
-
isEnum
public static boolean isEnum(int modifiers)
- 参数:
modifiers
-Class.getModifiers()
- 返回:
- true if this class's modifiers represents an enumeration type; false otherwise
- 另请参阅:
Class.isEnum()
-
isSynthetic
public static boolean isSynthetic(int modifiers)
- 参数:
modifiers
-Class.getModifiers()
- 返回:
- true if this class's modifiers represents a synthetic type; false otherwise
- 另请参阅:
Class.isSynthetic()
-
resolvePackageName
@Nullable public static java.lang.String resolvePackageName(java.lang.String className)
Resolve package name under specified class name- 参数:
className
- class name- 返回:
- package name
-
findClassNamesInClassPath
@Nonnull public static java.util.Set<java.lang.String> findClassNamesInClassPath(java.lang.String classPath, boolean recursive)
Find all class names in class path- 参数:
classPath
- class pathrecursive
- is recursive on sub directories- 返回:
- all class names in class path
-
findClassNamesInClassPath
public static java.util.Set<java.lang.String> findClassNamesInClassPath(java.io.File archiveFile, boolean recursive)
Find all class names in class path- 参数:
archiveFile
- JarFile or class patch directoryrecursive
- is recursive on sub directories- 返回:
- all class names in class path
-
findClassNamesInArchiveDirectory
protected static java.util.Set<java.lang.String> findClassNamesInArchiveDirectory(java.io.File classesDirectory, boolean recursive)
-
findClassNamesInArchiveFile
protected static java.util.Set<java.lang.String> findClassNamesInArchiveFile(java.io.File jarFile, boolean recursive)
-
findClassNamesInDirectory
protected static java.util.Set<java.lang.String> findClassNamesInDirectory(java.io.File classesDirectory, boolean recursive)
-
findClassNamesInJarFile
protected static java.util.Set<java.lang.String> findClassNamesInJarFile(java.io.File jarFile, boolean recursive)
-
resolveClassName
protected static java.lang.String resolveClassName(java.io.File classesDirectory, java.io.File classFile)
-
resolveClassName
public static java.lang.String resolveClassName(java.lang.String resourceName)
Resolve resource name to class name- 参数:
resourceName
- resource name- 返回:
- class name
-
getAllSuperClasses
public static java.util.Set<java.lang.Class<?>> getAllSuperClasses(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
Get all super classes from the specified type- 参数:
type
- the specified typeclassFilters
- the filters for classes- 返回:
- non-null read-only
Set
-
getAllInterfaces
public static java.util.Set<java.lang.Class<?>> getAllInterfaces(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... interfaceFilters)
Get all interfaces from the specified type- 参数:
type
- the specified typeinterfaceFilters
- the filters for interfaces- 返回:
- non-null read-only
Set
-
getAllInheritedTypes
public static java.util.Set<java.lang.Class<?>> getAllInheritedTypes(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... typeFilters)
Get all inherited types from the specified type- 参数:
type
- the specified typetypeFilters
- the filters for types- 返回:
- non-null read-only
Set
-
isAssignableFrom
public static boolean isAssignableFrom(java.lang.Class<?> superType, java.lang.Class<?> targetType)
the semantics is same asClass.isAssignableFrom(Class)
- 参数:
superType
- the super typetargetType
- the target type- 返回:
- see
Class.isAssignableFrom(Class)
-
isGenericClass
public static boolean isGenericClass(java.lang.Class<?> type)
Is generic class or not?- 参数:
type
- the target type- 返回:
- if the target type is not null or
void
or Void.class, returntrue
, or false
-
getTypes
public static java.lang.Class[] getTypes(java.lang.Object... values)
Resolve the types of the specified values- 参数:
values
- the values- 返回:
- If can't be resolved, return
empty class array
-
getTypeName
public static java.lang.String getTypeName(java.lang.Class<?> type)
Get the name of the specified type- 参数:
type
- the specified type- 返回:
- non-null
-
getSimpleName
public static java.lang.String getSimpleName(java.lang.Class<?> type)
Get the simple name of the specified type- 参数:
type
- the specified type- 返回:
- non-null
-
getAllClasses
public static java.util.Set<java.lang.Class<?>> getAllClasses(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
Get all classes from the specified type with filters- 参数:
type
- the specified typeclassFilters
- class filters- 返回:
- non-null read-only
Set
-
getAllClasses
public static java.util.Set<java.lang.Class<?>> getAllClasses(java.lang.Class<?> type, boolean includedSelf, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
Get all classes(may include self type) from the specified type with filters- 参数:
type
- the specified typeincludedSelf
- included self type or notclassFilters
- class filters- 返回:
- non-null read-only
Set
-
isDerived
public static boolean isDerived(java.lang.Class<?> targetType, java.lang.Class<?>... superTypes)
the semantics is same asClass.isAssignableFrom(Class)
- 参数:
targetType
- the target typesuperTypes
- the super types- 返回:
- see
Class.isAssignableFrom(Class)
- 从以下版本开始:
- 1.0.0
-
newInstance
public static <T> T newInstance(java.lang.Class<T> type, java.lang.Object... args)
-
getTopComponentType
public static java.lang.Class<?> getTopComponentType(java.lang.Object array)
-
getTopComponentType
public static java.lang.Class<?> getTopComponentType(java.lang.Class<?> arrayType)
-
cast
public static <T> T cast(java.lang.Object object, java.lang.Class<T> castType)
Cast the given object to the specified type- 类型参数:
T
- the type to cast- 参数:
object
- the objectcastType
- the type to cast- 返回:
- the casted instance if and only if
object
is an instance ofcastType
,null
otherwise
-
-