List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:Main.java
/** * Returns a hash code value for the object. * * @param obj/*from www.ja v a 2s . c om*/ * the obj * @return the int */ public static int hashCode(final Object obj) { return obj != null ? obj.hashCode() : 0; }
From source file:Main.java
public static int hashCode(Object o) { return o != null ? o.hashCode() : 0; }
From source file:Main.java
/** * Same hash function as <code>HashMap#newHash</code> method. *//*from www .j a va 2 s .co m*/ public static int hash(Object obj) { int h = obj.hashCode(); // This function ensures that hashCodes that differ only by // constant multiples at each bit position have a bounded // number of collisions (approximately 8 at default load factor). h ^= (h >>> 20) ^ (h >>> 12); return h ^ (h >>> 7) ^ (h >>> 4); }
From source file:Main.java
/** * Hash code of object.//from www . j a v a 2s . c om * * @param object object * @return hash code or 0 if object is null */ public static int objectHashCode(Object object) { return object == null ? 0 : object.hashCode(); }
From source file:Main.java
public static int getHashCode(Object obj) { return obj != null ? obj.hashCode() : 0; }
From source file:Main.java
/** * Returns a hash code for non-null Object x. * <p/>//from w w w. j av a 2 s. c om * This function ensures that hashCodes that differ only by * constant multiples at each bit position have a bounded * number of collisions. (Doug Lea) * * @param object the object serving as a key * @return the hash code */ public static int hash(Object object) { int h = object.hashCode(); h ^= (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_1) ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_2); return h ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_3) ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_4); }
From source file:Main.java
/** * Returns a 'unique' pseudo random material color for given object * * @param key the key for which the color should be generated * @return the color related to the key/*from w w w. j av a2 s . c om*/ * @link http://stackoverflow.com/a/29549014 */ public static int getMaterialColor(Object key) { return materialColors.get(Math.abs(key.hashCode()) % materialColors.size()); }
From source file:Main.java
static int hashCodeOrZero(Object paramObject) { if (paramObject != null) return paramObject.hashCode(); return 0;/*from w w w .j a v a 2 s .c o m*/ }
From source file:Main.java
/** * Returns a hash code for non-null Object x. * <p/>/*w w w. j a v a 2 s.c o m*/ * This function ensures that hashCodes that differ only by * constant multiples at each bit position have a bounded * number of collisions. (Doug Lea) * * @param object the object serving as a key * @return the hash code */ public static int hash(final Object object) { int h = object.hashCode(); h ^= (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_1) ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_2); return h ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_3) ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_4); }
From source file:Main.java
public static int hashCode(final int seed, final Object obj) { return hashCode(seed, obj != null ? obj.hashCode() : 0); }