Entity Comparator

A simple Comparator which can be configured to compare only certain properties of an object.

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

com.github.carlopantaleo
ArtifactId

ArtifactId

entity-comparator
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Entity Comparator
A simple Comparator which can be configured to compare only certain properties of an object.
Project URL

Project URL

https://github.com/carlopantaleo/entity-comparator
Source Code Management

Source Code Management

https://github.com/carlopantaleo/entity-comparator

Download entity-comparator

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.carlopantaleo/entity-comparator/ -->
<dependency>
    <groupId>com.github.carlopantaleo</groupId>
    <artifactId>entity-comparator</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.carlopantaleo/entity-comparator/
implementation 'com.github.carlopantaleo:entity-comparator:1.0.1'
// https://jarcasting.com/artifacts/com.github.carlopantaleo/entity-comparator/
implementation ("com.github.carlopantaleo:entity-comparator:1.0.1")
'com.github.carlopantaleo:entity-comparator:jar:1.0.1'
<dependency org="com.github.carlopantaleo" name="entity-comparator" rev="1.0.1">
  <artifact name="entity-comparator" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.carlopantaleo', module='entity-comparator', version='1.0.1')
)
libraryDependencies += "com.github.carlopantaleo" % "entity-comparator" % "1.0.1"
[com.github.carlopantaleo/entity-comparator "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
com.google.guava : guava jar 25.0-jre

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Entity Comparator

Build Status codecov jitpack

A simple Comparator which lets you compare objects by dynamically choosing the properties to compare.

Please note: if you are using Java 8 or later, please consider the standard Comparator class.

Get it

Add the latest version dependency to your POM:

<dependency>
    <groupId>com.github.carlopantaleo</groupId>
    <artifactId>entity-comparator</artifactId>
    <version>1.0.1</version>
</dependency>

Example usage

public class Example {
	private String field1;
	private String field2;
	
	// Getters and setters
	// ...
}

Example ex1 = new Example();
ex1.setField1("a");
ex1.setField2("a");

Example ex2 = new Example();
ex2.setField1("a");
ex2.setField2("b");

EntityComparator<Example> ec = new EntityComparator<>(Example.class);
ec.addComparingProperty("field1");
assertEquals(0, ec.compare(ex1, ex2));
ec.addComparingProperty("field2");
assertEquals(-1, ec.compare(ex1, ex2));

Versions

Version
1.0.1