Package org.jfree.util
Class ObjectUtilities
java.lang.Object
org.jfree.util.ObjectUtilities
A collection of useful static utility methods for handling classes and object
instantiation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
A constant for using the ClassContext as source for the classloader.private static ClassLoader
The custom classloader to be used (if not null).private static String
By default use the thread context.static final String
A constant for using the TheadContext as source for the classloader. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Returns a clone of the specified object, if it can be cloned, otherwise throws a CloneNotSupportedException.private static String
convertName
(String name, Class c) Transform the class-relative resource name into a global name by appending it to the classes package name.static Collection
deepClone
(Collection collection) Returns a new collection containing clones of all the items in the specified collection.static boolean
Returnstrue
if the two objects are equal OR bothnull
.static ClassLoader
Returns the custom classloader or null, if no custom classloader is defined.static ClassLoader
Returns the classloader, which was responsible for loading the given class.static String
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
Returns a hash code for an object, or zero if the object isnull
.static boolean
isJDK14()
Returnstrue
if this is version 1.4 or later of the Java runtime.static Object
loadAndInstantiate
(String className, Class source) Tries to create a new instance of the given class.static Object
loadAndInstantiate
(String className, Class source, Class type) Tries to create a new instance of the given class.private static String[]
parseVersions
(String version) 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.
-
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:
-
classLoaderSource
By default use the thread context. -
classLoader
The custom classloader to be used (if not null).
-
-
Constructor Details
-
ObjectUtilities
private ObjectUtilities()Default constructor - private.
-
-
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
Returnstrue
if the two objects are equal OR bothnull
.- Parameters:
o1
- object 1 (null
permitted).o2
- object 2 (null
permitted).- Returns:
true
orfalse
.
-
hashCode
Returns a hash code for an object, or zero if the object isnull
.- Parameters:
object
- the object (null
permitted).- Returns:
- The object's hash code (or zero if the object is
null
).
-
clone
Returns a clone of the specified object, if it can be cloned, otherwise throws a CloneNotSupportedException.- Parameters:
object
- the object to clone (null
not permitted).- Returns:
- A clone of the specified object.
- Throws:
CloneNotSupportedException
- if the object cannot be cloned.
-
deepClone
Returns a new collection containing clones of all the items in the specified collection.- Parameters:
collection
- the collection (null
not permitted).- Returns:
- A new collection containing clones of all the items in the specified collection.
- Throws:
CloneNotSupportedException
- if any of the items in the collection 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.
-
convertName
Transform the class-relative resource name into a global name by appending it to the classes package name. If the name is already a global name (the name starts with a "/"), then the name is returned unchanged.- Parameters:
name
- the resource namec
- the class which the resource is relative to- Returns:
- the tranformed name.
-
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
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 type.- Returns:
- the instantiated object or null, if an error occurred.
-
isJDK14
public static boolean isJDK14()Returnstrue
if this is version 1.4 or later of the Java runtime.- Returns:
- A boolean.
-
parseVersions
-