org.kuali.rice.krad.uif.util
Class CloneUtils

java.lang.Object
  extended by org.kuali.rice.krad.uif.util.CloneUtils

public class CloneUtils
extends Object

Utility class for copying objects using reflection. Modified from the jCommon library: http://www.matthicks.com/2008/05/fastest-deep-cloning.html

Author:
Matt Hicks, Kuali Rice Team (rice.collab@kuali.org)

Constructor Summary
CloneUtils()
           
 
Method Summary
static
<O> O
deepClone(O original)
           
protected static Object deepCloneList(Object original, Map<Object,Object> cache, boolean referenceCollectionCopy)
           
protected static Object deepCloneMap(Object original, Map<Object,Object> cache, boolean referenceCollectionCopy)
           
protected static Object deepCloneObject(Object original, Map<Object,Object> cache)
           
static
<O> O
deepCloneReflection(O original)
           
protected static Object deepCloneReflectionInternal(Object original, Map<Object,Object> cache, boolean referenceCollectionCopy)
           
static boolean fieldHasAnnotation(Class<?> clazz, String propertyName, Class<? extends Annotation> annotationClass)
          Determines whether the property of the given class has the given annotation specified
protected static List<Class<?>> getClassHierarchy(Class<?> c, boolean includeInterfaces)
           
static Field[] getFields(Class<?> c, boolean includeStatic)
           
static Field[] getFields(Class<?> c, boolean includeStatic, boolean includeTransient)
           
static Field[] getFields(Object object, boolean includeStatic)
           
static Field[] getFields(Object object, boolean includeStatic, boolean includeTransient)
           
static Map<String,Annotation> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass)
          Retrieves all field names for the given class that have the given annotation
protected static Object instantiate(Object original)
           
protected static Field internalField(Object object, String fieldName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloneUtils

public CloneUtils()
Method Detail

deepClone

public static final <O> O deepClone(O original)

deepCloneReflection

public static final <O> O deepCloneReflection(O original)
                                   throws Exception
Throws:
Exception

deepCloneReflectionInternal

protected static final Object deepCloneReflectionInternal(Object original,
                                                          Map<Object,Object> cache,
                                                          boolean referenceCollectionCopy)
                                                   throws Exception
Throws:
Exception

deepCloneObject

protected static Object deepCloneObject(Object original,
                                        Map<Object,Object> cache)
                                 throws Exception
Throws:
Exception

deepCloneMap

protected static Object deepCloneMap(Object original,
                                     Map<Object,Object> cache,
                                     boolean referenceCollectionCopy)
                              throws Exception
Throws:
Exception

deepCloneList

protected static Object deepCloneList(Object original,
                                      Map<Object,Object> cache,
                                      boolean referenceCollectionCopy)
                               throws Exception
Throws:
Exception

getFieldsWithAnnotation

public static Map<String,Annotation> getFieldsWithAnnotation(Class<?> clazz,
                                                             Class<? extends Annotation> annotationClass)
Retrieves all field names for the given class that have the given annotation

Parameters:
clazz - - class to find field annotations for
annotationClass - - class for annotation to find
Returns:
Map map containing the field name that has the annotation as a key and the annotation instance as a value

fieldHasAnnotation

public static boolean fieldHasAnnotation(Class<?> clazz,
                                         String propertyName,
                                         Class<? extends Annotation> annotationClass)
Determines whether the property of the given class has the given annotation specified

Parameters:
clazz - - class containing the property to check
propertyName - - name of the property to check
annotationClass - - class for the annotation to look for
Returns:
boolean true if the field associated with the property name has the given annotation, false if not

instantiate

protected static final Object instantiate(Object original)
                                   throws InstantiationException,
                                          IllegalAccessException
Throws:
InstantiationException
IllegalAccessException

getFields

public static Field[] getFields(Object object,
                                boolean includeStatic)

getFields

public static Field[] getFields(Object object,
                                boolean includeStatic,
                                boolean includeTransient)

getFields

public static Field[] getFields(Class<?> c,
                                boolean includeStatic)

getFields

public static Field[] getFields(Class<?> c,
                                boolean includeStatic,
                                boolean includeTransient)

internalField

protected static final Field internalField(Object object,
                                           String fieldName)

getClassHierarchy

protected static List<Class<?>> getClassHierarchy(Class<?> c,
                                                  boolean includeInterfaces)


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.