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
- Host: GitHub
- URL: https://github.com/tonivade/equalizer
- Owner: tonivade
- License: mit
- Created: 2015-10-16T22:21:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-22T20:08:22.000Z (almost 7 years ago)
- Last Synced: 2025-02-09T23:49:20.182Z (3 months ago)
- Topics: builder, equals, java
- Language: Java
- Size: 67.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);
}[](https://drone.io/github.com/tonivade/equalizer/latest)