Use java.util.Objects instead of com.google.common.base.Objects

Use
  java.util.Objects.equals(...)
instead of
  com.google.common.base.Objects.equal(...)
and
  java.util.Objects.hash(...)
instead of
  com.google.common.base.Objects.hashCode(...)
.

The JavaDoc of both methods in com.google.common.base.Objects says
that they should be treated as deprecated and that the corresponding
Java 7 methods in java.util.Objects should be used instead.

Change-Id: I55d53cde42a7eecfa310e1ae4038d2ee4d111c4b
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2014-11-17 14:26:41 +01:00 committed by David Pursehouse
parent b3a96b5ac5
commit 3efed75534
14 changed files with 42 additions and 41 deletions

View File

@ -14,9 +14,8 @@
package com.google.gerrit.common;
import com.google.common.base.Objects;
import java.io.File;
import java.util.Objects;
public class PluginData {
public final String name;
@ -33,14 +32,14 @@ public class PluginData {
public boolean equals(Object obj) {
if (obj instanceof PluginData) {
PluginData o = (PluginData) obj;
return Objects.equal(name, o.name) && Objects.equal(version, o.version)
&& Objects.equal(pluginFile, o.pluginFile);
return Objects.equals(name, o.name) && Objects.equals(version, o.version)
&& Objects.equals(pluginFile, o.pluginFile);
}
return super.equals(obj);
}
@Override
public int hashCode() {
return Objects.hashCode(name, version, pluginFile);
return Objects.hash(name, version, pluginFile);
}
}

View File

@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.gerrit.server.change.ChangeKind.NO_CODE_CHANGE;
import static com.google.gerrit.server.change.ChangeKind.TRIVIAL_REBASE;
import com.google.common.base.Objects;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
@ -47,6 +46,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.NavigableSet;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeMap;
@ -156,7 +156,7 @@ public class ApprovalCopier {
LabelType type = project.getLabelTypes().byLabel(psa.getLabelId());
if (type == null) {
return false;
} else if (Objects.equal(n, previous(allPsIds, psId.get())) && (
} else if (Objects.equals(n, previous(allPsIds, psId.get())) && (
type.isCopyMinScore() && type.isMaxNegative(psa)
|| type.isCopyMaxScore() && type.isMaxPositive(psa))) {
// Copy min/max score only from the immediately preceding patch set (which

View File

@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
@ -57,6 +56,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
@ -91,7 +91,7 @@ public class ApprovalsUtil {
return Iterables.filter(psas, new Predicate<PatchSetApproval>() {
@Override
public boolean apply(PatchSetApproval input) {
return Objects.equal(input.getAccountId(), accountId);
return Objects.equals(input.getAccountId(), accountId);
}
});
}

View File

@ -14,9 +14,10 @@
package com.google.gerrit.server.auth;
import com.google.common.base.Objects;
import com.google.gerrit.common.Nullable;
import java.util.Objects;
/**
* Defines an abstract request for user authentication to Gerrit.
*/
@ -50,7 +51,7 @@ public abstract class AuthRequest {
}
public void checkPassword(String pwd) throws AuthException {
if (!Objects.equal(getPassword(), pwd)) {
if (!Objects.equals(getPassword(), pwd)) {
throw new InvalidCredentialsException();
}
}

View File

@ -19,7 +19,6 @@ import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.Weigher;
@ -53,6 +52,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
public class ChangeKindCacheImpl implements ChangeKindCache {
@ -156,16 +156,16 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
public boolean equals(Object o) {
if (o instanceof Key) {
Key k = (Key) o;
return Objects.equal(prior, k.prior)
&& Objects.equal(next, k.next)
&& Objects.equal(strategyName, k.strategyName);
return Objects.equals(prior, k.prior)
&& Objects.equals(next, k.next)
&& Objects.equals(strategyName, k.strategyName);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(prior, next, strategyName);
return Objects.hash(prior, next, strategyName);
}
private void writeObject(ObjectOutputStream out) throws IOException {
@ -185,7 +185,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
private static class Loader extends CacheLoader<Key, ChangeKind> {
@Override
public ChangeKind load(Key key) throws IOException {
if (Objects.equal(key.prior, key.next)) {
if (Objects.equals(key.prior, key.next)) {
return ChangeKind.NO_CODE_CHANGE;
}

View File

@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@ -38,6 +37,7 @@ import com.google.inject.Singleton;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
/**
* Normalizes votes on labels according to project config and permissions.
@ -85,16 +85,16 @@ public class LabelNormalizer {
public boolean equals(Object o) {
if (o instanceof Result) {
Result r = (Result) o;
return Objects.equal(unchanged, r.unchanged)
&& Objects.equal(updated, r.updated)
&& Objects.equal(deleted, r.deleted);
return Objects.equals(unchanged, r.unchanged)
&& Objects.equals(updated, r.updated)
&& Objects.equals(deleted, r.deleted);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(unchanged, updated, deleted);
return Objects.hash(unchanged, updated, deleted);
}
@Override

View File

@ -20,7 +20,6 @@ import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import com.google.common.base.Objects;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
@ -97,6 +96,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
@ -1058,8 +1058,8 @@ public class MergeOp {
try {
ChangeMessage last = Iterables.getLast(cmUtil.byChange(db, notes));
if (last != null) {
if (Objects.equal(last.getAuthor(), msg.getAuthor())
&& Objects.equal(last.getMessage(), msg.getMessage())) {
if (Objects.equals(last.getAuthor(), msg.getAuthor())
&& Objects.equals(last.getMessage(), msg.getMessage())) {
long lastMs = last.getWrittenOn().getTime();
long msgMs = msg.getWrittenOn().getTime();
long sinceMs = msgMs - lastMs;

View File

@ -15,7 +15,6 @@
package com.google.gerrit.server.git;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
@ -47,6 +46,7 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.RawParseUtils;
import java.io.IOException;
import java.util.Objects;
/**
* Support for metadata stored within a version controlled branch.
@ -275,7 +275,7 @@ public abstract class VersionedMetaData {
@Override
public RevCommit createRef(String refName) throws IOException {
if (Objects.equal(src, revision)) {
if (Objects.equals(src, revision)) {
return revision;
}
return updateRef(ObjectId.zeroId(), src, refName);
@ -306,7 +306,7 @@ public abstract class VersionedMetaData {
@Override
public RevCommit commitAt(ObjectId expected) throws IOException {
if (Objects.equal(src, expected)) {
if (Objects.equals(src, expected)) {
return revision;
}
return updateRef(MoreObjects.firstNonNull(expected, ObjectId.zeroId()),

View File

@ -19,7 +19,6 @@ import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId;
import static com.google.gerrit.server.notedb.CommentsInNotesUtil.getCommentPsId;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
@ -52,6 +51,7 @@ import java.sql.Timestamp;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@ -232,13 +232,13 @@ public class ChangeRebuilder {
}
protected void checkUpdate(AbstractChangeUpdate update) {
checkState(Objects.equal(update.getPatchSetId(), psId),
checkState(Objects.equals(update.getPatchSetId(), psId),
"cannot apply event for %s to update for %s",
update.getPatchSetId(), psId);
checkState(when.getTime() - update.getWhen().getTime() <= TS_WINDOW_MS,
"event at %s outside update window starting at %s",
when, update.getWhen());
checkState(Objects.equal(update.getUser().getAccountId(), who),
checkState(Objects.equals(update.getUser().getAccountId(), who),
"cannot apply event by %s to update by %s",
who, update.getUser().getAccountId());
}

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.project;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.extensions.api.projects.ProjectInput.ConfigValue;
@ -56,6 +55,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
@Singleton
@ -178,7 +178,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
ObjectId baseRev = projectConfig.getRevision();
ObjectId commitRev = projectConfig.commit(md);
// Only fire hook if project was actually changed.
if (!Objects.equal(baseRev, commitRev)) {
if (!Objects.equals(baseRev, commitRev)) {
IdentifiedUser user = (IdentifiedUser) currentUser.get();
hooks.doRefUpdatedHook(
new Branch.NameKey(projectName, RefNames.REFS_CONFIG),

View File

@ -15,7 +15,6 @@
package com.google.gerrit.server.project;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.extensions.restapi.AuthException;
@ -40,6 +39,7 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.ObjectId;
import java.io.IOException;
import java.util.Objects;
@Singleton
class PutDescription implements RestModifyView<ProjectResource, Input> {
@ -97,7 +97,7 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
ObjectId baseRev = config.getRevision();
ObjectId commitRev = config.commit(md);
// Only fire hook if project was actually changed.
if (!Objects.equal(baseRev, commitRev)) {
if (!Objects.equals(baseRev, commitRev)) {
hooks.doRefUpdatedHook(
new Branch.NameKey(resource.getNameKey(), RefNames.REFS_CONFIG),
baseRev, commitRev, user.getAccount());

View File

@ -14,12 +14,12 @@
package com.google.gerrit.server.query.change;
import com.google.common.base.Objects;
import com.google.gerrit.extensions.common.SubmitType;
import org.eclipse.jgit.lib.ObjectId;
import java.io.Serializable;
import java.util.Objects;
public class ConflictKey implements Serializable {
private static final long serialVersionUID = 2L;
@ -73,6 +73,6 @@ public class ConflictKey implements Serializable {
@Override
public int hashCode() {
return Objects.hashCode(commit, otherCommit, submitType, contentMerge);
return Objects.hash(commit, otherCommit, submitType, contentMerge);
}
}

View File

@ -15,11 +15,11 @@
package com.google.gerrit.server.securestore;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Objects;
public class SecureStoreData {
public final File pluginFile;
@ -73,6 +73,6 @@ public class SecureStoreData {
@Override
public int hashCode() {
return Objects.hashCode(storeName);
return Objects.hash(storeName);
}
}

View File

@ -16,11 +16,12 @@ package com.google.gerrit.server.util;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import java.util.Objects;
/** A single vote on a label, consisting of a label name and a value. */
public class LabelVote {
public static LabelVote parse(String text) {
@ -99,7 +100,7 @@ public class LabelVote {
public boolean equals(Object o) {
if (o instanceof LabelVote) {
LabelVote l = (LabelVote) o;
return Objects.equal(name, l.name)
return Objects.equals(name, l.name)
&& value == l.value;
}
return false;