public class MinimalCloner extends Object implements Cloner, CloneDriver, CloneImplementor
Cloner
. It can deliver somewhat better throughput
than UnsafeCloneStrategy
using the Server JVM, and around twice the throughput of the
PortableCloneStrategy
. Unlike BasicCloner, this cloner does not offer any configuration
options. Due to lack of configuration and special functions, this cloner is unsuitable for many
datatypes.
Note that MinimalCloner can be slower for certain kinds of data structure. For example, when
cloning a linked list, MinimalCloner must visit all the references of the entire data structure,
whereas other Cloners can use a CloneImplementor to perform efficient cloning of this structure
iteratively.
In general, you are recommended to use MinimalCloner judiciously. Typically you can use it by
designating a data type as @Cloneable(implementor=MinimalCloner.class) so that the type known to
benefit from this cloner makes use of it.Constructor and Description |
---|
MinimalCloner() |
Modifier and Type | Method and Description |
---|---|
boolean |
canClone(Class<?> clazz)
Always returns true
|
<T> T |
clone(T obj)
Clones the supplied object
|
<T> T |
clone(T obj,
CloneDriver context,
IdentityHashMap<Object,Object> referencesToReuse,
long stackDepth)
Performs a clone.
|
CloneImplementor |
getAnnotationImplementor(Class<?> clazz)
Cloneable annotation is not supported
|
CloneImplementor |
getBuiltInImplementor(Class<?> clazz)
Gets the built in implementor for the given class
|
MethodHandle |
getCloneMethod(Class<?> clazz)
Cloneable interface is not supported
|
Set<Class<?>> |
getImmutableClasses()
No Immutable classes are identified
|
CloneImplementor |
getImplementor(Class<?> clazz)
This implementation does not delegate to implementors
|
Set<Class<?>> |
getNonCloneableClasses()
No Non-Cloneable classes are identified
|
void |
initialiseFor(Class<?> classes)
This method is included simply so that cold starts can be avoided.
|
boolean |
isCloneImmutable()
Immutable fields are always cloned, but object reference identity in the new structure is
preserved
|
boolean |
isCloneSyntheticFields()
Does not clone synthetic fields
|
boolean |
isCloneTransientAnnotatedFields()
Transient annotated fields are always cloned
|
boolean |
isCloneTransientFields()
Transient fields are always cloned
|
boolean |
isImmutableInstance(Object instance)
Indicates whether the given object instance should be treated as immutable
|
boolean |
isTrackReferences()
Indicates whether to track references
|
boolean |
isTrackReferencesForFlatClasses()
Indicates whether to also track references for flat classes when tracking references.
|
boolean |
isUseCloneable()
This implementation cannot invoke clone()
|
boolean |
isUseCloneImplementors()
CloneImplementors may not be used
|
<T> T |
newInstance(Class<T> c)
Create a new, uninitialised instance of the given class (if supported).
|
void |
putAnnotationImplementor(Class<?> clazz,
CloneImplementor implementor)
Put the registered implementor for the given class
|
void |
putCloneMethod(Class<?> clazz,
MethodHandle handle)
Put the clone() method for the indicated class
|
void |
putImmutableInstance(Object instance)
Stores an object instance to be treated as immutable
|
public MinimalCloner()
public <T> T newInstance(Class<T> c)
CloneImplementor
newInstance
in interface CloneImplementor
T
- The type of the instance to be constructedc
- Type to create instance ofpublic boolean canClone(Class<?> clazz)
canClone
in interface CloneImplementor
clazz
- The classpublic <T> T clone(T obj, CloneDriver context, IdentityHashMap<Object,Object> referencesToReuse, long stackDepth)
CloneImplementor
clone
in interface CloneImplementor
T
- The type of the object to be clonedobj
- Object to clonecontext
- The CloneDriver that initiated the requestreferencesToReuse
- Any references for objects already cloned to ensure reference
identity is preservedstackDepth
- The number of objects already cloned in the current data structurepublic CloneImplementor getImplementor(Class<?> clazz)
getImplementor
in interface CloneDriver
clazz
- The classpublic boolean isUseCloneable()
isUseCloneable
in interface CloneDriver
public boolean isCloneTransientFields()
isCloneTransientFields
in interface CloneDriver
public boolean isCloneTransientAnnotatedFields()
isCloneTransientAnnotatedFields
in interface CloneDriver
public boolean isCloneImmutable()
isCloneImmutable
in interface CloneDriver
public Set<Class<?>> getImmutableClasses()
getImmutableClasses
in interface CloneDriver
public Set<Class<?>> getNonCloneableClasses()
getNonCloneableClasses
in interface CloneDriver
public boolean isUseCloneImplementors()
isUseCloneImplementors
in interface CloneDriver
public <T> T clone(T obj)
Cloner
public void initialiseFor(Class<?> classes)
Cloner
initialiseFor
in interface Cloner
classes
- Classes to perform initialisation for.public CloneImplementor getAnnotationImplementor(Class<?> clazz)
getAnnotationImplementor
in interface CloneDriver
clazz
- The classpublic MethodHandle getCloneMethod(Class<?> clazz)
getCloneMethod
in interface CloneDriver
clazz
- The class to obtain the method forpublic boolean isCloneSyntheticFields()
isCloneSyntheticFields
in interface CloneDriver
public void putAnnotationImplementor(Class<?> clazz, CloneImplementor implementor)
CloneDriver
putAnnotationImplementor
in interface CloneDriver
clazz
- The classimplementor
- Implementor to registerpublic void putCloneMethod(Class<?> clazz, MethodHandle handle)
CloneDriver
putCloneMethod
in interface CloneDriver
clazz
- The class to obtain the method forhandle
- The related MethodHandlepublic CloneImplementor getBuiltInImplementor(Class<?> clazz)
CloneDriver
getBuiltInImplementor
in interface CloneDriver
clazz
- The classpublic boolean isImmutableInstance(Object instance)
CloneDriver
isImmutableInstance
in interface CloneDriver
instance
- The instance to check for whether it is registered as immutablepublic void putImmutableInstance(Object instance)
CloneDriver
putImmutableInstance
in interface CloneDriver
instance
- Object to be considered immutablepublic boolean isTrackReferences()
CloneDriver
isTrackReferences
in interface CloneDriver
public boolean isTrackReferencesForFlatClasses()
CloneDriver
isTrackReferencesForFlatClasses
in interface CloneDriver
Copyright © 2010–2018 Jadira Systems. All rights reserved.