Latte is a deep equality comparison and object cloning library.
Do you want your data to be final
? Do you want to safely broadcast to
different parts of the program?
This usually leads to cloning, which requires writing a copy constructor for
every model class, and overriding equals()
for deep equality.
Latte provides:
- Generic deep cloning that works on every type
- Generic deep equality (value equality) that works on every type
Add Latte
dependency to your build.gradle
file:
dependencies {
compile 'xyz.truenight.latte:latte:1.0.3'
}
or to your pom.xml
if you're using Maven:
<dependency>
<groupId>xyz.truenight.latte</groupId>
<artifactId>latte</artifactId>
<version>1.0.3</version>
<type>pom</type>
</dependency>
Efficient deep cloning that works on objects of any type.
SomeObject object = new SomeObject(param1, param2, param3, param4);
SomeObject clone = Latte.clone(object);
object == clone;
// false
Efficient deep equality that works on objects of any type.
SomeObject clone = Latte.clone(object);
Latte.equal(object, clone);
// true
Use @IgnoreField, @UseAdapter(TypeAdapter.class), @UnorderedCollection
annotations
to customise Latte's behaviour for individual classes:
public class SomeObject {
@IgnoreField(ignoreClone = false) // field will be cloned but won't be compared
private String param1;
private Object param2; // for non-primitive fields, reflective adapter is used
@UseAdapter(CustomAdapter.class) // to use custom adapter that extends TypeAdapter or TypeAdapterFactory
private Object param3;
@UnorderedCollection // element order will be ignored during comparison
private Collection<Object> param4;
private SomeObject() {
}
public SomeObject(String param1, Object param2, Object param3, Collection<Object> param4) {
this.param1 = param1;
this.param2 = param2;
this.param3 = param3;
this.param4 = param4;
}
}