Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Guava's Objects class with java.util.Objects #1786

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.google.inject.spi.Elements.withTrustedSource;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.ConfigurationException;
Expand All @@ -39,6 +38,7 @@
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.aopalliance.intercept.MethodInterceptor;

Expand Down Expand Up @@ -260,15 +260,15 @@ public boolean equals(Object obj) {
ConstructorBindingImpl<?> o = (ConstructorBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(constructorInjectionPoint, o.constructorInjectionPoint);
&& Objects.equals(constructorInjectionPoint, o.constructorInjectionPoint);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping(), constructorInjectionPoint);
return Objects.hash(getKey(), getScoping(), constructorInjectionPoint);
}

private static class Factory<T> implements InternalFactory<T> {
Expand Down
8 changes: 4 additions & 4 deletions core/src/com/google/inject/internal/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.inject.internal;

import com.google.common.base.Objects;
import com.google.inject.Binding;
import com.google.inject.Injector;
import com.google.inject.Scope;
Expand All @@ -34,6 +33,7 @@
import com.google.inject.spi.ProviderKeyBinding;
import com.google.inject.spi.UntargettedBinding;
import java.lang.annotation.Annotation;
import java.util.Objects;

/**
* Visits bindings to return a {@code IndexedBinding} that can be used to emulate the binding
Expand Down Expand Up @@ -83,16 +83,16 @@ public boolean equals(Object obj) {
}
IndexedBinding o = (IndexedBinding) obj;
return type == o.type
&& Objects.equal(scope, o.scope)
&& Objects.equals(scope, o.scope)
&& typeLiteral.equals(o.typeLiteral)
&& annotationType == o.annotationType
&& annotationName.equals(o.annotationName)
&& Objects.equal(extraEquality, o.extraEquality);
&& Objects.equals(extraEquality, o.extraEquality);
}

@Override
public int hashCode() {
return Objects.hashCode(
return Objects.hash(
type, scope, typeLiteral, annotationType, annotationName, extraEquality);
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/com/google/inject/internal/InjectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.inject.internal.Annotations.findScopeAnnotation;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -60,6 +59,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;

Expand Down Expand Up @@ -430,15 +430,15 @@ public boolean equals(Object obj) {
SyntheticProviderBindingImpl<?> o = (SyntheticProviderBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(providedBinding, o.providedBinding);
&& Objects.equals(providedBinding, o.providedBinding);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping(), providedBinding);
return Objects.hash(getKey(), getScoping(), providedBinding);
}
}

Expand Down Expand Up @@ -576,15 +576,15 @@ public boolean equals(Object obj) {
ConvertedConstantBindingImpl<?> o = (ConvertedConstantBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(value, o.value);
&& Objects.equals(value, o.value);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping(), value);
return Objects.hash(getKey(), getScoping(), value);
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/com/google/inject/internal/InstanceBindingImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.inject.spi.Elements.withTrustedSource;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Key;
Expand All @@ -29,6 +28,7 @@
import com.google.inject.spi.HasDependencies;
import com.google.inject.spi.InjectionPoint;
import com.google.inject.spi.InstanceBinding;
import java.util.Objects;
import java.util.Set;

final class InstanceBindingImpl<T> extends BindingImpl<T> implements InstanceBinding<T> {
Expand Down Expand Up @@ -108,14 +108,14 @@ public boolean equals(Object obj) {
InstanceBindingImpl<?> o = (InstanceBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(instance, o.instance);
&& Objects.equals(instance, o.instance);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping());
return Objects.hash(getKey(), getScoping());
}
}
6 changes: 3 additions & 3 deletions core/src/com/google/inject/internal/LinkedBindingImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import static com.google.inject.spi.Elements.withTrustedSource;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.spi.BindingTargetVisitor;
import com.google.inject.spi.Dependency;
import com.google.inject.spi.HasDependencies;
import com.google.inject.spi.LinkedKeyBinding;
import java.util.Objects;
import java.util.Set;

final class LinkedBindingImpl<T> extends BindingImpl<T>
Expand Down Expand Up @@ -101,14 +101,14 @@ public boolean equals(Object obj) {
LinkedBindingImpl<?> o = (LinkedBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(targetKey, o.targetKey);
&& Objects.equals(targetKey, o.targetKey);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping(), targetKey);
return Objects.hash(getKey(), getScoping(), targetKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import static com.google.inject.spi.Elements.withTrustedSource;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.spi.BindingTargetVisitor;
import com.google.inject.spi.Dependency;
import com.google.inject.spi.HasDependencies;
import com.google.inject.spi.ProviderKeyBinding;
import java.util.Objects;
import java.util.Set;


final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
implements ProviderKeyBinding<T>, HasDependencies, DelayedInitialize {

Expand Down Expand Up @@ -138,14 +139,14 @@ public boolean equals(Object obj) {
LinkedProviderBindingImpl<?> o = (LinkedProviderBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(providerKey, o.providerKey);
&& Objects.equals(providerKey, o.providerKey);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping(), providerKey);
return Objects.hash(getKey(), getScoping(), providerKey);
}
}
8 changes: 4 additions & 4 deletions core/src/com/google/inject/internal/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static java.util.stream.Collectors.joining;

import com.google.common.base.Equivalence;
import com.google.common.base.Objects;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
Expand All @@ -33,6 +32,7 @@
import java.util.Formatter;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/** Utility methods for {@link Message} objects */
Expand All @@ -49,7 +49,7 @@ static Message mergeSources(List<Object> sources, Message message) {
// merging errors.
if (!sources.isEmpty()
&& !messageSources.isEmpty()
&& Objects.equal(messageSources.get(0), sources.get(sources.size() - 1))) {
&& Objects.equals(messageSources.get(0), sources.get(sources.size() - 1))) {
messageSources = messageSources.subList(1, messageSources.size());
}
return message.withSource(
Expand Down Expand Up @@ -261,14 +261,14 @@ private static final class ThrowableEquivalence extends Equivalence<Throwable> {
@Override
protected boolean doEquivalent(Throwable a, Throwable b) {
return a.getClass().equals(b.getClass())
&& Objects.equal(a.getMessage(), b.getMessage())
&& Objects.equals(a.getMessage(), b.getMessage())
&& Arrays.equals(a.getStackTrace(), b.getStackTrace())
&& equivalent(a.getCause(), b.getCause());
}

@Override
protected int doHash(Throwable t) {
return Objects.hashCode(t.getClass().hashCode(), t.getMessage(), hash(t.getCause()));
return Objects.hash(t.getClass().hashCode(), t.getMessage(), hash(t.getCause()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.google.inject.internal;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.inject.TypeLiteral;
import com.google.inject.spi.ErrorDetail;
Expand All @@ -9,6 +8,7 @@
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;
import java.util.Objects;

/** Error reported when Guice can't find an useable constructor to create objects. */
final class MissingConstructorError extends InternalErrorDetail<MissingConstructorError> {
Expand All @@ -29,8 +29,8 @@ final class MissingConstructorError extends InternalErrorDetail<MissingConstruct
public boolean isMergeable(ErrorDetail<?> other) {
if (other instanceof MissingConstructorError) {
MissingConstructorError otherMissing = (MissingConstructorError) other;
return Objects.equal(type, otherMissing.type)
&& Objects.equal(atInjectRequired, otherMissing.atInjectRequired);
return Objects.equals(type, otherMissing.type)
&& Objects.equals(atInjectRequired, otherMissing.atInjectRequired);
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/google/inject/internal/MoreTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
import com.google.inject.ConfigurationException;
import com.google.inject.Key;
Expand All @@ -35,6 +34,7 @@
import java.lang.reflect.WildcardType;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Objects;

/**
* Static methods for working with types that we aren't publishing in the public {@code Types} API.
Expand Down Expand Up @@ -224,7 +224,7 @@ public static boolean equals(Type a, Type b) {

ParameterizedType pa = (ParameterizedType) a;
ParameterizedType pb = (ParameterizedType) b;
return Objects.equal(pa.getOwnerType(), pb.getOwnerType())
return Objects.equals(pa.getOwnerType(), pb.getOwnerType())
&& pa.getRawType().equals(pb.getRawType())
&& Arrays.equals(getSharedTypeArguments(pa), getSharedTypeArguments(pb));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.inject.spi.Elements.withTrustedSource;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Key;
Expand All @@ -32,6 +31,7 @@
import com.google.inject.spi.ProviderInstanceBinding;
import com.google.inject.spi.ProviderWithExtensionVisitor;
import com.google.inject.util.Providers;
import java.util.Objects;
import java.util.Set;

class ProviderInstanceBindingImpl<T> extends BindingImpl<T> implements ProviderInstanceBinding<T> {
Expand Down Expand Up @@ -73,6 +73,7 @@ public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
}
}

@Override
public Provider<? extends T> getProviderInstance() {
return Providers.guicify(providerInstance);
}
Expand Down Expand Up @@ -131,14 +132,14 @@ public boolean equals(Object obj) {
ProviderInstanceBindingImpl<?> o = (ProviderInstanceBindingImpl<?>) obj;
return getKey().equals(o.getKey())
&& getScoping().equals(o.getScoping())
&& Objects.equal(providerInstance, o.providerInstance);
&& Objects.equals(providerInstance, o.providerInstance);
} else {
return false;
}
}

@Override
public int hashCode() {
return Objects.hashCode(getKey(), getScoping());
return Objects.hash(getKey(), getScoping());
}
}
6 changes: 3 additions & 3 deletions core/src/com/google/inject/internal/ProviderMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.inject.internal;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Exposed;
Expand All @@ -36,6 +35,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;

Expand Down Expand Up @@ -218,7 +218,7 @@ public boolean equals(Object obj) {
if (obj instanceof ProviderMethod) {
ProviderMethod<?> o = (ProviderMethod<?>) obj;
return method.equals(o.method)
&& Objects.equal(instance, o.instance)
&& Objects.equals(instance, o.instance)
&& annotation.equals(o.annotation);
} else {
return false;
Expand All @@ -230,7 +230,7 @@ public int hashCode() {
// Avoid calling hashCode on 'instance', which is a user-object
// that might not be expecting it.
// (We need to call equals, so we do. But we can avoid hashCode.)
return Objects.hashCode(method, annotation);
return Objects.hash(method, annotation);
}


Expand Down
Loading
Loading