public class ClassUtil extends Object
Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsAssignableClass(Class<?> toFind,
Class<?>... classes)
Checks if the class in the first parameter is assignable
to one of the classes in the second or any later parameter.
|
static List<Class> |
findAnnotatedWith(Class<? extends Annotation> type) |
static List<Class> |
findAnnotatedWith(Class<? extends Annotation> type,
String[] igrnoreList,
String[] includeList) |
static List<Class> |
findInstancesOf(Class type) |
static List<Class> |
findInstancesOf(Class type,
String[] igrnoreList,
String[] includeList) |
static Class |
forName(String className,
Class caller)
Load the specified class.
|
static List<Field> |
getAnnotatedFields(Class runtimeClass,
Class<? extends Annotation> annotationClass) |
static <T> List<Class<T>> |
getClasses(String fileName,
Class<T> instanceOf)
Will try to create a List of classes that are listed
in the passed in file.
|
static <U> Object |
getField(Field field,
U instance) |
static Method |
getGetterMethod(String getterName,
Object bean,
Class<?> returnType) |
static Method |
getGetterMethodByProperty(String propertyName,
Class<?> beanClass,
Class<?> returnType) |
static InputStream |
getResourceAsStream(String resourceName,
Class caller)
Get the specified resource as a stream.
|
static InputStream |
getResourceAsStream(String resourceName,
ClassLoader classLoader)
Get the specified resource as a stream.
|
static List<URL> |
getResources(String resourcePath,
Class<?> caller) |
static List<URL> |
getResources(String resourcePath,
ClassLoader callerClassLoader) |
static Method |
getSetterMethod(String setterName,
Class beanclass,
Class<?> setterParamType) |
static Method |
getSetterMethod(String setterName,
Object bean,
Class<?> setterParamType) |
static int |
indexOfFirstAssignableClass(Class<?> toFind,
Class<?>... classes)
Gets the array index of the first class within an array of classes to
which a specified class is assignable.
|
static Object |
newProxyInstance(Class[] classes,
InvocationHandler handler) |
static <U> void |
setField(Field field,
U instance,
Object value) |
static String |
toFilePath(Package aPackage) |
static String |
toGetterName(String property) |
static String |
toIsGetterName(String property) |
static String |
toSetterName(String property) |
public static Class forName(String className, Class caller) throws ClassNotFoundException
className
- The name of the class to load.caller
- The class of the caller.ClassNotFoundException
- If the class cannot be found.public static InputStream getResourceAsStream(String resourceName, Class caller)
resourceName
- The name of the class to load.caller
- The class of the caller.public static InputStream getResourceAsStream(String resourceName, ClassLoader classLoader)
resourceName
- The name of the class to load.classLoader
- The ClassLoader to use, if the resource is not located via the
Thread context ClassLoader.public static List<URL> getResources(String resourcePath, Class<?> caller) throws IOException
IOException
public static List<URL> getResources(String resourcePath, ClassLoader callerClassLoader) throws IOException
IOException
public static List<Class> findInstancesOf(Class type, String[] igrnoreList, String[] includeList)
public static List<Class> findAnnotatedWith(Class<? extends Annotation> type, String[] igrnoreList, String[] includeList)
public static List<Class> findAnnotatedWith(Class<? extends Annotation> type)
public static Object newProxyInstance(Class[] classes, InvocationHandler handler)
public static <T> List<Class<T>> getClasses(String fileName, Class<T> instanceOf)
fileName
- The name of the file containing the list of classes,
one class name per line.instanceOf
- The instanceof filter.public static boolean containsAssignableClass(Class<?> toFind, Class<?>... classes)
toFind
- The class to check for assignment compatibility.classes
- The classes against which toFind
should be checked.toFind
is assignable to any one of the
specified classes.public static <U> void setField(Field field, U instance, Object value) throws IllegalAccessException
IllegalAccessException
public static <U> Object getField(Field field, U instance) throws IllegalAccessException
IllegalAccessException
public static List<Field> getAnnotatedFields(Class runtimeClass, Class<? extends Annotation> annotationClass)
public static int indexOfFirstAssignableClass(Class<?> toFind, Class<?>... classes)
toFind
- The class to check for assignment compatibility.classes
- The classes against which toFind
should be checked.classes
to which
toFind
is assignable, if it can be assigned to one of the specified
classes, -1
otherwise.public static Method getSetterMethod(String setterName, Object bean, Class<?> setterParamType)
public static Method getSetterMethod(String setterName, Class beanclass, Class<?> setterParamType)
public static Method getGetterMethod(String getterName, Object bean, Class<?> returnType)
Copyright © 2020. All rights reserved.