Skip to content

Instantly share code, notes, and snippets.

@phisad
Last active March 13, 2019 08:45
Show Gist options
  • Save phisad/e85cf688821dc6249f3a06520d590861 to your computer and use it in GitHub Desktop.
Save phisad/e85cf688821dc6249f3a06520d590861 to your computer and use it in GitHub Desktop.
Eclipse code template for equals hash toString with apache commons lang3
${:import(org.apache.commons.lang3.builder.EqualsBuilder,
org.apache.commons.lang3.builder.HashCodeBuilder,
org.apache.commons.lang3.builder.ToStringBuilder,
org.apache.commons.lang3.builder.ToStringStyle)}
@Override
public boolean equals(Object aObj) {
if(!(aObj instanceof ${enclosing_type})) {
return false;
}
${enclosing_type} tmpOther = (${enclosing_type}) aObj;
return new EqualsBuilder().append(${cursor}${field}, tmpOther.${field}).isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(${field}).toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(ToStringStyle.SHORT_PREFIX_STYLE).append(${field}).toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment