CompareToBuilder,EqualsBuilder,ToStringBuilder
, , 。
import org.apache.commons.lang.builder.CompareToBuilder
import org.apache.commons.lang.builder.EqualsBuilder
import org.apache.commons.lang.builder.HashCodeBuilder
import org.apache.commons.lang.builder.ToStringBuilder
class LavaLamp implements Comparable{
@Property model
@Property baseColor
@Property liquidColor
@Property lavaColor
def String toString() {
return new ToStringBuilder(this).
append(this.model).
append(this.baseColor).
append(this.liquidColor).
append(this.lavaColor).
toString()
}
def boolean equals(obj) {
if (!(obj instanceof LavaLamp)) {
return false
}
LavaLamp rhs = (LavaLamp) obj
return new EqualsBuilder().
append(this.model, rhs.model).
append(this.baseColor, rhs.baseColor).
append(this.liquidColor, rhs.liquidColor).
append(this.lavaColor,rhs.lavaColor).isEquals()
}
def int compareTo(obj) {
LavaLamp lmp = (LavaLamp)obj
return new CompareToBuilder().
append(lmp.model, this.model).append(lmp.lavaColor, this.lavaColor).append(lmp.baseColor, this.baseColor).
append(lmp.liquidColor, this.liquidColor).
toComparison()
}
}