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:
David Pursehouse
2016-02-18 15:28:55 +09:00
parent 38d9918edf
commit 8b6d2f52c3
5 changed files with 46 additions and 53 deletions

View File

@@ -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 &lt;author@example.com&gt;}: full populated</li>
* <li>{@code A U. Thor (12)}: missing email address</li>
* <li>{@code Anonymous Coward &lt;author@example.com&gt;}: 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;