Replace custom eq methods with Objects.equals
Change-Id: Ia167b23754de6f33d4d6a105accbc14e444cc98a Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/** Helper to edit a section of the configuration files. */
|
/** Helper to edit a section of the configuration files. */
|
||||||
@@ -100,7 +101,7 @@ public class Section {
|
|||||||
if (nullIfDefault && nv.equals(dv)) {
|
if (nullIfDefault && nv.equals(dv)) {
|
||||||
nv = null;
|
nv = null;
|
||||||
}
|
}
|
||||||
if (!eq(ov, nv)) {
|
if (!Objects.equals(ov, nv)) {
|
||||||
set(name, nv);
|
set(name, nv);
|
||||||
}
|
}
|
||||||
return nv;
|
return nv;
|
||||||
@@ -148,7 +149,7 @@ public class Section {
|
|||||||
public String select(final String title, String name, String dv, Set<String> allowedValues) {
|
public String select(final String title, String name, String dv, Set<String> allowedValues) {
|
||||||
final String ov = get(name);
|
final String ov = get(name);
|
||||||
String nv = ui.readString(ov != null ? ov : dv, allowedValues, "%s", title);
|
String nv = ui.readString(ov != null ? ov : dv, allowedValues, "%s", title);
|
||||||
if (!eq(ov, nv)) {
|
if (!Objects.equals(ov, nv)) {
|
||||||
set(name, nv);
|
set(name, nv);
|
||||||
}
|
}
|
||||||
return nv;
|
return nv;
|
||||||
@@ -177,7 +178,7 @@ public class Section {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String nv = ui.password("%s's password", user);
|
final String nv = ui.password("%s's password", user);
|
||||||
if (!eq(ov, nv)) {
|
if (!Objects.equals(ov, nv)) {
|
||||||
setSecure(password, nv);
|
setSecure(password, nv);
|
||||||
}
|
}
|
||||||
return nv;
|
return nv;
|
||||||
@@ -195,7 +196,7 @@ public class Section {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String nv = ui.password("%s", prompt);
|
final String nv = ui.password("%s", prompt);
|
||||||
if (!eq(ov, nv)) {
|
if (!Objects.equals(ov, nv)) {
|
||||||
setSecure(passwordKey, nv);
|
setSecure(passwordKey, nv);
|
||||||
}
|
}
|
||||||
return nv;
|
return nv;
|
||||||
@@ -216,11 +217,4 @@ public class Section {
|
|||||||
String getName() {
|
String getName() {
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean eq(String a, String b) {
|
|
||||||
if (a == null && b == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return a != null && a.equals(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -225,13 +226,13 @@ public class AccountManager {
|
|||||||
|
|
||||||
if (!realm.allowsEdit(AccountFieldName.FULL_NAME)
|
if (!realm.allowsEdit(AccountFieldName.FULL_NAME)
|
||||||
&& !Strings.isNullOrEmpty(who.getDisplayName())
|
&& !Strings.isNullOrEmpty(who.getDisplayName())
|
||||||
&& !eq(user.getAccount().getFullName(), who.getDisplayName())) {
|
&& !Objects.equals(user.getAccount().getFullName(), who.getDisplayName())) {
|
||||||
accountUpdates.add(u -> u.setFullName(who.getDisplayName()));
|
accountUpdates.add(u -> u.setFullName(who.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!realm.allowsEdit(AccountFieldName.USER_NAME)
|
if (!realm.allowsEdit(AccountFieldName.USER_NAME)
|
||||||
&& who.getUserName() != null
|
&& who.getUserName() != null
|
||||||
&& !eq(user.getUserName(), who.getUserName())) {
|
&& !Objects.equals(user.getUserName(), who.getUserName())) {
|
||||||
log.warn(
|
log.warn(
|
||||||
String.format(
|
String.format(
|
||||||
"Not changing already set username %s to %s", user.getUserName(), who.getUserName()));
|
"Not changing already set username %s to %s", user.getUserName(), who.getUserName()));
|
||||||
@@ -249,10 +250,6 @@ public class AccountManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean eq(String a, String b) {
|
|
||||||
return (a == null && b == null) || (a != null && a.equals(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
private AuthResult create(ReviewDb db, AuthRequest who)
|
private AuthResult create(ReviewDb db, AuthRequest who)
|
||||||
throws OrmException, AccountException, IOException, ConfigInvalidException {
|
throws OrmException, AccountException, IOException, ConfigInvalidException {
|
||||||
Account.Id newId = new Account.Id(sequences.nextAccountId());
|
Account.Id newId = new Account.Id(sequences.nextAccountId());
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@@ -2445,7 +2446,8 @@ class ReceiveCommits {
|
|||||||
// or no parents were updated (rebase), else warn that only part
|
// or no parents were updated (rebase), else warn that only part
|
||||||
// of the commit was modified.
|
// of the commit was modified.
|
||||||
if (newCommit.getTree().equals(priorCommit.getTree())) {
|
if (newCommit.getTree().equals(priorCommit.getTree())) {
|
||||||
boolean messageEq = eq(newCommit.getFullMessage(), priorCommit.getFullMessage());
|
boolean messageEq =
|
||||||
|
Objects.equals(newCommit.getFullMessage(), priorCommit.getFullMessage());
|
||||||
boolean parentsEq = parentsEqual(newCommit, priorCommit);
|
boolean parentsEq = parentsEqual(newCommit, priorCommit);
|
||||||
boolean authorEq = authorEqual(newCommit, priorCommit);
|
boolean authorEq = authorEqual(newCommit, priorCommit);
|
||||||
ObjectReader reader = rp.getRevWalk().getObjectReader();
|
ObjectReader reader = rp.getRevWalk().getObjectReader();
|
||||||
@@ -2723,18 +2725,8 @@ class ReceiveCommits {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return eq(aAuthor.getName(), bAuthor.getName())
|
return Objects.equals(aAuthor.getName(), bAuthor.getName())
|
||||||
&& eq(aAuthor.getEmailAddress(), bAuthor.getEmailAddress());
|
&& Objects.equals(aAuthor.getEmailAddress(), bAuthor.getEmailAddress());
|
||||||
}
|
|
||||||
|
|
||||||
static boolean eq(String a, String b) {
|
|
||||||
if (a == null && b == null) {
|
|
||||||
return true;
|
|
||||||
} else if (a == null || b == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return a.equals(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validRefOperation(ReceiveCommand cmd) {
|
private boolean validRefOperation(ReceiveCommand cmd) {
|
||||||
|
|||||||
Reference in New Issue
Block a user