It is recommended and sometimes necessary, classes that represent values (value classes) to override hashCode()
, equals()
[and optionally
Posting my comment as an answer by request: Commonclipse, an Eclipse plugin that facilitates the use of Apache Commons, does what you want to do.
Caveat: I have no recent experience with this plugin, which is why I originally posted as a comment, and not as an answer.
In the eclipse preferences (Window>Preferences) go to Java > Editor > Templates.
In there you can create a teplate with name:hashcode context:java description:Create a hashcode method. The Pattern should contain something like this:
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
Save and return to your java class. Type the name (hashcode) and press ctrl enter. You can then select your template from the drop down list.
Do the same for each method you want. You could also create a template that combines everything together as well.