/** * Returns the hashCode of a non-null object or zero for a null object. * @param o the object to get the hashCode for. * @return the hashCode */ public static int hashCode(Object o) { return o != null ? o.hashCode() : 0; }
@Override public int hashCode() { Object o = value; return o != null ? o.hashCode() : 0; }
/** An implementation of {@link List#hashCode()}. */ static int hashCodeImpl(List<?> list) { // TODO(lowasser): worth optimizing for RandomAccess? int hashCode = 1; for (Object o : list) { hashCode = 31 * hashCode + (o == null ? 0 : o.hashCode()); hashCode = ~~hashCode; // needed to deal with GWT integer overflow } return hashCode; }
/** An implementation for {@link Set#hashCode()}. */ static int hashCodeImpl(Set<?> s) { int hashCode = 0; for (Object o : s) { hashCode += o != null ? o.hashCode() : 0; hashCode = ~~hashCode; // Needed to deal with unusual integer overflow in GWT. } return hashCode; }
@Override public int hashCode() { return e.hashCode(); }
@Override public int hashCode() { int hashCode = 1; int n = size(); for (int i = 0; i < n; i++) { hashCode = 31 * hashCode + get(i).hashCode(); hashCode = ~~hashCode; // needed to deal with GWT integer overflow } return hashCode; }
@Override public int hashCode() { int h = value != null ? value.hashCode() : 0; h = h * 31 + (int)((time >>> 31) ^ time); h = h * 31 + unit.hashCode(); return h; }
@Override public int hashCode() { int result = 17; result = 31 * result + tlsVersion.hashCode(); result = 31 * result + cipherSuite.hashCode(); result = 31 * result + peerCertificates.hashCode(); result = 31 * result + localCertificates.hashCode(); return result; }
@Override public int hashCode() { return i.hashCode(); } }
@Override public Integer apply(Object o) { return (o == null) ? 0 : o.hashCode(); } }
public void testHashCode() { int expectedHashCode = 1; for (E element : getOrderedElements()) { expectedHashCode = 31 * expectedHashCode + ((element == null) ? 0 : element.hashCode()); } assertEquals( "A List's hashCode() should be computed from those of its elements.", expectedHashCode, getList().hashCode()); }
public void testHashCode() { int expectedHashCode = 0; for (E element : getSampleElements()) { expectedHashCode += ((element == null) ? 0 : element.hashCode()); } assertEquals( "A Set's hashCode() should be the sum of those of its elements.", expectedHashCode, getSet().hashCode()); }
private static void assertEqualWildcardType(WildcardType expected, WildcardType actual) { assertEquals(expected.toString(), actual.toString()); assertEquals(actual.toString(), expected.hashCode(), actual.hashCode()); assertThat(actual.getLowerBounds()) .asList() .containsExactlyElementsIn(asList(expected.getLowerBounds())) .inOrder(); assertThat(actual.getUpperBounds()) .asList() .containsExactlyElementsIn(asList(expected.getUpperBounds())) .inOrder(); }
@CollectionSize.Require(ONE) public void testHashCode_size1() { assertEquals("multiset has incorrect hash code", 1 ^ e0().hashCode(), getMultiset().hashCode()); } }