|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.unitils.mock.core.proxy.CloneUtil
public class CloneUtil
Utility class for deep cloning objects. In a deep clone, not only the object itself is cloned, but also all the inner objects.
| Constructor Summary | |
|---|---|
CloneUtil()
|
|
| Method Summary | ||
|---|---|---|
protected static java.lang.Object |
cloneArray(java.lang.Object arrayToClone,
java.util.Map<java.lang.Object,java.lang.Object> cloneCache)
Clones the given array and all it's elements. |
|
protected static void |
cloneFields(java.lang.Class<?> clazz,
java.lang.Object instanceToClone,
java.lang.Object clonedInstance,
java.util.Map<java.lang.Object,java.lang.Object> cloneCache)
Clones all values in all fields of the given class and superclasses. |
|
protected static java.lang.Object |
cloneObject(java.lang.Object instanceToClone,
java.util.Map<java.lang.Object,java.lang.Object> cloneCache)
Actual implementation of the cloning. |
|
static
|
createDeepClone(T object)
Creates a deep clone of the given object. |
|
protected static java.lang.Object |
createInstanceUsingClone(java.lang.Object instanceToClone)
If the given value is cloneable and the cloning succeeds, the clone is returned, else null is returned. |
|
protected static java.lang.Object |
createInstanceUsingObjenesis(java.lang.Object instanceToClone)
Tries to create an instance of the same type as the given value using Objenesis. |
|
protected static boolean |
isImmutable(java.lang.Object instanceToClone)
Returns the given value if it is immutable, else null is returned. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CloneUtil()
| Method Detail |
|---|
public static <T> T createDeepClone(T object)
object - The object to clone
protected static java.lang.Object cloneObject(java.lang.Object instanceToClone,
java.util.Map<java.lang.Object,java.lang.Object> cloneCache)
throws java.lang.Throwable
cloneArray(java.lang.Object, java.util.Map) method.
Finally it will see whether the object is cloneable and the clone method can be used. If not, Objenisis is
used to create the instance. The last step is to recursively do the same operation for the inner fields.
An object is cloned once. All created clones are put in a cache and if an object is to be cloned a second time,
the cached instance is used. This way the object graph is preserved.
instanceToClone - The instance, not nullcloneCache - The cached clones, not null
java.lang.Throwableprotected static boolean isImmutable(java.lang.Object instanceToClone)
instanceToClone - The instance, not null
protected static java.lang.Object createInstanceUsingClone(java.lang.Object instanceToClone)
instanceToClone - The instance, not null
protected static java.lang.Object createInstanceUsingObjenesis(java.lang.Object instanceToClone)
instanceToClone - The instance, not null
protected static void cloneFields(java.lang.Class<?> clazz,
java.lang.Object instanceToClone,
java.lang.Object clonedInstance,
java.util.Map<java.lang.Object,java.lang.Object> cloneCache)
throws java.lang.Throwable
clazz - The current classinstanceToClone - The instance, not nullclonedInstance - The clone, not nullcloneCache - The cached clones, not null
java.lang.Throwable
protected static java.lang.Object cloneArray(java.lang.Object arrayToClone,
java.util.Map<java.lang.Object,java.lang.Object> cloneCache)
throws java.lang.Throwable
arrayToClone - The array, not nullcloneCache - The cached clones, not null
java.lang.Throwable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||