Skip to content
/ KaCopy Public

KaCopy is the compact high effective library for deep cloning java objects

License

Notifications You must be signed in to change notification settings

parkito/KaCopy

Repository files navigation



KaCopy is the compact high effective library for deep cloning java objects

KaCopy uses:

Table of contents

Theory

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.

Common usage

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

Installation

Maven

<dependency>
    <groupId>ru.siksmfp</groupId>
    <artifactId>KaCopy</artifactId>
    <version>0.0.9</version>
</dependency>

Gradle

compile 'ru.siksmfp:KaCopy:0.0.9'

API

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

Versions

All major versions (x.*.* ) are backward compatible. Minor versions (*.x.y) contain only bug fixing and no api changes

Examples

List<Integer> integerList = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> integerListClone = kaCopier.deepCopy(integerList);

integerListClone is the full clone of integerList

License

MIT

About

KaCopy is the compact high effective library for deep cloning java objects

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages