View Javadoc

1   /**
2    * 
3    */
4   package org.millscript.commons.util.maplet;
5   
6   import org.millscript.commons.util.IMap;
7   import org.millscript.commons.util.Maplet;
8   
9   /**
10   * This is a utility class for calculating {@link Maplet} hash codes.
11   * <p>
12   * The {@link IMap#hashCode()} method requires that different {@link IMap}
13   * implementations have the same hash code if they contain they have the same
14   * number of mappings and map the same keys to the same values. As a result we
15   * require that for a given key and value, any implementation of {@link Maplet}
16   * must return the same hash code.
17   * </p>
18   *
19   * @author krogers
20   */
21  public final class MapletUtil {
22  
23      public static final int mapletHashCode( final Object key, final Object value ) {
24          int hash = 865432;
25          hash = 37 * hash + ( key == null ? 0 : key.hashCode() );
26          hash = 37 * hash + ( value == null ? 0 : value.hashCode() );
27          return hash;
28      }
29  
30  }