Jakarta commons-lang provides a convenient way for building consistent equals(Object), toString(), hashCode(), and compareTo(Object) methods. Commons-lang builders are robust and flexible. Probably the most useful builder is the toString() one, which helps you in creating consistent and configurable (through the use of a ToStringStyle object) toString() methods in your project.
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE)
.appendSuper(super.toString())
.append("age", this.age)
.append("isSmoker", this.isSmoker)
.append("name", this.name)
.toString();
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return new HashCodeBuilder(357504959, 1759723435)
.appendSuper(super.hashCode())
.append(this.age)
.append(this.isSmoker)
.append(this.name)
.toHashCode();
}
/**
* @see java.lang.Object#equals(Object)
*/
public boolean equals(Object object) {
if (!(object instanceof Person)) {
return false;
}
Person rhs = (Person) object;
return new EqualsBuilder()
.appendSuper(super.equals(object))
.append(this.age, rhs.age)
.append(this.isSmoker, rhs.isSmoker)
.append(this.name, rhs.name)
.isEquals();
}