Class ObjectUtilities
java.lang.Object
org.pentaho.reporting.libraries.base.util.ObjectUtilities
A collection of useful static utility methods for handling classes and object instantiation.
- Author:
- Thomas Morgner
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectReturns a clone of the specified object, if it can be cloned, otherwise throws a CloneNotSupportedException.static intcompareVersionArrays(Integer[] a1, Integer[] a2) Compares version numbers.static booleanReturnstrueif the two objects are equal OR bothnull.static booleanequalArray(Object[] array1, Object[] array2) Compares two arrays and determines if they are equal.static booleanPerforms a comparison on two file objects to determine if they refer to the same file.static ClassLoaderReturns the custom classloader or null, if no custom classloader is defined.static ClassLoaderReturns the classloader, which was responsible for loading the given class.static StringReturns the internal configuration entry, whether the classloader of the thread context or the context classloader should be used.static URLgetResource(String name, Class c) Returns the resource specified by the absolute name.static InputStreamgetResourceAsStream(String name, Class context) Returns the inputstream for the resource specified by the absolute name.static URLgetResourceRelative(String name, Class c) Returns the resource specified by the relative name.static InputStreamgetResourceRelativeAsStream(String name, Class context) Returns the inputstream for the resource specified by the relative name.static intstatic <T> TinstantiateSafe(Class clazz, Class<T> type) static booleanisJDK14()Checks whether the current JDK is at least JDK 1.4.static ObjectloadAndInstantiate(String className, Class source) Deprecated.This class is not typesafe and instantiates the specified object without any additional checks.static <T> TloadAndInstantiate(String className, Class source, Class<T> type) Tries to create a new instance of the given class.static <T> Class<? extends T>loadAndValidate(String className, Class source, Class<T> type) static Integer[]parseVersions(String version) Parses a version string into numbers.static voidsetClassLoader(ClassLoader classLoader) Redefines the custom classloader.static voidsetClassLoaderSource(String classLoaderSource) Defines the internal configuration entry, whether the classloader of the thread context or the context classloader should be used.
-
Field Details
-
THREAD_CONTEXT
A constant for using the TheadContext as source for the classloader.- See Also:
-
CLASS_CONTEXT
A constant for using the ClassContext as source for the classloader.- See Also:
-
-
Method Details
-
getClassLoaderSource
Returns the internal configuration entry, whether the classloader of the thread context or the context classloader should be used.- Returns:
- the classloader source, either THREAD_CONTEXT or CLASS_CONTEXT.
-
setClassLoaderSource
Defines the internal configuration entry, whether the classloader of the thread context or the context classloader should be used. This setting can only be defined using the API, there is no safe way to put this into an external configuration file.- Parameters:
classLoaderSource- the classloader source, either THREAD_CONTEXT or CLASS_CONTEXT.
-
equal
Returnstrueif the two objects are equal OR bothnull.- Parameters:
o1- object 1 (nullpermitted).o2- object 2 (nullpermitted).- Returns:
trueorfalse.
-
equals
Performs a comparison on two file objects to determine if they refer to the same file. TheFile.equals()method requires that the files refer to the same file in the same way (relative vs. absolute).- Parameters:
file1- the first file (nullpermitted).file2- the second file (nullpermitted).- Returns:
trueif the files refer to the same file,falseotherwise
-
clone
Returns a clone of the specified object, if it can be cloned, otherwise throws a CloneNotSupportedException.- Parameters:
object- the object to clone (nullnot permitted).- Returns:
- A clone of the specified object.
- Throws:
CloneNotSupportedException- if the object cannot be cloned.
-
setClassLoader
Redefines the custom classloader.- Parameters:
classLoader- the new classloader or null to use the default.
-
getClassLoader
Returns the custom classloader or null, if no custom classloader is defined.- Returns:
- the custom classloader or null to use the default.
-
getClassLoader
Returns the classloader, which was responsible for loading the given class.- Parameters:
c- the classloader, either an application class loader or the boot loader.- Returns:
- the classloader, never null.
- Throws:
SecurityException- if the SecurityManager does not allow to grab the context classloader.
-
getResource
Returns the resource specified by the absolute name.- Parameters:
name- the name of the resourcec- the source class- Returns:
- the url of the resource or null, if not found.
-
getResourceRelative
Returns the resource specified by the relative name.- Parameters:
name- the name of the resource relative to the given classc- the source class- Returns:
- the url of the resource or null, if not found.
-
getResourceAsStream
Returns the inputstream for the resource specified by the absolute name.- Parameters:
name- the name of the resourcecontext- the source class- Returns:
- the url of the resource or null, if not found.
-
getResourceRelativeAsStream
Returns the inputstream for the resource specified by the relative name.- Parameters:
name- the name of the resource relative to the given classcontext- the source class- Returns:
- the url of the resource or null, if not found.
-
loadAndInstantiate
Deprecated.This class is not typesafe and instantiates the specified object without any additional checks.Tries to create a new instance of the given class. This is a short cut for the common bean instantiation code.- Parameters:
className- the class name as String, never null.source- the source class, from where to get the classloader.- Returns:
- the instantiated object or null, if an error occured.
-
loadAndInstantiate
Tries to create a new instance of the given class. This is a short cut for the common bean instantiation code. This method is a type-safe method and will not instantiate the class unless it is an instance of the given type.- Parameters:
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.- Returns:
- the instantiated object, which is guaranteed to be of the given type, or null, if an error occured.
-
instantiateSafe
-
loadAndValidate
-
isJDK14
public static boolean isJDK14()Checks whether the current JDK is at least JDK 1.4.- Returns:
- true, if the JDK has been recognized as JDK 1.4, false otherwise.
-
compareVersionArrays
Compares version numbers.- Parameters:
a1- the first array.a2- the second array.- Returns:
- -1 if a1 is less than a2, 0 if a1 and a2 are equal, and +1 otherwise.
-
parseVersions
Parses a version string into numbers.- Parameters:
version- the version.- Returns:
- the parsed version array.
-
equalArray
Compares two arrays and determines if they are equal. This method allows to passnullnull references for any of the arrays.- Parameters:
array1- the first array to compare.array2- the second array to compare.- Returns:
- true, if both arrays are equal or both arrays are null, false otherwise.
-
hashCode
-