KaCopy uses:
- concepts of Deep cloning library and Objenesis library for user friendly usage
- platform specific reflection API for high effectiveness.
Cloning means creating a new object from an already presented object and copying all data of object to that new object.
Deep copy is creating a new object and then copying the non-static fields of the current object to the new object. If a field is a value type, a bit by bit copy of the field is performed. If a field is a reference type, a new copy of the referred object is performed. A deep copy of an object is a new object with entirely new instance variables, it does not share objects with the old.
ru.siksmfp.kacopy.api.KaCopier is the main api class of KaCopy. So, you need just create instance of KaCopier and use all functionality of framework
KaCopier copier = new KaCopier();
KaCopy has next public elements
- CopierSettings is the property class for storing additional settings. You could use it if extra settings is needed. For example next instruction allows clone anonymous parent of class.
copier.settings.cloneAnonymousParent(true);
-
T deepCopy(T object) is the method for deep object's cloning. It returns new instance of object with the same content as original has.
-
T shallowCopy(T object) is the method for shallow copying. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied
<dependency>
<groupId>ru.siksmfp</groupId>
<artifactId>KaCopy</artifactId>
<version>0.0.9</version>
</dependency>
compile 'ru.siksmfp:KaCopy:0.0.9'
API consists of next elements
CopierSettings is the class contains optional setting for KaCopy class
IDeepCloner is the interface describes deep cloners - instrument for overriding cloning of adjusted classed. So, you can implement your clone-logic for specific classes.
IFastCloner is the interface for fast cloners overriding. You can implement specific logic for fast cloning specific classes
Immutable is a annotation for marking class which doesn't have needs for copying
KaCopier is the main class for full functional providing
All major versions (x.*.* ) are backward compatible. Minor versions (*.x.y) contain only bug fixing and no api changes
List<Integer> integerList = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> integerListClone = kaCopier.deepCopy(integerList);
integerListClone
is the full clone of integerList