Package org.kie.camel.embedded.component
Class FastCloner
- java.lang.Object
-
- org.kie.camel.embedded.component.FastCloner
-
public class FastCloner extends Object
Cloner: deep clone objects. This class is thread safe. One instance can be used by multiple threads on the same time. 18 Sep 2008
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFastCloner.FastClonerArrayListstatic classFastCloner.FastClonerCalendarstatic classFastCloner.FastClonerCustomCollection<T extends Collection>static classFastCloner.FastClonerHashMapstatic classFastCloner.FastClonerHashSetstatic classFastCloner.FastClonerLinkedListstatic classFastCloner.FastClonerTreeMapstatic interfaceFastCloner.IFastCloner
-
Constructor Summary
Constructors Constructor Description FastCloner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> TcloneInternal(T o, Map<Object,Object> clones)PLEASE DONT CALL THIS METHOD The only reason for been public is because IFastCloner must invoke it<T,E extends T>
voidcopyPropertiesOfInheritedClass(T src, E dest)copies all properties from src to dest.<T> TdeepClone(T o)deep clones "o".voiddontClone(Class<?>... c)instances of classes that shouldn't be cloned can be registered using this method.protected ObjectfastClone(Object o, Map<Object,Object> clones)<T> TfastCloneOrNewInstance(Class<T> c)booleanisCloningEnabled()booleanisDumpClonedClasses()booleanisNullTransient()voidnullInsteadOfClone(Class<?>... c)instead of cloning these classes will set the field to nullvoidregisterConstant(Class<?> c, String privateFieldName)voidregisterConstant(Object o)voidregisterFastCloner(Class<?> c, FastCloner.IFastCloner fastCloner)protected voidregisterFastCloners()registers a std set of fast cloners.voidregisterImmutable(Class<?>... c)registers an immutable class.protected voidregisterKnownConstants()protected voidregisterKnownJdkImmutableClasses()registers some known JDK immutable classes.voidregisterStaticFields(Class<?>... classes)registers all static fields of these classes.voidsetCloningEnabled(boolean cloningEnabled)voidsetDumpClonedClasses(boolean dumpClonedClasses)will println() all cloned classes.voidsetExtraImmutables(Set<Class<?>> set)spring framework friendly version of registerImmutablevoidsetExtraNullInsteadOfClone(Set<Class<?>> set)spring framework friendly version of nullInsteadOfClonevoidsetNullTransient(boolean nullTransient)this makes the cloner to set a transient field to null upon cloning.<T> TshallowClone(T o)shallow clones "o".
-
-
-
Method Detail
-
isNullTransient
public boolean isNullTransient()
-
setNullTransient
public void setNullTransient(boolean nullTransient)
this makes the cloner to set a transient field to null upon cloning. NOTE: primitive types can't be nulled. Their value will be set to default, i.e. 0 for int- Parameters:
nullTransient- true for transient fields to be nulled
-
registerFastCloners
protected void registerFastCloners()
registers a std set of fast cloners.
-
fastClone
protected Object fastClone(Object o, Map<Object,Object> clones) throws IllegalAccessException
- Throws:
IllegalAccessException
-
registerConstant
public void registerConstant(Object o)
-
registerKnownJdkImmutableClasses
protected void registerKnownJdkImmutableClasses()
registers some known JDK immutable classes. Override this to register your own list of jdk's immutable classes
-
registerKnownConstants
protected void registerKnownConstants()
-
registerStaticFields
public void registerStaticFields(Class<?>... classes)
registers all static fields of these classes. Those static fields won't be cloned when an instance of the class is cloned. This is useful i.e. when a static field object is added into maps or sets. At that point, there is no way for the cloner to know that it was static except if it is registered.- Parameters:
classes- array of classes
-
dontClone
public void dontClone(Class<?>... c)
instances of classes that shouldn't be cloned can be registered using this method.- Parameters:
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.
-
nullInsteadOfClone
public void nullInsteadOfClone(Class<?>... c)
instead of cloning these classes will set the field to null- Parameters:
c- the classes to nullify during cloning
-
setExtraNullInsteadOfClone
public void setExtraNullInsteadOfClone(Set<Class<?>> set)
spring framework friendly version of nullInsteadOfClone
-
registerImmutable
public void registerImmutable(Class<?>... c)
registers an immutable class. Immutable classes are not cloned.- Parameters:
c- the immutable class
-
setExtraImmutables
public void setExtraImmutables(Set<Class<?>> set)
spring framework friendly version of registerImmutable
-
registerFastCloner
public void registerFastCloner(Class<?> c, FastCloner.IFastCloner fastCloner)
-
fastCloneOrNewInstance
public <T> T fastCloneOrNewInstance(Class<T> c)
-
deepClone
public <T> T deepClone(T o)
deep clones "o".- Type Parameters:
T- the type of "o"- Parameters:
o- the object to be deep-cloned- Returns:
- a deep-clone of "o".
-
shallowClone
public <T> T shallowClone(T o)
shallow clones "o". This means that if c=shallowClone(o) then c!=o. Any change to c won't affect o.- Type Parameters:
T- the type of o- Parameters:
o- the object to be shallow-cloned- Returns:
- a shallow clone of "o"
-
cloneInternal
protected <T> T cloneInternal(T o, Map<Object,Object> clones) throws IllegalAccessExceptionPLEASE DONT CALL THIS METHOD The only reason for been public is because IFastCloner must invoke it- Throws:
IllegalAccessException
-
copyPropertiesOfInheritedClass
public <T,E extends T> void copyPropertiesOfInheritedClass(T src, E dest)copies all properties from src to dest. Src and dest can be of different class, provided they contain same field names- Parameters:
src- the source objectdest- the destination object which must contain as minimul all the fields of src
-
isDumpClonedClasses
public boolean isDumpClonedClasses()
-
setDumpClonedClasses
public void setDumpClonedClasses(boolean dumpClonedClasses)
will println() all cloned classes. Useful for debugging only.- Parameters:
dumpClonedClasses- true to enable printing all cloned classes
-
isCloningEnabled
public boolean isCloningEnabled()
-
setCloningEnabled
public void setCloningEnabled(boolean cloningEnabled)
-
-