aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2023-07-06 16:34:41 +0200
committersonartech <sonartech@sonarsource.com>2023-07-17 20:03:45 +0000
commit1716376a8e423d7811a031cff0210d89757ee8b1 (patch)
tree21cd4a178ad0d1dfd80859b53ab92beb63106452
parent30b98e2afca3a56f4b52f79f483a3b5ab353ece3 (diff)
downloadsonarqube-1716376a8e423d7811a031cff0210d89757ee8b1.tar.gz
sonarqube-1716376a8e423d7811a031cff0210d89757ee8b1.zip
NO-JIRA replace MoreCollectors.toHashSet with Collectors.toSet
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java3
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryValidator.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImpl.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/util/stream/MoreCollectors.java10
-rw-r--r--sonar-core/src/test/java/org/sonar/core/util/stream/MoreCollectorsTest.java12
9 files changed, 12 insertions, 31 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
index 0824989ff91..3de3e502207 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
@@ -72,7 +72,6 @@ import static org.sonar.api.utils.DateUtils.longToDate;
import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS;
@@ -311,7 +310,7 @@ public class IssueQueryFactory {
return;
}
- Set<String> qualifiers = components.stream().map(ComponentDto::qualifier).collect(toHashSet());
+ Set<String> qualifiers = components.stream().map(ComponentDto::qualifier).collect(Collectors.toSet());
checkArgument(qualifiers.size() == 1, "All components must have the same qualifier, found %s", String.join(",", qualifiers));
setBranch(builder, components.get(0), request.getBranch(), request.getPullRequest(), dbSession);
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java
index 7468cbe5fd3..144222b18a0 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java
@@ -164,7 +164,7 @@ public class PermissionIndexer implements EventIndexer {
PermissionIndexerDao permissionIndexerDao = new PermissionIndexerDao();
Set<String> remainingEntityUuids = items.stream().map(EsQueueDto::getDocId)
.map(AuthorizationDoc::entityUuidOf)
- .collect(MoreCollectors.toHashSet());
+ .collect(Collectors.toSet());
permissionIndexerDao.selectByUuids(dbClient, dbSession, remainingEntityUuids).forEach(p -> {
remainingEntityUuids.remove(p.getEntityUuid());
bulkIndexers.forEach(bi -> bi.add(AuthorizationDoc.fromDto(bi.getIndexType(), p).toIndexRequest()));
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryValidator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryValidator.java
index 82a077b79cd..3143aedb168 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryValidator.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryValidator.java
@@ -28,7 +28,6 @@ import org.sonar.server.measure.index.ProjectMeasuresQuery;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Arrays.asList;
-import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
import static org.sonar.db.measure.ProjectMeasuresIndexerIterator.METRIC_KEYS;
import static org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion;
import static org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_LAST_ANALYSIS_DATE;
@@ -42,7 +41,7 @@ public class ProjectMeasuresQueryValidator {
}
public static void validate(ProjectMeasuresQuery query) {
- validateFilterKeys(query.getMetricCriteria().stream().map(MetricCriterion::getMetricKey).collect(toHashSet()));
+ validateFilterKeys(query.getMetricCriteria().stream().map(MetricCriterion::getMetricKey).collect(Collectors.toSet()));
validateSort(query.getSort());
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
index 4462634a79f..12ff4cec875 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.resources.ResourceTypes;
@@ -48,10 +49,9 @@ import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.SUBVIEW;
import static org.sonar.api.resources.Qualifiers.VIEW;
-import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
-import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
+import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
@@ -127,7 +127,7 @@ public class SearchAction implements ComponentsWsAction {
private Map<String, String> searchProjectsKeysByUuids(DbSession dbSession, List<EntityDto> entities) {
Set<String> projectUuidsToSearch = entities.stream()
.map(EntityDto::getAuthUuid)
- .collect(toHashSet());
+ .collect(Collectors.toSet());
List<EntityDto> projects = dbClient.entityDao().selectByUuids(dbSession, projectUuidsToSearch);
return projects.stream().collect(toMap(EntityDto::getUuid, EntityDto::getKey));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
index 62444aa7776..2c1ff6b57e3 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.MeasureDto;
@@ -88,7 +87,7 @@ public class SearchHistoryResult {
}
public SearchHistoryResult setMeasures(List<MeasureDto> measures) {
- Set<String> analysisUuids = analyses.stream().map(SnapshotDto::getUuid).collect(MoreCollectors.toHashSet());
+ Set<String> analysisUuids = analyses.stream().map(SnapshotDto::getUuid).collect(Collectors.toSet());
ImmutableList.Builder<MeasureDto> measuresBuilder = ImmutableList.builder();
List<MeasureDto> filteredMeasures = measures.stream()
.filter(measure -> analysisUuids.contains(measure.getAnalysisUuid()))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImpl.java
index 7573cdbf284..30bb63dd1bc 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImpl.java
@@ -57,7 +57,7 @@ public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
Set<String> deactivatedRuleUuids = dbClient.activeRuleDao().selectByRuleProfile(dbSession, initialRuleProfile)
.stream()
.map(ActiveRuleDto::getRuleUuid)
- .collect(MoreCollectors.toHashSet());
+ .collect(Collectors.toSet());
// all rules, including those which are removed from built-in profile
Set<String> ruleUuids = Stream.concat(
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java
index d2e05d66a6f..52e3e5f2314 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java
@@ -475,7 +475,7 @@ public class RuleActivator {
Collection<QProfileDto> profiles = db.qualityProfileDao().selectDescendants(dbSession, parents);
Set<String> ruleProfileUuids = profiles.stream()
.map(QProfileDto::getRulesProfileUuid)
- .collect(MoreCollectors.toHashSet());
+ .collect(Collectors.toSet());
Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleUuids, ruleProfileUuids);
List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(Collectors.toList());
List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
diff --git a/sonar-core/src/main/java/org/sonar/core/util/stream/MoreCollectors.java b/sonar-core/src/main/java/org/sonar/core/util/stream/MoreCollectors.java
index b21fcbfcc9e..fd07870b346 100644
--- a/sonar-core/src/main/java/org/sonar/core/util/stream/MoreCollectors.java
+++ b/sonar-core/src/main/java/org/sonar/core/util/stream/MoreCollectors.java
@@ -26,9 +26,9 @@ import com.google.common.collect.ImmutableSetMultimap;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
@@ -57,12 +57,8 @@ public final class MoreCollectors {
return Collectors.toCollection(() -> EnumSet.noneOf(enumClass));
}
- public static <T> Collector<T, ?, HashSet<T>> toHashSet() {
- return java.util.stream.Collectors.toCollection(HashSet::new);
- }
-
- public static <T> Collector<T, ?, HashSet<T>> toHashSet(int size) {
- return java.util.stream.Collectors.toCollection(() -> new HashSet<>(size));
+ public static <T> Collector<T, ?, Set<T>> toHashSet(int size) {
+ return Collectors.toSet();
}
/**
diff --git a/sonar-core/src/test/java/org/sonar/core/util/stream/MoreCollectorsTest.java b/sonar-core/src/test/java/org/sonar/core/util/stream/MoreCollectorsTest.java
index 26195f9903e..1dc511d2b64 100644
--- a/sonar-core/src/test/java/org/sonar/core/util/stream/MoreCollectorsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/util/stream/MoreCollectorsTest.java
@@ -79,18 +79,6 @@ public class MoreCollectorsTest {
}
@Test
- public void toHashSet_builds_an_HashSet() {
- Set<Integer> res = Stream.of(1, 2, 3, 4, 5).collect(toHashSet());
- assertThat(res).isInstanceOf(HashSet.class)
- .containsExactly(1, 2, 3, 4, 5);
- }
-
- @Test
- public void toHashSet_parallel_stream() {
- assertThat(HUGE_SET.parallelStream().collect(toHashSet())).isEqualTo(HUGE_SET);
- }
-
- @Test
public void toHashSet_with_size_builds_an_ArrayList() {
Set<Integer> res = Stream.of(1, 2, 3, 4, 5).collect(toHashSet(30));
assertThat(res).isInstanceOf(HashSet.class)