Equalizer

Java Helper class to create nice equals methods

License

License

GroupId

GroupId

com.github.tonivade
ArtifactId

ArtifactId

equalizer
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Equalizer
Java Helper class to create nice equals methods
Project URL

Project URL

https://github.com/tonivade/equalizer
Source Code Management

Source Code Management

https://github.com/tonivade/equalizer

Download equalizer

How to add to project

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

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
nl.jqno.equalsverifier : equalsverifier jar 1.7.5

Project Modules

There are no modules declared in this project.

Equalizer

Equalizer is a helper class in order to create nice equals method for your java classes.

There are some alternatives like commons-lang, guava or Object.equals, but all have the same problem:

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    Data other = (Data) obj;
    return Objects.equals(this.id, other.id) && Objects.equals(this.value, other.value);
}

There are some boilerplate code you have to include previously to the fields comparison.

Equalizer tries to solve this problem:

@Override
public boolean equals(Object obj) {
    return equalizer(this)
        .append((one, other) -> Objects.equals(one.id, other.id))
        .append((one, other) -> Objects.equals(one.value, other.value))
        .applyTo(obj);
}

Build Status

Versions

Version
0.3.0
0.2.0