public final class Clone extends Object implements Serializable
Object using this class instance call clone(Object) method.
There are some preconfigured options available:
- basic() - Clone instance for cloning basic types and objects that implement CloneBehavior
- deep() - Clone instance for cloning any Cloneable objects
- reflective() - Clone instance for cloning any objects, Cloneable or notClone,
UnknownResolver,
GlobalCloneBehavior,
CloneBehavior,
Cloneable,
Serialized Form| Constructor and Description |
|---|
Clone(UnknownResolver unknownResolver,
GlobalCloneBehavior... behaviors)
Constructs new
Clone algorithm. |
Clone(UnknownResolver unknownResolver,
List<GlobalCloneBehavior> behaviors)
Constructs new
Clone algorithm. |
| Modifier and Type | Method and Description |
|---|---|
static Clone |
basic()
Returns
Clone algorithm that is able to clone basic object types as well as simple Collections and Maps. |
<T> T |
clone(T object)
Returns clone of the specified object.
|
static Clone |
deep()
Returns
Clone algorithm that can also clone custom objects through ReflectionCloneBehavior. |
<T> T |
nonNullClone(T object)
Returns non-
null clone of the specified object. |
static Clone |
reflective()
|
public Clone(@NotNull UnknownResolver unknownResolver, @NotNull GlobalCloneBehavior... behaviors)
Clone algorithm.unknownResolver - unknown object types case resolverbehaviors - behaviors taking part in this clone algorithm instancepublic Clone(@NotNull UnknownResolver unknownResolver, @NotNull List<GlobalCloneBehavior> behaviors)
Clone algorithm.unknownResolver - unknown object types case resolverbehaviors - behaviors taking part in this clone algorithm instance@Nullable public <T> T clone(@Nullable T object)
Clone.InternalClone instance is used for every separate clone operation.
That is necessary because Clone.InternalClone stores cloned object references internally to preserve object links.T - cloned object typeobject - object to clone, should never be null@NotNull public <T> T nonNullClone(@NotNull T object)
null clone of the specified object.
New Clone.InternalClone instance is used for every separate clone operation.
That is necessary because Clone.InternalClone stores cloned object references internally to preserve object links.T - cloned object typeobject - object to clone, should never be nullnull clone of the specified object@NotNull public static Clone basic()
Clone algorithm that is able to clone basic object types as well as simple Collections and Maps.
This algorithm is most useful for cases when you don't want to clone any unwanted objects and only focus on few basic types and
some extra types which have strictly defined clone behavior through implementing CloneBehavior.Clone algorithm that is able to clone basic object types as well as simple Collections and Maps@NotNull public static Clone deep()
Clone algorithm that can also clone custom objects through ReflectionCloneBehavior.
Be careful when using this clone algorithm as it will go through all object references and will clone any existing fields.
This algorithm is most useful for cases of cloning complex multi-level structures of objects where defining every clone operation
can be difficult and vulnerable to mistakes.Clone algorithm that can also clone custom objects through ReflectionCloneBehavior@NotNull public static Clone reflective()
Clone algorithm similar to deep() but also allows non-Cloneable objects to be cloned.
Be careful when using this clone algorithm as it will go through all object references and will clone any existing fields.
Just like deep() clone algorithm this one is most useful for cloning complex multi-level structures of objects while also
honoring base Object.clone() API while going through the structure of objects.Clone algorithm similar to deep() that also uses base Object.clone() APICopyright © 2020. All rights reserved.