public final class ObjectUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CLASS_CONTEXT
A constant for using the ClassContext as source for the classloader.
|
static String |
THREAD_CONTEXT
A constant for using the TheadContext as source for the classloader.
|
Modifier and Type | Method and Description |
---|---|
static Object |
clone(Object object)
Returns a clone of the specified object, if it can be cloned, otherwise throws a CloneNotSupportedException.
|
static int |
compareVersionArrays(Integer[] a1,
Integer[] a2)
Compares version numbers.
|
static boolean |
equal(Object o1,
Object o2)
Returns
true if the two objects are equal OR both null . |
static boolean |
equalArray(Object[] array1,
Object[] array2)
Compares two arrays and determines if they are equal.
|
static boolean |
equals(File file1,
File file2)
Performs a comparison on two file objects to determine if they refer to the
same file.
|
static ClassLoader |
getClassLoader()
Returns the custom classloader or null, if no custom classloader is defined.
|
static ClassLoader |
getClassLoader(Class c)
Returns the classloader, which was responsible for loading the given class.
|
static String |
getClassLoaderSource()
Returns the internal configuration entry, whether the classloader of the thread context or the context classloader
should be used.
|
static URL |
getResource(String name,
Class c)
Returns the resource specified by the absolute name.
|
static InputStream |
getResourceAsStream(String name,
Class context)
Returns the inputstream for the resource specified by the absolute name.
|
static URL |
getResourceRelative(String name,
Class c)
Returns the resource specified by the relative name.
|
static InputStream |
getResourceRelativeAsStream(String name,
Class context)
Returns the inputstream for the resource specified by the relative name.
|
static int |
hashCode(Object[] array1) |
static boolean |
isJDK14()
Checks whether the current JDK is at least JDK 1.4.
|
static Object |
loadAndInstantiate(String className,
Class source)
Deprecated.
This class is not typesafe and instantiates the specified object without any additional checks.
|
static <T> T |
loadAndInstantiate(String className,
Class source,
Class<T> type)
Tries to create a new instance of the given class.
|
static Integer[] |
parseVersions(String version)
Parses a version string into numbers.
|
static void |
setClassLoader(ClassLoader classLoader)
Redefines the custom classloader.
|
static void |
setClassLoaderSource(String classLoaderSource)
Defines the internal configuration entry, whether the classloader of the thread context or the context classloader
should be used.
|
public static final String THREAD_CONTEXT
public static final String CLASS_CONTEXT
public static String getClassLoaderSource()
public static void setClassLoaderSource(String classLoaderSource)
classLoaderSource
- the classloader source, either THREAD_CONTEXT or CLASS_CONTEXT.public static boolean equal(Object o1, Object o2)
true
if the two objects are equal OR both null
.o1
- object 1 (null
permitted).o2
- object 2 (null
permitted).true
or false
.public static boolean equals(File file1, File file2)
File.equals()
method requires that the files refer
to the same file in the same way (relative vs. absolute).file1
- the first file (null
permitted).file2
- the second file (null
permitted).true
if the files refer to the same file, false
otherwisepublic static Object clone(Object object) throws CloneNotSupportedException
object
- the object to clone (null
not permitted).CloneNotSupportedException
- if the object cannot be cloned.public static void setClassLoader(ClassLoader classLoader)
classLoader
- the new classloader or null to use the default.public static ClassLoader getClassLoader()
public static ClassLoader getClassLoader(Class c)
c
- the classloader, either an application class loader or the boot loader.SecurityException
- if the SecurityManager does not allow to grab the context classloader.public static URL getResource(String name, Class c)
name
- the name of the resourcec
- the source classpublic static URL getResourceRelative(String name, Class c)
name
- the name of the resource relative to the given classc
- the source classpublic static InputStream getResourceAsStream(String name, Class context)
name
- the name of the resourcecontext
- the source classpublic static InputStream getResourceRelativeAsStream(String name, Class context)
name
- the name of the resource relative to the given classcontext
- the source classpublic static Object loadAndInstantiate(String className, Class source)
className
- the class name as String, never null.source
- the source class, from where to get the classloader.public static <T> T loadAndInstantiate(String className, Class source, Class<T> type)
className
- the class name as String, never null.source
- the source class, from where to get the classloader.type
- the expected type of the object that is being instantiated.public static boolean isJDK14()
public static int compareVersionArrays(Integer[] a1, Integer[] a2)
a1
- the first array.a2
- the second array.public static Integer[] parseVersions(String version)
version
- the version.public static boolean equalArray(Object[] array1, Object[] array2)
null
null
references for any of the arrays.array1
- the first array to compare.array2
- the second array to compare.public static int hashCode(Object[] array1)