@@ -0,0 +1,1970 @@
+package net.acomputerdog.core;%0A%0Aimport java.lang.reflect.Array;%0A%0A/**%0A * Simple HashCode generator, based on code by Joshua Bloch.  Use like:%0A * public int hashCode() %7B%0A * int result = HashCode.SEED;%0A * result = HashCode.hash(result, field_a);%0A * result = HashCode.hash(result, field_b);%0A * result = HashCode.hash(result, field_c);%0A * result = HashCode.hash(result, field_d);%0A * result = HashCode.hash(result, field_e);%0A * result = HashCode.hash(result, field_f);%0A * return result;%0A * %7D%0A */%0Apublic class Hash %7B%0A    private static final int PRIME = 37;%0A    public static final int SEED = 19;%0A%0A    public static int hash(int seed, boolean val) %7B%0A        return firstTerm(seed) + (val ? 1 : 0);%0A    %7D%0A%0A    public static int hash(int seed, char val) %7B%0A        return firstTerm(seed) + (int) val;%0A    %7D%0A%0A    public static int hash(int seed, long val) %7B%0A        return firstTerm(seed) + (int) (val %5E (val %3E%3E%3E 32));%0A    %7D%0A%0A    public static int hash(int seed, float val) %7B%0A        return hash(seed, Float.floatToIntBits(val));%0A    %7D%0A%0A    public static int hash(int seed, double val) %7B%0A        return hash(seed, Double.doubleToLongBits(val));%0A    %7D%0A%0A    public static int hash(int seed, int val) %7B%0A        return firstTerm(seed) + val;%0A    %7D%0A%0A    public static int hash(int seed, Object obj) %7B%0A        int result = seed;%0A        if (obj == null) %7B%0A            result = hash(result, 0);%0A        %7D else if (!isArray(obj)) %7B%0A            result = hash(result, obj.hashCode());%0A        %7D else %7B%0A            int length = Array.getLength(obj);%0A            for (int idx = 0; idx %3C length; ++idx) %7B%0A                Object item = Array.get(obj, idx);%0A                if (!(item == obj)) %7B%0A                    result = hash(result, item);%0A                %7D%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static int firstTerm(int seed) %7B%0A        return PRIME * seed;%0A    %7D%0A%0A    private static boolean isArray(Object obj) %7B%0A        return obj.getClass().isArray();%0A    %7D%0A%7D%0A

Add Hash