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 Class<?> |
forName(@NonNull 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(@NonNull StackTraceElement[] elements)
Gets the calling method name.
|
static Class<?> |
getCglibProxy(@NonNull 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(@NonNull Class<?> clazz)
Gets the classname from the given class.
|
static String |
getClassnameWithSuffix(@NonNull Class<?> clazz)
Gets the classname and concats the suffix ".class" from the class.
|
static String |
getClassnameWithSuffix(@NonNull Object obj)
Gets the classname and concats the suffix ".class" from the object.
|
static ClassType |
getClassType(@NonNull Class<?> clazz)
Gets the
ClassType from the given class. |
static String |
getCurrentMethodName(@NonNull StackTraceElement[] elements)
Gets the current method name.
|
static List<File> |
getDirectoriesFromResources(@NonNull String path,
boolean isPackage)
Gets the directories from the given path.
|
static String |
getJarPath(@NonNull Class<?> clazz)
If the given class is in a JAR file than the jar path as String will be returned.
|
static Class<?>[] |
getJdkProxyInterfaces(@NonNull Class<?> clazz)
Gets the jdk proxy interfaces.
|
static String |
getManifestUrl(@NonNull 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(@NonNull 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(@NonNull Class<?> clazz)
Gets the path from the given class.
|
static String |
getPathFromObject(Object obj)
Finds the absolute path from the object.
|
static URL |
getResource(@NonNull Class<?> clazz)
Gives the url from the path back.
|
static URL |
getResource(@NonNull Class<?> clazz,
@NonNull String path)
Gives the url from the path back.
|
static URL |
getResource(@NonNull String name)
Gives the URL from the resource.
|
static <T> URL |
getResource(@NonNull String name,
T obj)
Gives the URL from the resource.
|
static File |
getResourceAsFile(@NonNull String name)
Gives the resource as a file Object.
|
static File |
getResourceAsFile(@NonNull String name,
@NonNull Object obj)
Gives the resource as a file Object.
|
static InputStream |
getResourceAsStream(@NonNull Class<?> clazz,
@NonNull String uri)
This method call the getResourceAsStream from the ClassLoader.
|
static InputStream |
getResourceAsStream(@NonNull String name)
Gives the Inputstream from the resource.
|
static InputStream |
getResourceAsStream(@NonNull String name,
@NonNull Object obj)
Gives the Inputstream from the resource.
|
static List<URL> |
getResources(@NonNull String path)
Gets a list with urls from the given path for all resources.
|
static String |
getSimpleName(@NonNull 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(@NonNull 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(@NonNull 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(@NonNull 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 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 Class<?> forName(@NonNull @NonNull 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(@NonNull @NonNull StackTraceElement[] elements)
elements - the elementspublic static Class<?> getCglibProxy(@NonNull @NonNull 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(@NonNull @NonNull Class<?> clazz)
clazz - The class.public static String getClassnameWithSuffix(@NonNull @NonNull Class<?> clazz)
clazz - The class.public static String getClassnameWithSuffix(@NonNull @NonNull Object obj)
obj - The object.public static ClassType getClassType(@NonNull @NonNull Class<?> clazz)
ClassType from the given class.clazz - The class.ClassType from the given class.public static String getCurrentMethodName(@NonNull @NonNull StackTraceElement[] elements)
elements - the elementspublic static List<File> getDirectoriesFromResources(@NonNull @NonNull 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(@NonNull @NonNull Class<?> clazz)
clazz - The class.public static Class<?>[] getJdkProxyInterfaces(@NonNull @NonNull Class<?> clazz)
clazz - the classpublic static String getManifestUrl(@NonNull @NonNull Class<?> clazz)
clazz - The class.public static String getName(@NonNull @NonNull 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(@NonNull @NonNull Class<?> clazz)
Objectclazz - The class.public static String getPathFromObject(Object obj)
obj - The object.public static URL getResource(@NonNull @NonNull Class<?> clazz)
clazz - The class-object.public static URL getResource(@NonNull @NonNull Class<?> clazz, @NonNull @NonNull String path)
clazz - The class-object.path - The path.public static URL getResource(@NonNull @NonNull String name)
name - The name from the resource.public static <T> URL getResource(@NonNull @NonNull String name, @NonNull T obj)
T - the generic typename - The name from the resource.obj - The Object.public static File getResourceAsFile(@NonNull @NonNull String name) throws URISyntaxException
name - The name from the file.URISyntaxException - occurs by creation of the file with an uri.public static File getResourceAsFile(@NonNull @NonNull String name, @NonNull @NonNull Object obj) throws URISyntaxException, IOException
name - The name from the file.obj - The Object.URISyntaxException - occurs by creation of the file with an uri.IOException - Signals that an I/O exception has occurred.public static InputStream getResourceAsStream(@NonNull @NonNull Class<?> clazz, @NonNull @NonNull String uri)
clazz - the clazzuri - The uri as String.public static InputStream getResourceAsStream(@NonNull @NonNull String name)
name - The name from the resource.public static InputStream getResourceAsStream(@NonNull @NonNull String name, @NonNull @NonNull Object obj)
name - The name from the resource.obj - The Object.public static List<URL> getResources(@NonNull @NonNull String path) throws IOException
path - The base path.IOException - Signals that an I/O exception has occurred.public static String getSimpleName(@NonNull @NonNull Class<?> clazz)
clazz - The class.public static Class<?> getUnwrappedProxy(Class<?> clazz)
clazz - the classClass is null.public static URL getURL(@NonNull @NonNull 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(@NonNull
@NonNull 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(@NonNull
@NonNull 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.Copyright © 2015–2019 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.