public final class ClassExtensions extends Object
ClassExtensions provides extension methods for the class Class.| Modifier and Type | Field and Description |
|---|---|
protected static String |
CGLIB_TAG
The Constant CGLIB_TAG contains the tag of a cglib class name.
|
| Constructor and Description |
|---|
ClassExtensions() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
equalsByClassName(Class<?> oneClass,
Class<?> otherClass)
Equal the given class objects by they qualified class names.
|
static Class<?> |
forName(String className)
Look up the class in the "current" ClassLoader.
|
static Class<?> |
getBaseClass(Class<?> childClass)
Gets the parent base class from the given child class.
|
static String |
getCallingMethodName(StackTraceElement[] elements)
Gets the calling method name.
|
static Class<?> |
getCglibProxy(Class<?> clazz)
Gets the real class if the given class is decorated with cglib proxy classes.
|
static <T> Class<T> |
getClass(T object)
Gets the
Class of the given object. |
static ClassLoader |
getClassLoader()
Gets the current class loader.
|
static ClassLoader |
getClassLoader(Object obj)
Gets the ClassLoader from the given object.
|
static String |
getClassname(Class<?> clazz)
Gets the classname from the given class.
|
static String |
getClassnameWithSuffix(Class<?> clazz)
Gets the classname and concats the suffix ".class" from the class.
|
static String |
getClassnameWithSuffix(Object obj)
Gets the classname and concats the suffix ".class" from the object.
|
static de.alpharogroup.lang.ClassType |
getClassType(Class<?> clazz)
Gets the
ClassType from the given class. |
static String |
getCurrentMethodName(StackTraceElement[] elements)
Gets the current method name.
|
static List<File> |
getDirectoriesFromResources(String path,
boolean isPackage)
Gets the directories from the given path.
|
static String |
getJarPath(Class<?> clazz)
If the given class is in a JAR file than the jar path as String will be returned.
|
static Class<?>[] |
getJdkProxyInterfaces(Class<?> clazz)
Gets the jdk proxy interfaces.
|
static String |
getManifestUrl(Class<?> clazz)
If the given class is in a JAR, WAR or EAR file than the manifest url as String is returned.
|
static String |
getName(Class<?> clazz)
Returns the name of the given class or null if the given class is null.
|
static String |
getName(Class<?> clazz,
boolean simple)
Returns the name of the given class or null if the given class is null.
|
static String |
getPath(Class<?> clazz)
Gets the path from the given class.
|
static String |
getPathFromObject(Object obj)
Finds the absolute path from the object.
|
static URL |
getResource(Class<?> clazz)
Gives the url from the path back.
|
static URL |
getResource(Class<?> clazz,
String path)
Gives the url from the path back.
|
static URL |
getResource(String name)
Gives the URL from the resource.
|
static <T> URL |
getResource(String name,
T obj)
Gives the URL from the resource.
|
static File |
getResourceAsFile(String name)
Gives the resource as a file Object.
|
static File |
getResourceAsFile(String name,
Object obj)
Gives the resource as a file Object.
|
static InputStream |
getResourceAsStream(Class<?> clazz,
String uri)
This method call the getResourceAsStream from the ClassLoader.
|
static InputStream |
getResourceAsStream(String name)
Gives the Inputstream from the resource.
|
static InputStream |
getResourceAsStream(String name,
Object obj)
Gives the Inputstream from the resource.
|
static List<URL> |
getResources(String path)
Gets a list with urls from the given path for all resources.
|
static String |
getSimpleName(Class<?> clazz)
Returns the simple name of the given class or null if the given class is null.
|
static Class<?> |
getUnwrappedProxy(Class<?> clazz)
Gets the unwrapped proxy class.
|
static URL |
getURL(Class<?> clazz)
Returns the URL from the given class.
|
static <T> boolean |
isCglib(Class<T> clazz)
Checks if the given
Class is cglib proxy class. |
static boolean |
isCollection(Class<?> clazz)
Checks if the given class is assignable from
Collection. |
static boolean |
isDerivate(ClassLoader source,
ClassLoader compare)
Compares the two given ClassLoader objects and returns true if compare is a derivate of
source.
|
static <T> boolean |
isJdkProxy(Class<T> clazz)
Checks if the given
Class is a JDK proxy class. |
static boolean |
isMap(Class<?> clazz)
Checks if the given class is assignable from
Map. |
static <T> boolean |
isProxy(Class<T> clazz)
Checks if the given
Class is a proxy class. |
static String |
normalizeQualifiedClassName(String qualifiedClassname)
Normalizes the given full qualified class name.
|
static String |
normalizeSimpleClassName(String className)
Normalizes the given simple class name.
|
static Set<Class<?>> |
scanClassesFromPackage(File directory,
String packagePath)
Scan for classes in the given directory.
|
static Set<Class<?>> |
scanClassesFromPackage(File directory,
String packagePath,
boolean recursive)
Scan recursive for classes in the given directory.
|
static Set<Class<?>> |
scanClassNames(String packageName)
Scan class names from the given package name.
|
static Set<Class<?>> |
scanClassNames(String packageName,
boolean recursive)
Scan class names from the given package name.
|
static Class<?>[] |
unwrapProxy(Class<?> clazz)
Unwrap the given
Class if it is wrapped from cglib or jdk proxies. |
protected static final String CGLIB_TAG
public static boolean equalsByClassName(Class<?> oneClass, Class<?> otherClass)
oneClass - one class for equation by the qualified class name.otherClass - the other class for equation by the qualified class name.public static Class<?> forName(String className) throws ClassNotFoundException
className - The class name to loadClassNotFoundException - is thrown if the Class was not found or could not be located.public static Class<?> getBaseClass(Class<?> childClass)
childClass - the child classpublic static String getCallingMethodName(StackTraceElement[] elements)
elements - the elementspublic static Class<?> getCglibProxy(Class<?> clazz)
clazz - the classpublic static <T> Class<T> getClass(T object)
Class of the given object.T - the generic typeobject - the object to resolve the classClass of the given object or null if the object is null.public static ClassLoader getClassLoader()
public static ClassLoader getClassLoader(Object obj)
obj - The object.public static String getClassname(Class<?> clazz)
clazz - The class.public static String getClassnameWithSuffix(Class<?> clazz)
clazz - The class.public static String getClassnameWithSuffix(Object obj)
obj - The object.public static de.alpharogroup.lang.ClassType getClassType(Class<?> clazz)
ClassType from the given class.clazz - The class.ClassType from the given class.public static String getCurrentMethodName(StackTraceElement[] elements)
elements - the elementspublic static List<File> getDirectoriesFromResources(String path, boolean isPackage) throws IOException, URISyntaxException
path - the pathisPackage - If the Flag is true than the given path is a package.IOException - Signals that an I/O exception has occurred.URISyntaxException - is thrown if a string could not be parsed as a URI reference.public static String getJarPath(Class<?> clazz)
clazz - The class.public static Class<?>[] getJdkProxyInterfaces(Class<?> clazz)
clazz - the classpublic static String getManifestUrl(Class<?> clazz)
clazz - The class.public static String getName(Class<?> clazz)
clazz - The class.public static String getName(Class<?> clazz, boolean simple)
clazz - The classsimple - The flag if the simple name should be returned.public static String getPath(Class<?> clazz)
Objectclazz - The class.public static String getPathFromObject(Object obj)
obj - The object.public static URL getResource(Class<?> clazz)
clazz - The class-object.public static URL getResource(Class<?> clazz, String path)
clazz - The class-object.path - The path.public static URL getResource(String name)
name - The name from the resource.public static <T> URL getResource(String name, T obj)
T - the generic typename - The name from the resource.obj - The Object.public static File getResourceAsFile(String name) throws URISyntaxException
name - The name from the file.URISyntaxException - occurs by creation of the file with an uri.public static File getResourceAsFile(String name, Object obj) throws URISyntaxException
name - The name from the file.obj - The Object.URISyntaxException - occurs by creation of the file with an uri.public static InputStream getResourceAsStream(Class<?> clazz, String uri)
clazz - the clazzuri - The uri as String.public static InputStream getResourceAsStream(String name)
name - The name from the resource.public static InputStream getResourceAsStream(String name, Object obj)
name - The name from the resource.obj - The Object.public static List<URL> getResources(String path) throws IOException
path - The base path.IOException - Signals that an I/O exception has occurred.public static String getSimpleName(Class<?> clazz)
clazz - The class.public static Class<?> getUnwrappedProxy(Class<?> clazz)
clazz - the classClass is null.public static URL getURL(Class<?> clazz)
clazz - The class.public static <T> boolean isCglib(Class<T> clazz)
Class is cglib proxy class.T - the generic typeclazz - the class to checkClass is cglib proxy class otherwise false.public static boolean isCollection(Class<?> clazz)
Collection.clazz - The class.Collection otherwise false.public static boolean isDerivate(ClassLoader source, ClassLoader compare)
source - the sourcecompare - the comparepublic static <T> boolean isJdkProxy(Class<T> clazz)
Class is a JDK proxy class.T - the generic typeclazz - the class to checkClass is a JDK proxy class otherwise false.public static boolean isMap(Class<?> clazz)
Map.clazz - The class.Map otherwise false.public static <T> boolean isProxy(Class<T> clazz)
Class is a proxy class.T - the generic typeclazz - the class to checkClass is a proxy class otherwise false.public static String normalizeQualifiedClassName(String qualifiedClassname)
qualifiedClassname - the full qualified class name to normalize.public static String normalizeSimpleClassName(String className)
className - the class name to normalize.public static Set<Class<?>> scanClassesFromPackage(File directory, String packagePath) throws ClassNotFoundException
directory - the directorypackagePath - the package pathClassNotFoundException - occurs if a given class cannot be located by the specified class loaderpublic static Set<Class<?>> scanClassesFromPackage(File directory, String packagePath, boolean recursive) throws ClassNotFoundException
directory - the directorypackagePath - the package pathrecursive - the recursiveClassNotFoundException - is thrown if a class in the given path cannot be located.public static Set<Class<?>> scanClassNames(String packageName) throws IOException, ClassNotFoundException
packageName - the package nameIOException - Signals that an I/O exception has occurred.ClassNotFoundException - is thrown if a class in the given path cannot be located.public static Set<Class<?>> scanClassNames(String packageName, boolean recursive) throws IOException, ClassNotFoundException
packageName - the package namerecursive - the recursive flagIOException - Signals that an I/O exception has occurred.ClassNotFoundException - is thrown if a class in the given path cannot be located.Copyright © 2015–2018 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.