Skip to content

tonivade/equalizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Java Helper class to create nice equals methods

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages