AccountInfo: Move getName and getNameEmail to Account
These methods are only being invoked by callers that already
have an Account. Move the methods to Account and invoke them
directly rather than instantiating a new AccountInfo only for
these calls.
Change-Id: Ie32f3316b4fef74afb6d98a4e26de2ea27909fe1
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountInfo.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountInfo.java
index 8614be5..e8f9fd5 100644
--- a/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountInfo.java
+++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountInfo.java
@@ -76,51 +76,4 @@
public String getUsername() {
return username;
}
-
- /**
- * Formats an account name.
- * <p>
- * If the account has a full name, it returns only the full name. Otherwise it
- * returns a longer form that includes the email address.
- */
- public String getName(String anonymousCowardName) {
- if (getFullName() != null) {
- return getFullName();
- }
- if (getPreferredEmail() != null) {
- return getPreferredEmail();
- }
- return getNameEmail(anonymousCowardName);
- }
-
- /**
- * Formats an account as a name and an email address.
- * <p>
- * Example output:
- * <ul>
- * <li>{@code A U. Thor <author@example.com>}: full populated</li>
- * <li>{@code A U. Thor (12)}: missing email address</li>
- * <li>{@code Anonymous Coward <author@example.com>}: missing name</li>
- * <li>{@code Anonymous Coward (12)}: missing name and email address</li>
- * </ul>
- */
- public String getNameEmail(String anonymousCowardName) {
- String name = getFullName();
- if (name == null) {
- name = anonymousCowardName;
- }
-
- final StringBuilder b = new StringBuilder();
- b.append(name);
- if (getPreferredEmail() != null) {
- b.append(" <");
- b.append(getPreferredEmail());
- b.append(">");
- } else if (getId() != null) {
- b.append(" (");
- b.append(getId().get());
- b.append(")");
- }
- return b.toString();
- }
}
diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java
index 295239f..2bb6702 100644
--- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java
+++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java
@@ -243,6 +243,49 @@
preferredEmail = addr;
}
+ /**
+ * Formats an account name.
+ * <p>
+ * If the account has a full name, it returns only the full name. Otherwise it
+ * returns a longer form that includes the email address.
+ */
+ public String getName(String anonymousCowardName) {
+ if (fullName != null) {
+ return fullName;
+ }
+ if (preferredEmail != null) {
+ return preferredEmail;
+ }
+ return getNameEmail(anonymousCowardName);
+ }
+
+ /**
+ * Get the name and email address.
+ * <p>
+ * Example output:
+ * <ul>
+ * <li>{@code A U. Thor <author@example.com>}: full populated</li>
+ * <li>{@code A U. Thor (12)}: missing email address</li>
+ * <li>{@code Anonymous Coward <author@example.com>}: missing name</li>
+ * <li>{@code Anonymous Coward (12)}: missing name and email address</li>
+ * </ul>
+ */
+ public String getNameEmail(String anonymousCowardName) {
+ String name = fullName != null ? fullName : anonymousCowardName;
+ StringBuilder b = new StringBuilder();
+ b.append(name);
+ if (preferredEmail != null) {
+ b.append(" <");
+ b.append(preferredEmail);
+ b.append(">");
+ } else if (accountId != null) {
+ b.append(" (");
+ b.append(accountId.get());
+ b.append(")");
+ }
+ return b.toString();
+ }
+
/** Get the date and time the user first registered. */
public Timestamp getRegisteredOn() {
return registeredOn;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java b/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java
index e9f37e9..2e93ce7 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java
@@ -18,7 +18,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable;
-import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountProjectWatch;
import com.google.gerrit.reviewdb.client.Change;
@@ -309,7 +308,7 @@
}
public String getNameEmail() {
- return new AccountInfo(getAccount()).getNameEmail(anonymousCowardName);
+ return getAccount().getNameEmail(anonymousCowardName);
}
@Override
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeNoteUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeNoteUtil.java
index 3199a47..f6f7dd5 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeNoteUtil.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeNoteUtil.java
@@ -16,7 +16,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Ints;
-import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.RefNames;
@@ -62,7 +61,7 @@
public static PersonIdent newIdent(Account author, Date when,
PersonIdent serverIdent, String anonymousCowardName) {
return new PersonIdent(
- new AccountInfo(author).getName(anonymousCowardName),
+ author.getName(anonymousCowardName),
author.getId().get() + "@" + GERRIT_PLACEHOLDER_HOST,
when, serverIdent.getTimeZone());
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/CommentsInNotesUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/CommentsInNotesUtil.java
index a35e7b9..b59386b 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/CommentsInNotesUtil.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/CommentsInNotesUtil.java
@@ -26,7 +26,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.primitives.Ints;
-import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.CommentRange;
@@ -364,7 +363,7 @@
private PersonIdent newIdent(Account author, Date when) {
return new PersonIdent(
- new AccountInfo(author).getName(anonymousCowardName),
+ author.getName(anonymousCowardName),
author.getId().get() + "@" + GERRIT_PLACEHOLDER_HOST,
when, serverIdent.getTimeZone());
}