Merge "Refactor AccountState to be a Java record"
diff --git a/java/com/google/gerrit/server/account/AccountState.java b/java/com/google/gerrit/server/account/AccountState.java
index 13c913d..e2fd6af 100644
--- a/java/com/google/gerrit/server/account/AccountState.java
+++ b/java/com/google/gerrit/server/account/AccountState.java
@@ -14,7 +14,6 @@
package com.google.gerrit.server.account;
-import com.google.auto.value.AutoValue;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -38,9 +37,21 @@
*
* <p>Most callers should not construct AccountStates directly but rather lookup accounts via the
* account cache (see {@link AccountCache#get(Account.Id)}).
+ *
+ * @param account Cached account metadata.
+ * @param externalIds The external identities that identify the account holder.
+ * @param userName The username, if one has been declared for this user.
+ * @param projectWatches The project watches of the account.
+ * @param defaultPreferences Gerrit's default preferences as stored in {@code preferences.config}.
+ * @param userPreferences User preferences as stored in {@code preferences.config}.
*/
-@AutoValue
-public abstract class AccountState {
+public record AccountState(
+ Account account,
+ ImmutableSet<ExternalId> externalIds,
+ Optional<String> userName,
+ ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>> projectWatches,
+ Optional<CachedPreferences> defaultPreferences,
+ Optional<CachedPreferences> userPreferences) {
/**
* Creates an AccountState for a given account with no external IDs, no project watches and
@@ -63,7 +74,7 @@
CachedAccountDetails account, CachedPreferences defaultConfig, ExternalIds externalIds)
throws IOException {
ImmutableSet<ExternalId> extIds = externalIds.byAccount(account.account().id());
- return new AutoValue_AccountState(
+ return new AccountState(
account.account(),
extIds,
ExternalId.getUserName(extIds),
@@ -80,7 +91,7 @@
* @return the account state
*/
public static AccountState forAccount(Account account, Collection<ExternalId> extIds) {
- return new AutoValue_AccountState(
+ return new AccountState(
account,
ImmutableSet.copyOf(extIds),
ExternalId.getUserName(extIds),
@@ -97,31 +108,10 @@
ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>> projectWatches,
Optional<CachedPreferences> defaultPreferences,
Optional<CachedPreferences> userPreferences) {
- return new AutoValue_AccountState(
+ return new AccountState(
account, externalIds, userName, projectWatches, defaultPreferences, userPreferences);
}
- /** Get the cached account metadata. */
- public abstract Account account();
-
- /** The external identities that identify the account holder. */
- public abstract ImmutableSet<ExternalId> externalIds();
-
- /**
- * Get the username, if one has been declared for this user.
- *
- * <p>The username is the {@link ExternalId} using the scheme {@link ExternalId#SCHEME_USERNAME}.
- *
- * @return the username, {@link Optional#empty()} if the user has no username, or if the username
- * is empty
- */
- public abstract Optional<String> userName();
-
- /** The project watches of the account. */
- public abstract ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>> projectWatches();
-
- /** The general preferences of the account. */
-
/** The general preferences of the account. */
public GeneralPreferencesInfo generalPreferences() {
return CachedPreferences.general(
@@ -141,13 +131,13 @@
}
@Override
- public final String toString() {
+ public String toString() {
MoreObjects.ToStringHelper h = MoreObjects.toStringHelper(this);
h.addValue(account().id());
return h.toString();
}
- public final String debugString() {
+ public String debugString() {
// Most of the fields might have a large representation. Using a multiline format to ease the
// reading.
return "AccountState[\n\t"
@@ -161,10 +151,4 @@
.add("editPreferences: " + editPreferences())
+ "\n]";
}
-
- /** Gerrit's default preferences as stored in {@code preferences.config}. */
- public abstract Optional<CachedPreferences> defaultPreferences();
-
- /** User preferences as stored in {@code preferences.config}. */
- public abstract Optional<CachedPreferences> userPreferences();
}