/** * Compares two potentially null objects with each other using Object.equals. * @param o1 the first object * @param o2 the second object * @return the comparison result */ public static boolean equals(Object o1, Object o2) { // NOPMD return o1 == o2 || (o1 != null && o1.equals(o2)); }
@Override public boolean equals(Object other) { if (other instanceof InternerFunction) { InternerFunction<?> that = (InternerFunction<?>) other; return interner.equals(that.interner); } return false; } }
private static int indexOf(Object[] array, Object toFind) { for (int i = 0; i < array.length; i++) { if (toFind.equals(array[i])) return i; } throw new NoSuchElementException(); }
@Override public boolean equals(@Nullable Object other) { if (!(other instanceof Handshake)) return false; Handshake that = (Handshake) other; return tlsVersion.equals(that.tlsVersion) && cipherSuite.equals(that.cipherSuite) && peerCertificates.equals(that.peerCertificates) && localCertificates.equals(that.localCertificates); }
@Override public boolean equals(@Nullable Object object) { if (object instanceof Present) { Present<?> other = (Present<?>) object; return reference.equals(other.reference); } return false; }
boolean equalsNonHost(Address that) { return this.dns.equals(that.dns) && this.proxyAuthenticator.equals(that.proxyAuthenticator) && this.protocols.equals(that.protocols) && this.connectionSpecs.equals(that.connectionSpecs) && this.proxySelector.equals(that.proxySelector) && Objects.equals(this.proxy, that.proxy) && Objects.equals(this.sslSocketFactory, that.sslSocketFactory) && Objects.equals(this.hostnameVerifier, that.hostnameVerifier) && Objects.equals(this.certificatePinner, that.certificatePinner) && this.url().port() == that.url().port(); }
@Override public boolean equals(Object obj) { if (obj instanceof DummyHandler) { DummyHandler that = (DummyHandler) obj; return identity().equals(that.identity()); } else { return false; } }
static <K, V> ImmutableSortedMap<K, V> emptyMap(Comparator<? super K> comparator) { if (Ordering.natural().equals(comparator)) { return of(); } else { return new ImmutableSortedMap<>( ImmutableSortedSet.emptySet(comparator), ImmutableList.<V>of()); } }
@Override public boolean equals(@Nullable Object obj) { if (obj instanceof HasAnInterface) { HasAnInterface that = (HasAnInterface) obj; return i.equals(that.i); } else { return false; } }
@Override public boolean equals(@Nullable Object obj) { // In general getClass().isInstance() is bad for equals. // But here we fully control the subclasses to ensure symmetry. if (getClass().isInstance(obj)) { Wrapper that = (Wrapper) obj; return wrapped.equals(that.wrapped); } return false; }
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) @CollectionSize.Require(absent = ZERO) public void testSetValueWithNullValuesPresent() { for (Entry<K, V> entry : getMap().entrySet()) { if (entry.getKey().equals(k0())) { assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(null)); break; } } expectReplacement(entry(k0(), (V) null)); }
@Override public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onNext(a[0], 2, wip, error); } ts.onNext(t); }
@Override public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onNext(a[0], 2, wip, error); } to.onNext(t); }
@Override public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onComplete(a[0], wip, error); } ts.onNext(t); }
@Override public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onComplete(a[0], wip, error); } to.onNext(t); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testSetValue() { for (Entry<K, V> entry : getMap().entrySet()) { if (entry.getKey().equals(k0())) { assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3())); break; } } expectReplacement(entry(k0(), v3())); }
@GwtIncompatible // ImmutableSortedSet.indexOf // TODO(cpovirk): consider manual binary search under GWT to preserve O(log N) lookup @Override public int indexOf(@Nullable Object target) { int index = delegateCollection().indexOf(target); // TODO(kevinb): reconsider if it's really worth making feeble attempts at // sanity for inconsistent comparators. // The equals() check is needed when the comparator isn't compatible with // equals(). return (index >= 0 && get(index).equals(target)) ? index : -1; }
@Override public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onError(a[0], new TestException(), wip, error); } ts.onNext(t); }
@Override public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onError(a[0], new TestException(), wip, error); } to.onNext(t); }
@Test public void errorNotificationCompare() { TestException ex = new TestException(); Object n1 = NotificationLite.error(ex); assertEquals(ex.hashCode(), n1.hashCode()); assertFalse(n1.equals(NotificationLite.complete())); } }