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
This commit is contained in:
@@ -76,51 +76,4 @@ public class AccountInfo {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +243,49 @@ public final class Account {
|
||||
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;
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.google.common.collect.FluentIterable;
|
||||
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 class IdentifiedUser extends CurrentUser {
|
||||
}
|
||||
|
||||
public String getNameEmail() {
|
||||
return new AccountInfo(getAccount()).getNameEmail(anonymousCowardName);
|
||||
return getAccount().getNameEmail(anonymousCowardName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.notedb;
|
||||
|
||||
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 class ChangeNoteUtil {
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableList;
|
||||
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 @@ public class CommentsInNotesUtil {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user