|
|
||||||
Evan Summers's Blog
«Chronicles of the Trove: Fixing by Deprefixing |
Main
| A Short Note About Properties And Politics »
Entity EqualsPosted by evanx on June 28, 2007 at 08:01 AM | Comments (0)
Let's look at neatening up those messy equals() and hashCode() methods in our entities.
public class Feed { private int id; private String uri; ... private Comparable[] values() { return new Comparable[] {id, uri}; } public boolean equals(Object object) { if (object instanceof Feed) { Feed feed = (Feed) object; return typeHelper.equals(values(), feed.values()); } return false; } public int hashCode() { return typeHelper.hashCode(values()); } } where we implement a values() method to return an array of our IDs et al for hashCode() and equals(), and utilise a helper class.
Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment | ||||||
|
|