Replace usage of Iterables.limit with Java 8 Stream API
Also remove ChangeQueryBuilder's unnecessary construction of an ImmutableSet. The else block returns a regular Set, so there is no need for the other branch to return ImmutableSet. Change-Id: I28b14ee322b7edabea5023f9cb25452d128da9d8
This commit is contained in:
parent
292815cf05
commit
dba9da101c
@ -18,8 +18,6 @@ import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.common.GroupBaseInfo;
|
||||
@ -275,10 +273,9 @@ public class ReviewersUtil {
|
||||
|
||||
private List<GroupReference> suggestAccountGroups(
|
||||
SuggestReviewers suggestReviewers, ProjectState projectState) {
|
||||
return Lists.newArrayList(
|
||||
Iterables.limit(
|
||||
groupBackend.suggest(suggestReviewers.getQuery(), projectState),
|
||||
suggestReviewers.getLimit()));
|
||||
return groupBackend.suggest(suggestReviewers.getQuery(), projectState).stream()
|
||||
.limit(suggestReviewers.getLimit())
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
private static class GroupAsReviewer {
|
||||
|
@ -15,10 +15,10 @@
|
||||
package com.google.gerrit.server.group;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.gerrit.common.data.GroupDescription;
|
||||
@ -304,12 +304,12 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
"You should only have no more than one --project and -n with --suggest");
|
||||
}
|
||||
List<GroupReference> groupRefs =
|
||||
Lists.newArrayList(
|
||||
Iterables.limit(
|
||||
groupBackend.suggest(
|
||||
suggest,
|
||||
projects.stream().findFirst().map(pc -> pc.getProjectState()).orElse(null)),
|
||||
limit <= 0 ? 10 : Math.min(limit, 10)));
|
||||
groupBackend
|
||||
.suggest(
|
||||
suggest, projects.stream().findFirst().map(pc -> pc.getProjectState()).orElse(null))
|
||||
.stream()
|
||||
.limit(limit <= 0 ? 10 : Math.min(limit, 10))
|
||||
.collect(toList());
|
||||
|
||||
List<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groupRefs.size());
|
||||
for (GroupReference ref : groupRefs) {
|
||||
|
@ -21,8 +21,6 @@ import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Enums;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.gerrit.common.data.GroupDescription;
|
||||
@ -1244,7 +1242,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
int maxTerms = args.indexConfig.maxTerms();
|
||||
if (allMembers.size() > maxTerms) {
|
||||
// limit the number of query terms otherwise Gerrit will barf
|
||||
accounts = ImmutableSet.copyOf(Iterables.limit(allMembers, maxTerms));
|
||||
accounts = allMembers.stream().limit(maxTerms).collect(toSet());
|
||||
} else {
|
||||
accounts = allMembers;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user