CurrentUser#getUserName: Return Optional<String> instead of nullable String
This makes it more explicit that callers must handle the case where the returned username is absent. Change-Id: I97e33caa8e9cc8092dc398e3b383d7afd5beb96f Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import dk.brics.automaton.Automaton;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class RefPatternMatcher {
|
||||
public static RefPatternMatcher getMatcher(String pattern) {
|
||||
@@ -133,16 +134,11 @@ public abstract class RefPatternMatcher {
|
||||
}
|
||||
|
||||
private ImmutableSet<String> getUsernames(CurrentUser user) {
|
||||
Stream<String> usernames = Streams.stream(user.getUserName());
|
||||
if (user.isIdentifiedUser()) {
|
||||
return Streams.concat(
|
||||
user.asIdentifiedUser().getEmailAddresses().stream(),
|
||||
ImmutableSet.of(user.getUserName()).stream())
|
||||
.collect(toImmutableSet());
|
||||
usernames = Streams.concat(usernames, user.asIdentifiedUser().getEmailAddresses().stream());
|
||||
}
|
||||
if (user.getUserName() != null) {
|
||||
return ImmutableSet.of(user.getUserName());
|
||||
}
|
||||
return ImmutableSet.of();
|
||||
return usernames.collect(toImmutableSet());
|
||||
}
|
||||
|
||||
public boolean matchPrefix(String ref) {
|
||||
|
||||
Reference in New Issue
Block a user