1 3 package jodd.util; 4 5 18 public class HashCodeUtil { 19 20 24 public static final int SEED = 173; 25 26 public static final int PRIME = 37; 27 28 31 public static int hash(int seed, boolean aBoolean) { 32 return (PRIME * seed) + (aBoolean ? 1 : 0); 33 } 34 35 38 public static int hash(int seed, char aChar) { 39 return (PRIME * seed) + (int) aChar; 40 } 41 42 45 public static int hash(int seed, int aInt) { 46 return (PRIME * seed) + aInt; 47 } 48 49 52 public static int hash(int seed, long aLong) { 53 return (PRIME * seed) + (int) (aLong ^ (aLong >>> 32)); 54 } 55 56 59 public static int hash(int seed, float aFloat) { 60 return hash(seed, Float.floatToIntBits(aFloat)); 61 } 62 63 66 public static int hash(int seed, double aDouble) { 67 return hash(seed, Double.doubleToLongBits(aDouble)); 68 } 69 70 76 public static int hash(int seed, Object aObject) { 77 int result = seed; 78 if (aObject == null) { 79 result = hash(result, 0); 80 } else if (aObject.getClass().isArray() == false) { 81 result = hash(result, aObject.hashCode()); 82 } else { 83 Object [] objects = (Object []) aObject; 84 int length = objects.length; 85 for (int idx = 0; idx < length; ++idx) { 86 result = hash(result, objects[idx]); 87 } 88 } 89 return result; 90 } 91 92 } | Popular Tags |