public class Cloner
extends java.lang.Object
构造器和说明 |
---|
Cloner() |
Cloner(IInstantiationStrategy instantiationStrategy) |
限定符和类型 | 方法和说明 |
---|---|
protected java.util.List<java.lang.reflect.Field> |
allFields(java.lang.Class<?> c)
reflection utils, override this to choose which fields to clone
|
protected <T> T |
cloneInternal(T o,
java.util.Map<java.lang.Object,java.lang.Object> clones) |
protected boolean |
considerImmutable(java.lang.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,
java.lang.Object... dontCloneThese) |
void |
dontClone(java.lang.Class<?>... c)
instances of classes that shouldn't be cloned can be registered using this method.
|
void |
dontCloneInstanceOf(java.lang.Class<?>... c) |
protected java.lang.Object |
fastClone(java.lang.Object o,
java.util.Map<java.lang.Object,java.lang.Object> clones) |
<T> T |
fastCloneOrNewInstance(java.lang.Class<T> c) |
IDumpCloned |
getDumpCloned() |
protected java.lang.Class<?> |
getImmutableAnnotation() |
boolean |
isCloneAnonymousParent() |
boolean |
isCloningEnabled() |
boolean |
isDumpClonedClasses() |
boolean |
isNullTransient() |
protected <T> T |
newInstance(java.lang.Class<T> c)
creates a new instance of c.
|
void |
nullInsteadOfClone(java.lang.Class<?>... c)
instead of cloning these classes will set the field to null
|
void |
registerConstant(java.lang.Class<?> c,
java.lang.String privateFieldName) |
void |
registerConstant(java.lang.Object o) |
void |
registerFastCloner(java.lang.Class<?> c,
IFastCloner fastCloner) |
protected void |
registerFastCloners()
registers a std set of fast cloners.
|
void |
registerImmutable(java.lang.Class<?>... c)
registers an immutable class.
|
protected void |
registerKnownConstants() |
protected void |
registerKnownJdkImmutableClasses()
registers some known JDK immutable classes.
|
void |
registerStaticFields(java.lang.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(java.lang.Class<?>... c) |
void |
setDumpCloned(IDumpCloned dumpCloned)
provide a cloned classes dumper (so i.e. they can be logged or stored in a file
instead of the default behaviour which is to println(cloned) )
|
void |
setDumpClonedClasses(boolean dumpClonedClasses)
will println() all cloned classes.
|
void |
setExtraImmutables(java.util.Set<java.lang.Class<?>> set) |
void |
setExtraNullInsteadOfClone(java.util.Set<java.lang.Class<?>> set) |
void |
setExtraStaticFields(java.util.Set<java.lang.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(java.lang.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 java.lang.Object fastClone(java.lang.Object o, java.util.Map<java.lang.Object,java.lang.Object> clones) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public void registerConstant(java.lang.Object o)
public void registerConstant(java.lang.Class<?> c, java.lang.String privateFieldName)
protected void registerKnownJdkImmutableClasses()
protected void registerKnownConstants()
public void registerStaticFields(java.lang.Class<?>... classes)
classes
- array of classespublic void setExtraStaticFields(java.util.Set<java.lang.Class<?>> set)
set
- a set of classes which will be scanned for static fieldspublic void dontClone(java.lang.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(java.lang.Class<?>... c)
public void setDontCloneInstanceOf(java.lang.Class<?>... c)
public void nullInsteadOfClone(java.lang.Class<?>... c)
c
- the classes to nullify during cloningpublic void setExtraNullInsteadOfClone(java.util.Set<java.lang.Class<?>> set)
public void registerImmutable(java.lang.Class<?>... c)
c
- the immutable classpublic void setExtraImmutables(java.util.Set<java.lang.Class<?>> set)
public void registerFastCloner(java.lang.Class<?> c, IFastCloner fastCloner)
public void unregisterFastCloner(java.lang.Class<?> c)
protected <T> T newInstance(java.lang.Class<T> c)
T
- the type of cc
- the classpublic <T> T fastCloneOrNewInstance(java.lang.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, java.lang.Object... dontCloneThese)
public <T> T shallowClone(T o)
T
- the type of oo
- the object to be shallow-clonedprotected boolean considerImmutable(java.lang.Class<?> clz)
clz
- the class under checkprotected java.lang.Class<?> getImmutableAnnotation()
protected <T> T cloneInternal(T o, java.util.Map<java.lang.Object,java.lang.Object> clones) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public <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 java.util.List<java.lang.reflect.Field> allFields(java.lang.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()