LangUtils { public static int hashCode(final int seed, final int hashcode) { return seed * HASH_OFFSET + hashcode; } private  LangUtils(); static int hashCode(final int seed, final int hashcode); static int hashCode(final int seed, final boolean b); static int hashCode(final int seed, final Object obj); static boolean equals(final Object obj1, final Object obj2); static boolean equals(final Object[] a1, final Object[] a2); static final int HASH_SEED; static final int HASH_OFFSET; }
@Test public void testBasicHash() { final Integer i = Integer.valueOf(1234); final int h1 = LangUtils.hashCode(LangUtils.HASH_SEED, i.hashCode()); final int h2 = LangUtils.hashCode(LangUtils.HASH_SEED, i); Assert.assertTrue(h1 == h2); }
@Test public void testNullObjectHash() { final int h1 = LangUtils.hashCode(LangUtils.HASH_SEED, null); final int h2 = LangUtils.hashCode(LangUtils.HASH_SEED, 0); Assert.assertTrue(h1 == h2); }
@Test public void testBooleanHash() { final int h1 = LangUtils.hashCode(LangUtils.HASH_SEED, true); final int h2 = LangUtils.hashCode(LangUtils.HASH_SEED, false); final int h3 = LangUtils.hashCode(LangUtils.HASH_SEED, true); final int h4 = LangUtils.hashCode(LangUtils.HASH_SEED, false); Assert.assertTrue(h1 != h2); Assert.assertTrue(h1 == h3); Assert.assertTrue(h2 == h4); }