@Override public int hashCode() { return HashedArray.hashCode(this.key); }
/** * Creates a new instance of the HashedArray class. * * @param array An {@link ArrayView} to wrap. */ public HashedArray(ArrayView array) { super(array.array(), array.arrayOffset(), array.getLength()); this.hashCode = hashCode(array); }
/** * Tests equals() and hashCode(). */ @Test public void testEqualsHashCode() { val data1 = generate(); val data2 = copy(data1); HashedArray prev = null; for (int i = 0; i < data1.size(); i++) { val a1 = new HashedArray(data1.get(i)); val a2 = new HashedArray(data2.get(i)); Assert.assertEquals("Expecting hashCode() to be the same for the same array contents.", a1.hashCode(), a2.hashCode()); Assert.assertTrue("Expecting equals() to return true for the same array contents.", a1.equals(a2) && a2.equals(a1)); if (prev != null) { Assert.assertNotEquals("Expecting hashCode() to be different for different arrays.", prev.hashCode(), a1.hashCode()); Assert.assertFalse("Expecting equals() to return false for different array contents.", prev.equals(a1) || a1.equals(prev)); } prev = a1; } }