1 package annotations.util; 2 3 /*>>> 4 import org.checkerframework.checker.nullness.qual.*; 5 */ 6 7 /** 8 * A simple class to mash a lot of data into a hash code for use in 9 * implementing {@link Object#hashCode}. The mashing algorithm currently is 10 * not very good; the advantage of a {@link Hasher} class is that an 11 * improvement to its mashing algorithm benefits all classes that use it. 12 */ 13 public final class Hasher { 14 /** 15 * The calculated hash code for the data that has been contributed so far. 16 */ 17 public int hash = 0; 18 19 private static final int SHIFT = 5; 20 21 /** 22 * Contributes the data <code>x</code> to the calculation of the hash code. 23 */ 24 public void mash(int x) { 25 hash = ((hash << SHIFT) | (hash >> (32 - SHIFT))) ^ x; 26 } 27 } 28