Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please find below simple instructions how to create hashCode, equals and toString methods using Apache commons builders.</p> <h2>hashCode</h2> <ol> <li>If two objects are equal according to the equals() method, they must have the same hashCode() value </li> <li>It is possible that two distinct objects could have the same hashCode(). </li> <li>Please use unique Business ID for the hashCode creation (it is mean that you should use some unique property that represent business entity, for example, name) </li> <li>Hibernate Entity: please do NOT use Hibernate id for the hashCode creation </li> <li><p>You may call for .appendSuper(super.hashCode()) in case your class is subclass </p> <pre> @Override public int hashCode() { return new HashCodeBuilder() .append(getName()) .toHashCode(); } </pre></li> </ol> <h2>equals</h2> <ol> <li>Please compare Business ID (it is mean that you should use some unique property that represent business entity, for example, name) </li> <li>Hibernate Entity: please do NOT compare Hibernate id </li> <li>Hibernate Entity: use getters when you access the other object field to let to Hibernate to load the property </li> <li><p>You may call for .appendSuper(super.equals(other)) in case your class is subclass </p> <pre> @Override public boolean equals(final Object other) { if (this == other) return true; if (!(other instanceof TreeNode)) return false; TreeNode castOther = (TreeNode) other; return new EqualsBuilder() .append(getName(), castOther.getName()) .isEquals(); } </pre></li> </ol> <h2>toString</h2> <ol> <li>Please ensure that toString will not throw NullPointerException. </li> <li><p>You may call for .appendSuper(super.toString()) in case your class is subclass </p> <pre> @Override public String toString() { return new ToStringBuilder(this) .append("Name", getName()) .toString(); } </pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload