public class Cloner extends Object
| Constructor and Description |
|---|
Cloner() |
Cloner(IInstantiationStrategy instantiationStrategy) |
| Modifier and Type | Method and Description |
|---|---|
protected List<Field> |
allFields(Class<?> c)
reflection utils, override this to choose which fields to clone
|
<T> T |
cloneInternal(T o,
Map<Object,Object> clones)
PLEASE DONT CALL THIS METHOD
The only reason for been public is because custom IFastCloner's must invoke it
|
<T,E extends T> |
copyPropertiesOfInheritedClass(T src,
E dest)
copies all properties from src to dest.
|
<T> T |
deepClone(T o)
deep clones "o".
|
<T> T |
deepCloneDontCloneInstances(T o,
Object... dontCloneThese) |
void |
dontClone(Class<?>... c)
instances of classes that shouldn't be cloned can be registered using this method.
|
void |
dontCloneInstanceOf(Class<?>... c) |
protected Object |
fastClone(Object o,
Map<Object,Object> clones) |
<T> T |
fastCloneOrNewInstance(Class<T> c) |
boolean |
isCloningEnabled() |
boolean |
isDumpClonedClasses() |
boolean |
isNullTransient() |
protected <T> T |
newInstance(Class<T> c)
creates a new instance of c.
|
void |
nullInsteadOfClone(Class<?>... c)
instead of cloning these classes will set the field to null
|
void |
registerConstant(Class<?> c,
String privateFieldName) |
void |
registerConstant(Object o) |
void |
registerFastCloner(Class<?> c,
IFastCloner fastCloner) |
protected void |
registerFastCloners()
registers a std set of fast cloners.
|
void |
registerImmutable(Class<?>... c)
registers an immutable class.
|
protected void |
registerKnownConstants() |
protected void |
registerKnownJdkImmutableClasses()
registers some known JDK immutable classes.
|
void |
registerStaticFields(Class<?>... classes)
registers all static fields of these classes.
|
void |
setCloneSynthetics(boolean cloneSynthetics) |
void |
setCloningEnabled(boolean cloningEnabled) |
void |
setDumpClonedClasses(boolean dumpClonedClasses)
will println() all cloned classes.
|
void |
setExtraImmutables(Set<Class<?>> set)
spring framework friendly version of registerImmutable
|
void |
setExtraNullInsteadOfClone(Set<Class<?>> set)
spring framework friendly version of nullInsteadOfClone
|
void |
setExtraStaticFields(Set<Class<?>> set)
spring framework friendly version of registerStaticFields
|
void |
setNullTransient(boolean nullTransient)
this makes the cloner to set a transient field to null upon cloning.
|
<T> T |
shallowClone(T o)
shallow clones "o".
|
public Cloner()
public Cloner(IInstantiationStrategy instantiationStrategy)
public boolean isNullTransient()
public void setNullTransient(boolean nullTransient)
nullTransient - true for transient fields to be nulledpublic void setCloneSynthetics(boolean cloneSynthetics)
protected void registerFastCloners()
protected Object fastClone(Object o, Map<Object,Object> clones) throws IllegalAccessException
IllegalAccessExceptionpublic void registerConstant(Object o)
protected void registerKnownJdkImmutableClasses()
protected void registerKnownConstants()
public void registerStaticFields(Class<?>... classes)
classes - array of classespublic void setExtraStaticFields(Set<Class<?>> set)
set - a set of classes which will be scanned for static fieldspublic void dontClone(Class<?>... c)
c - The class that shouldn't be cloned. That is, whenever a deep clone for
an object is created and c is encountered, the object instance of c will
be added to the clone.public void dontCloneInstanceOf(Class<?>... c)
public void nullInsteadOfClone(Class<?>... c)
c - the classes to nullify during cloningpublic void setExtraNullInsteadOfClone(Set<Class<?>> set)
public void registerImmutable(Class<?>... c)
c - the immutable classpublic void setExtraImmutables(Set<Class<?>> set)
public void registerFastCloner(Class<?> c, IFastCloner fastCloner)
protected <T> T newInstance(Class<T> c)
T - the type of cc - the classpublic <T> T fastCloneOrNewInstance(Class<T> c)
public <T> T deepClone(T o)
T - the type of "o"o - the object to be deep-clonedpublic <T> T deepCloneDontCloneInstances(T o,
Object... dontCloneThese)
public <T> T shallowClone(T o)
T - the type of oo - the object to be shallow-clonedpublic <T> T cloneInternal(T o,
Map<Object,Object> clones)
throws IllegalAccessException
IllegalAccessExceptionpublic <T,E extends T> void copyPropertiesOfInheritedClass(T src,
E dest)
src - the source objectdest - the destination object which must contain as minimum all the fields of srcprotected List<Field> allFields(Class<?> c)
public boolean isDumpClonedClasses()
public void setDumpClonedClasses(boolean dumpClonedClasses)
dumpClonedClasses - true to enable printing all cloned classespublic boolean isCloningEnabled()
public void setCloningEnabled(boolean cloningEnabled)
Copyright © 2012. All Rights Reserved.