Skip to content

Instantly share code, notes, and snippets.

@s4nchez
Created July 28, 2011 14:41
Show Gist options
  • Save s4nchez/1111657 to your computer and use it in GitHub Desktop.
Save s4nchez/1111657 to your computer and use it in GitHub Desktop.
IntelliJ IDEA Live Template for equals() and hashCode() using apache commons
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
final $CLASS$ rhs = ($CLASS$) obj;
return new EqualsBuilder()
.append(object, rhs.object)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(13, 17)
.append(object)
.toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append(object)
.toString();
}
@legolas
Copy link

legolas commented Nov 16, 2017

Nice!
Is it possible to generate random values for the HashCodeBuilder? See Apache commons javadocs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment