us.ihmc.utilities.reflect
Class ReflectionTools

java.lang.Object
  extended by us.ihmc.utilities.reflect.ReflectionTools

public final class ReflectionTools
extends java.lang.Object


Method Summary
static
<T> java.util.ArrayList<java.lang.reflect.Field>
compareAllPrimitives(T instance1, T instance2)
          Compares all primitives of two instances of a class
static
<T> java.util.ArrayList<java.lang.reflect.Field>
compareDeclaredPrimitives(java.lang.Class<? extends T> cls, T instance1, T instance2)
          Compares the declared primitives of two instances of a class
static java.util.ArrayList<java.lang.reflect.Field> getAllFields(java.lang.Class<?> cls)
           
static
<T> java.util.List<T>
getFieldContentsAssignableFromClass(java.lang.Object object, java.lang.Class<T> clazz)
           
static java.lang.String getStringRepresentationOfArrayEntry(java.lang.Object array, int index)
           
static java.lang.String getStringRepresentationOfFieldContent(java.lang.Object object, java.lang.reflect.Field field)
           
static
<T> boolean
isPrimitiveArrayEntryTheSame(T instance1, T instance2, int index)
          Compares the values of a field for two instances of a class.
static
<T> boolean
isPrimitiveFieldContentTheSame(T instance1, T instance2, java.lang.reflect.Field field)
          Compares the values of a field for two instances of a class.
static void printAllFieldContents(java.lang.Object instance)
          Prints the contents of all fields of the instance
static
<T> void
printDeclaredFieldContents(java.lang.Class<? extends T> cls, T instance)
          Prints the contents of the declared fields of the instance.
static void printDeclaredFields(java.lang.Class<?> cls)
          Prints the declared fields of the class.
static void printFieldContents(java.lang.Object instance, java.lang.reflect.Field field)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

printDeclaredFields

public static void printDeclaredFields(java.lang.Class<?> cls)
Prints the declared fields of the class. This includes public, protected, default (package) access, and private fields, but excludes inherited fields.

Parameters:
cls - class to print the fields for

printDeclaredFieldContents

public static <T> void printDeclaredFieldContents(java.lang.Class<? extends T> cls,
                                                  T instance)
                                       throws java.lang.IllegalArgumentException,
                                              java.lang.IllegalAccessException
Prints the contents of the declared fields of the instance. This includes public, protected, default (package) access, and private fields, but excludes inherited fields.

Type Parameters:
T - type of the instance
Parameters:
cls - type to print the declared fields for
instance - instance to print the declared field contents for
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

printAllFieldContents

public static void printAllFieldContents(java.lang.Object instance)
                                  throws java.lang.IllegalArgumentException,
                                         java.lang.IllegalAccessException
Prints the contents of all fields of the instance

Parameters:
instance - instance instance to print the field contents for
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

compareDeclaredPrimitives

public static <T> java.util.ArrayList<java.lang.reflect.Field> compareDeclaredPrimitives(java.lang.Class<? extends T> cls,
                                                                                         T instance1,
                                                                                         T instance2)
                                                                              throws java.lang.IllegalArgumentException,
                                                                                     java.lang.IllegalAccessException
Compares the declared primitives of two instances of a class

Type Parameters:
T - type of the instances
Parameters:
cls - type to compare the declared fields for
instance1 - first instance to test
instance2 - second instance to test
Returns:
a list of differing primitives
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

compareAllPrimitives

public static <T> java.util.ArrayList<java.lang.reflect.Field> compareAllPrimitives(T instance1,
                                                                                    T instance2)
                                                                         throws java.lang.IllegalArgumentException,
                                                                                java.lang.IllegalAccessException
Compares all primitives of two instances of a class

Type Parameters:
T - type of the instances
Parameters:
instance1 - first instance to test
instance2 - second instance to test
Returns:
a list of differing primitives
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

isPrimitiveFieldContentTheSame

public static <T> boolean isPrimitiveFieldContentTheSame(T instance1,
                                                         T instance2,
                                                         java.lang.reflect.Field field)
                                              throws java.lang.IllegalArgumentException,
                                                     java.lang.IllegalAccessException
Compares the values of a field for two instances of a class.

Type Parameters:
T - type of the instances. Type must contain the specified field.
Parameters:
instance1 - first instance to test
instance2 - second instance to test
field - field to test
Returns:
true iff the primitive fields are equal
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

isPrimitiveArrayEntryTheSame

public static <T> boolean isPrimitiveArrayEntryTheSame(T instance1,
                                                       T instance2,
                                                       int index)
Compares the values of a field for two instances of a class.

Type Parameters:
T - type of the instances. Type must contain the specified field.
Parameters:
instance1 - first instance to test
instance2 - second instance to test
field - field to test
Returns:
true iff the primitive fields are equal

getStringRepresentationOfFieldContent

public static java.lang.String getStringRepresentationOfFieldContent(java.lang.Object object,
                                                                     java.lang.reflect.Field field)
                                                              throws java.lang.IllegalArgumentException,
                                                                     java.lang.IllegalAccessException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException

getStringRepresentationOfArrayEntry

public static java.lang.String getStringRepresentationOfArrayEntry(java.lang.Object array,
                                                                   int index)

getAllFields

public static java.util.ArrayList<java.lang.reflect.Field> getAllFields(java.lang.Class<?> cls)

printFieldContents

public static void printFieldContents(java.lang.Object instance,
                                      java.lang.reflect.Field field)
                               throws java.lang.IllegalArgumentException,
                                      java.lang.IllegalAccessException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException

getFieldContentsAssignableFromClass

public static <T> java.util.List<T> getFieldContentsAssignableFromClass(java.lang.Object object,
                                                                        java.lang.Class<T> clazz)