An open API service indexing awesome lists of open source software.

https://github.com/tonivade/equalizer

Java Helper class to create nice equals methods
https://github.com/tonivade/equalizer

builder equals java

Last synced: about 1 month ago
JSON representation

Java Helper class to create nice equals methods

Awesome Lists containing this project

README

        

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](https://drone.io/github.com/tonivade/equalizer/status.png)](https://drone.io/github.com/tonivade/equalizer/latest)