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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user