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
|
protected <T> T |
cloneInternal(T o,
Map<Object,Object> clones) |
protected boolean |
considerImmutable(Class<?> clz)
override this to decide if a class is immutable.
|
<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) |
IDumpCloned |
getDumpCloned() |
protected Class<?> |
getImmutableAnnotation() |
boolean |
isCloneAnonymousParent() |
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 |
registerCloningStrategy(ICloningStrategy strategy) |
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 |
setCloneAnonymousParent(boolean cloneAnonymousParent)
if false, anonymous classes parent class won't be cloned.
|
void |
setCloneSynthetics(boolean cloneSynthetics) |
void |
setCloningEnabled(boolean cloningEnabled) |
void |
setDontCloneInstanceOf(Class<?>... c) |
void |
setDumpCloned(IDumpCloned dumpCloned)
provide a cloned classes dumper (so i.e.
|
void |
setDumpClonedClasses(boolean dumpClonedClasses)
will println() all cloned classes.
|
void |
setExtraImmutables(Set<Class<?>> set) |
void |
setExtraNullInsteadOfClone(Set<Class<?>> set) |
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".
|
static Cloner |
shared() |
static Cloner |
standard() |
void |
unregisterFastCloner(Class<?> c) |
public Cloner()
public Cloner(IInstantiationStrategy instantiationStrategy)
public IDumpCloned getDumpCloned()
public void setDumpCloned(IDumpCloned dumpCloned)
dumpCloned - an implementation of the interface which can dump the
cloned classes.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 registerCloningStrategy(ICloningStrategy strategy)
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 setDontCloneInstanceOf(Class<?>... c)
public void nullInsteadOfClone(Class<?>... c)
c - the classes to nullify during cloningpublic void registerImmutable(Class<?>... c)
c - the immutable classpublic void registerFastCloner(Class<?> c, IFastCloner fastCloner)
public void unregisterFastCloner(Class<?> c)
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-clonedprotected boolean considerImmutable(Class<?> clz)
clz - the class under checkprotected Class<?> getImmutableAnnotation()
protected <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)
public void setCloneAnonymousParent(boolean cloneAnonymousParent)
public boolean isCloneAnonymousParent()
public static Cloner standard()
public static Cloner shared()
Copyright © 2017. All rights reserved.