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

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

public final class CopyUtils
extends Object

Provides a lightweight "hands-free" copy implementation to replace the need for copyProperties() in building LifecycleElement implementations.

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

Constructor Summary
CopyUtils()
           
 
Method Summary
static
<T> T
copy(Copyable obj)
          Mix-in copy implementation for objects that implement the Copyable interface}
static
<T> T
getDeepCopy(T obj)
          Get a deep copy of an object using cloning.
static
<T> T
getShallowCopy(T obj)
          Get a shallow copy (clone) of an object.
static boolean isDeepCopyAvailable(Class<?> type)
          Determine if deep copying is available for a type.
static boolean isDelay()
          Determine whether or not to use a delayed copy proxy.
static
<T> boolean
isShallowCopyAvailable(T obj)
          Determine if shallow copying is available on an object.
static void preventModification(Copyable obj)
          Prepare a copyable object for caching by calling Copyable.preventModification() on all copyable instances located by a deep traversal of the object.
static
<T extends Copyable>
T
unwrapDeep(Copyable obj)
          Prepare a copyable object for caching by calling Copyable.preventModification() on all copyable instances located by a deep traversal of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CopyUtils

public CopyUtils()
Method Detail

isDelay

public static boolean isDelay()
Determine whether or not to use a delayed copy proxy.

When true, and #isUseClone() is also true, then deep copy operations will be truncated where a copyable represented by an interfaces is specified by the field, array, list or map involved indicated. Rather than copy the object directly, a proxy wrapping the original will be placed, which when used will invoke the copy operation.

This value is controlled by the parameter "krad.uif.copyable.delay". By default, full deep copy will be used.

Returns:
True if deep copy will be truncated with a delayed copy proxy, false for full deep copy.

copy

public static <T> T copy(Copyable obj)
Mix-in copy implementation for objects that implement the Copyable interface}

Type Parameters:
T - copyable type
Parameters:
obj - The object to copy.
Returns:
A deep copy of the object.

isShallowCopyAvailable

public static <T> boolean isShallowCopyAvailable(T obj)
Determine if shallow copying is available on an object.

Type Parameters:
T - copyable type
Parameters:
obj - The object to check.
Returns:
True if getShallowCopy(Object) may be expected to return a shallow copy of the object. False if a null return value is expected.

isDeepCopyAvailable

public static boolean isDeepCopyAvailable(Class<?> type)
Determine if deep copying is available for a type.

Parameters:
type - The type to check.
Returns:
True if getDeepCopy(Object) may be expected to follow references to this type. False if the type should not be deeply copied.

getShallowCopy

public static <T> T getShallowCopy(T obj)
                        throws CloneNotSupportedException
Get a shallow copy (clone) of an object.

This method simplifies access to the clone() method.

Type Parameters:
T - copyable type
Parameters:
obj - The object to clone.
Returns:
A shallow copy of obj, or null if obj is null.
Throws:
CloneNotSupportedException - If copying is not available on the object, or if thrown by clone() itself. When isShallowCopyAvailable() returns true, then this exception is not expected and may be considered an internal error.

preventModification

public static void preventModification(Copyable obj)
Prepare a copyable object for caching by calling Copyable.preventModification() on all copyable instances located by a deep traversal of the object.

Parameters:
obj - The object to prepare for caching.

unwrapDeep

public static <T extends Copyable> T unwrapDeep(Copyable obj)
Prepare a copyable object for caching by calling Copyable.preventModification() on all copyable instances located by a deep traversal of the object.

Type Parameters:
T - copyable type
Parameters:
obj - The object to prepare for caching.
Returns:
A deep copy of the object.

getDeepCopy

public static <T> T getDeepCopy(T obj)
Get a deep copy of an object using cloning.

Type Parameters:
T - copyable type
Parameters:
obj - The object to get a deep copy of.
Returns:
A deep copy of the object.


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.