Last update: 2011-06-23

org.proteios.util
Class ClassUtil

java.lang.Object
  extended by org.proteios.util.ClassUtil

public class ClassUtil
extends Object

Utility class for Class objects.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Constructor Summary
ClassUtil()
           
 
Method Summary
static
<I> Constructor<I>
findConstructor(Class<I> clazz, Object[] parameters)
          Find a constructor for the specified class which takes parameters of the specified types taking superclasses and interfaces into account.
static Set<Class> getInterfaces(Class clazz)
          Get all interfaces a class implements, including those implemented by superclasses.
static boolean isAssignable(Class<?>[] classes, Object[] values)
          Check if one array of class objects is assignment compatible with values in another array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtil

public ClassUtil()
Method Detail

findConstructor

public static <I> Constructor<I> findConstructor(Class<I> clazz,
                                                 Object[] parameters)
Find a constructor for the specified class which takes parameters of the specified types taking superclasses and interfaces into account. This method finds the first declared constructor which can accept parameters of the specified type.

Parameters:
clazz - The class to find a constructor for
parameters - The parameters that are going to be sent to the constructor's Constructor.newInstance(Object[]) method
Returns:
A constructor object or null if no constructor was found

isAssignable

public static boolean isAssignable(Class<?>[] classes,
                                   Object[] values)
Check if one array of class objects is assignment compatible with values in another array. Ie. the Class.isAssignableFrom(Class) method returns true for each element in the classes array with respect to the class of the corresponding value in the values array. Null elements in the values array are ignored.

Parameters:
classes - The class objects representing the parameters we want to assign values to
values - The parameter values to assign
Returns:
TRUE if all parameters are assignable

getInterfaces

public static Set<Class> getInterfaces(Class clazz)
Get all interfaces a class implements, including those implemented by superclasses.

Parameters:
clazz - The Class to check
Returns:
A Set containing the Class objects for the interfaces

Last update: 2011-06-23