本文整理了Java中java.lang.Object.hashCode()
方法的一些代码示例,展示了Object.hashCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Object.hashCode()
方法的具体详情如下:
包路径:java.lang.Object
类名称:Object
方法名:hashCode
暂无
代码示例来源:origin: ReactiveX/RxJava
/**
* 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;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public int hashCode() {
Object o = value;
return o != null ? o.hashCode() : 0;
}
代码示例来源:origin: google/guava
/** 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;
}
代码示例来源:origin: google/guava
/** 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;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public int hashCode() {
return e.hashCode();
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
return SequentialFunnel.class.hashCode() ^ elementFunnel.hashCode();
}
}
代码示例来源:origin: square/retrofit
@Override public int hashCode() {
return Arrays.hashCode(typeArguments)
^ rawType.hashCode()
^ (ownerType != null ? ownerType.hashCode() : 0);
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
return (ownerType == null ? 0 : ownerType.hashCode())
^ argumentsList.hashCode()
^ rawType.hashCode();
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: ReactiveX/RxJava
@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;
}
代码示例来源:origin: square/okhttp
@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;
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
K k = getKey();
V v = getValue();
return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
K k = getKey();
V v = getValue();
return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
return i.hashCode();
}
}
代码示例来源:origin: google/guava
@Override
public Integer apply(Object o) {
return (o == null) ? 0 : o.hashCode();
}
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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();
}
代码示例来源:origin: google/guava
@CollectionSize.Require(ONE)
public void testHashCode_size1() {
assertEquals("multiset has incorrect hash code", 1 ^ e0().hashCode(), getMultiset().hashCode());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void errorNotificationCompare() {
TestException ex = new TestException();
Object n1 = NotificationLite.error(ex);
assertEquals(ex.hashCode(), n1.hashCode());
assertFalse(n1.equals(NotificationLite.complete()));
}
}
内容来源于网络,如有侵权,请联系作者删除!