RefPatternMatcher#getUsernames: Return ImmutableSet

This way it's guaranteed that callers see each username only once.

Change-Id: Ica535e345483727c2b99608a2d37b5e8b67e248b
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-01-23 13:36:41 +01:00
parent c47bc45be4
commit eb23e4f2be

View File

@@ -14,11 +14,12 @@
package com.google.gerrit.server.project;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.gerrit.server.project.RefPattern.isRE;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.RefNames;
@@ -26,7 +27,6 @@ import com.google.gerrit.server.CurrentUser;
import dk.brics.automaton.Automaton;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
public abstract class RefPatternMatcher {
@@ -132,15 +132,16 @@ public abstract class RefPatternMatcher {
return false;
}
private Iterable<String> getUsernames(CurrentUser user) {
private ImmutableSet<String> getUsernames(CurrentUser user) {
if (user.isIdentifiedUser()) {
Set<String> emails = user.asIdentifiedUser().getEmailAddresses();
ImmutableSet<String> emails = user.asIdentifiedUser().getEmailAddresses();
if (user.getUserName() == null) {
return emails;
} else if (emails.isEmpty()) {
return ImmutableSet.of(user.getUserName());
}
return Iterables.concat(emails, ImmutableSet.of(user.getUserName()));
return Streams.concat(emails.stream(), ImmutableSet.of(user.getUserName()).stream())
.collect(toImmutableSet());
}
if (user.getUserName() != null) {
return ImmutableSet.of(user.getUserName());