|
||||||||||
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 Object |
cloneArray(Object arrayToClone,
Map<Object,Object> cloneCache)
Clones the given array and all it's elements. |
|
protected static void |
cloneFields(Class<?> clazz,
Object instanceToClone,
Object clonedInstance,
Map<Object,Object> cloneCache)
Clones all values in all fields of the given class and superclasses. |
|
protected static Object |
cloneObject(Object instanceToClone,
Map<Object,Object> cloneCache)
Actual implementation of the cloning. |
|
static
|
createDeepClone(T object)
Creates a deep clone of the given object. |
|
protected static Object |
createInstanceUsingClone(Object instanceToClone)
If the given value is cloneable and the cloning succeeds, the clone is returned, else null is returned. |
|
protected static Object |
createInstanceUsingObjenesis(Object instanceToClone)
Tries to create an instance of the same type as the given value using Objenesis. |
|
protected static boolean |
isImmutable(Object instanceToClone)
|
|
protected static boolean |
isJdkClass(Object instanceToClone)
|
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 Object cloneObject(Object instanceToClone, Map<Object,Object> cloneCache) throws 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
Throwable
protected static boolean isImmutable(Object instanceToClone)
instanceToClone
- The instance, not null
protected static boolean isJdkClass(Object instanceToClone)
instanceToClone
- The instance, not null
protected static Object createInstanceUsingClone(Object instanceToClone)
instanceToClone
- The instance, not null
protected static Object createInstanceUsingObjenesis(Object instanceToClone)
instanceToClone
- The instance, not null
protected static void cloneFields(Class<?> clazz, Object instanceToClone, Object clonedInstance, Map<Object,Object> cloneCache) throws Throwable
clazz
- The current classinstanceToClone
- The instance, not nullclonedInstance
- The clone, not nullcloneCache
- The cached clones, not null
Throwable
protected static Object cloneArray(Object arrayToClone, Map<Object,Object> cloneCache) throws Throwable
arrayToClone
- The array, not nullcloneCache
- The cached clones, not null
Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |