NotifyResolver: Use SetMultimap for accounts to notify

An account ID should only appear once per RecipientType; allowing
duplicates of the same account ID with the same RecipientType doesn't
make sense. This shouldn't have any effect in practice, since these
accounts are converted to Sets within OutgoingEmail, but the code is
cleaner this way.

Change-Id: I677def1384151bfe52fa20e291864b260a9df3fb
This commit is contained in:
Dave Borowitz
2019-02-05 15:22:58 -08:00
parent 0312eb2315
commit eecebc44d6
2 changed files with 7 additions and 7 deletions

View File

@@ -19,7 +19,7 @@ import static java.util.stream.Collectors.joining;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.api.changes.NotifyInfo;
@@ -50,18 +50,18 @@ public class NotifyResolver {
}
public static Result create(NotifyHandling notifyHandling) {
return create(notifyHandling, ImmutableListMultimap.of());
return create(notifyHandling, ImmutableSetMultimap.of());
}
public static Result create(
NotifyHandling handling, ImmutableListMultimap<RecipientType, Account.Id> recipients) {
NotifyHandling handling, ImmutableSetMultimap<RecipientType, Account.Id> recipients) {
return new AutoValue_NotifyResolver_Result(handling, recipients);
}
public abstract NotifyHandling handling();
// TODO(dborowitz): Should be ImmutableSetMultimap.
public abstract ImmutableListMultimap<RecipientType, Account.Id> accounts();
public abstract ImmutableSetMultimap<RecipientType, Account.Id> accounts();
public Result withHandling(NotifyHandling notifyHandling) {
return create(notifyHandling, accounts());
@@ -83,7 +83,7 @@ public class NotifyResolver {
NotifyHandling handling, @Nullable Map<RecipientType, NotifyInfo> notifyDetails)
throws BadRequestException, OrmException, IOException, ConfigInvalidException {
requireNonNull(handling);
ImmutableListMultimap.Builder<RecipientType, Account.Id> b = ImmutableListMultimap.builder();
ImmutableSetMultimap.Builder<RecipientType, Account.Id> b = ImmutableSetMultimap.builder();
if (notifyDetails != null) {
for (Map.Entry<RecipientType, NotifyInfo> e : notifyDetails.entrySet()) {
b.putAll(e.getKey(), find(e.getValue().accounts));

View File

@@ -49,8 +49,8 @@ import com.google.common.base.Throwables;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
@@ -1586,7 +1586,7 @@ class ReceiveCommits {
NotifyResolver.Result getNotifyForNewChange() {
return NotifyResolver.Result.create(
firstNonNull(notifyHandling, workInProgress ? NotifyHandling.OWNER : NotifyHandling.ALL),
ImmutableListMultimap.<RecipientType, Account.Id>builder()
ImmutableSetMultimap.<RecipientType, Account.Id>builder()
.putAll(RecipientType.TO, notifyTo)
.putAll(RecipientType.CC, notifyCc)
.putAll(RecipientType.BCC, notifyBcc)