Class HashCodeGenerator

java.lang.Object
com.helger.commons.hashcode.HashCodeGenerator
All Implemented Interfaces:
IHashCodeGenerator, IAppendable<IHashCodeGenerator>

@NotThreadSafe public final class HashCodeGenerator extends Object implements IHashCodeGenerator
A small hash code creation class based on the article found in the net. See this article for details.
After calling append(Object) for all objects use getHashCode() to retrieve the calculated hash code. Once the hash code was calculated no modifications are allowed.

A real world example for a final class derived from Object or a base class looks like this:

 @Override
 public int hashCode ()
 {
   return new HashCodeGenerator (this).append (member1).append (member2).getHashCode ();
 }
 

For a derived class, the typical code looks like this, assuming the base class also uses HashCodeGenerator:

 @Override
 public int hashCode ()
 {
   return HashCodeGenerator.getDerived (super.hashCode ()).append (member3).append (member4).getHashCode ();
 }
 
Author:
Philip Helger