aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2023-07-10 16:59:50 +0200
committersonartech <sonartech@sonarsource.com>2023-07-17 20:03:45 +0000
commitce0e4ddf7ec619dde2c6cf02ae0ec08012f47335 (patch)
tree2f32948edd74d54872a7ec53c07fb1289e88a34a /server
parent46ac0043ee3aedee6b2304969533847781d985ef (diff)
downloadsonarqube-ce0e4ddf7ec619dde2c6cf02ae0ec08012f47335.tar.gz
sonarqube-ce0e4ddf7ec619dde2c6cf02ae0ec08012f47335.zip
NO-JIRA replace guava copy uniqueIndex to Collectors.toMap and simplify lambdas
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoader.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImpl.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerExecutionTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java10
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/KeyLongValue.java5
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java6
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java6
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java6
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationHandler.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java4
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java3
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java3
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java9
-rw-r--r--server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterMetricsIT.java5
-rw-r--r--server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterPluginsIT.java7
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java8
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java4
-rw-r--r--server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java5
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java4
-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/measure/index/ProjectMeasuresIndex.java6
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java7
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java9
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationIT.java7
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java7
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java21
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java7
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateCaycChecker.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchGroupsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchUsersAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImpl.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java4
68 files changed, 177 insertions, 188 deletions
diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
index 22a22cd7645..99c7cfdbd0a 100644
--- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
+++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
@@ -57,7 +58,6 @@ import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.singleton;
import static java.util.Optional.ofNullable;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS;
import static org.sonar.db.ce.CeQueueDto.Status.PENDING;
@@ -228,7 +228,7 @@ public class CeQueueImpl implements CeQueue {
// these components correspond to a branch or a portfolio (analysis target)
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao()
.selectByUuids(dbSession, componentUuids).stream()
- .collect(uniqueIndex(ComponentDto::uuid));
+ .collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
Set<String> entityUuids = dtos.stream().map(CeQueueDto::getEntityUuid).filter(Objects::nonNull).collect(Collectors.toSet());
Map<String, EntityDto> entitiesByUuid = dbClient.entityDao().selectByUuids(dbSession, entityUuids).stream()
.collect(Collectors.toMap(EntityDto::getUuid, e -> e));
@@ -249,7 +249,7 @@ public class CeQueueImpl implements CeQueue {
.map(entitiesByUuid::get)
.orElse(null);
Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream()
- .collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
+ .collect(Collectors.toMap(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
result.add(convertToTask(dbSession, dto, characteristics, component, entity));
}
return result;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
index 9e545bfba94..1b0fd6774c6 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
@@ -34,6 +34,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.ibatis.session.ResultContext;
@@ -52,7 +53,6 @@ import org.sonar.ce.task.projectanalysis.filemove.FileSimilarity.LazyFileImpl;
import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepository;
import org.sonar.ce.task.step.ComputationStep;
import org.sonar.core.util.logs.Profiler;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.FileMoveRowDto;
@@ -208,7 +208,7 @@ public class FileMoveDetectionStep implements ComputationStep {
builder.add(new DbComponent(row.getKey(), row.getUuid(), row.getPath(), row.getLineCount()));
});
return builder.build().stream()
- .collect(MoreCollectors.uniqueIndex(DbComponent::uuid));
+ .collect(Collectors.toMap(DbComponent::uuid, Function.identity()));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoader.java
index 0406506f8a7..04b667ad070 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoader.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoader.java
@@ -27,13 +27,15 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
+import org.slf4j.LoggerFactory;
import org.sonar.api.config.Configuration;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.utils.System2;
-import org.slf4j.LoggerFactory;
import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolder;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.FieldDiffs;
@@ -48,7 +50,6 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.groupingBy;
import static org.sonar.api.issue.Issue.STATUS_CLOSED;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.issue.IssueFieldsSetter.FROM_BRANCH;
import static org.sonar.server.issue.IssueFieldsSetter.STATUS;
@@ -163,7 +164,7 @@ public class ComponentIssuesLoader {
* While loading the changes for the issues, this class will also collect old status changes that should be deleted.
*/
private void loadLatestDiffChangesForReopeningOfClosedIssues(DbSession dbSession, Collection<DefaultIssue> issues) {
- Map<String, DefaultIssue> issuesByKey = issues.stream().collect(uniqueIndex(DefaultIssue::key));
+ Map<String, DefaultIssue> issuesByKey = issues.stream().collect(Collectors.toMap(DefaultIssue::key, Function.identity()));
CollectIssueChangesToDeleteResultHandler collectChangesToDelete = new CollectIssueChangesToDeleteResultHandler(issueChangesToDeleteRepository);
CollectLastStatusAndResolution collectLastStatusAndResolution = new CollectLastStatusAndResolution(issuesByKey);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
index 34bde01c7b5..63114035495 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues;
@@ -34,7 +35,6 @@ import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.PrIssueDto;
import static org.sonar.api.utils.DateUtils.longToDate;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class SiblingsIssuesLoader {
@@ -81,7 +81,7 @@ public class SiblingsIssuesLoader {
.toList();
componentIssuesLoader.loadChanges(session, issues);
return issues.stream()
- .collect(uniqueIndex(i -> issuesByKey.get(i.key()), i -> i, issues.size()));
+ .collect(Collectors.toMap(i -> issuesByKey.get(i.key()), Function.identity()));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImpl.java
index 93ec34fccff..c01eaad6d09 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImpl.java
@@ -22,11 +22,12 @@ package org.sonar.ce.task.projectanalysis.metric;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.sonar.api.measures.Metric;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.measures.Metric;
import org.sonar.core.metric.ScannerMetrics;
-import org.sonar.core.util.stream.MoreCollectors;
public class ReportMetricValidatorImpl implements ReportMetricValidator {
private static final Logger LOG = LoggerFactory.getLogger(ReportMetricValidatorImpl.class);
@@ -35,7 +36,7 @@ public class ReportMetricValidatorImpl implements ReportMetricValidator {
private final Set<String> alreadyLoggedMetricKeys = new HashSet<>();
public ReportMetricValidatorImpl(ScannerMetrics scannerMetrics) {
- this.metricByKey = scannerMetrics.getMetrics().stream().collect(MoreCollectors.uniqueIndex(Metric::getKey));
+ this.metricByKey = scannerMetrics.getMetrics().stream().collect(Collectors.toMap(Metric::getKey, Function.identity()));
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
index 095a7f3b395..371691edae8 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.step;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache;
@@ -43,7 +44,6 @@ import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.server.issue.IssueStorage;
import static org.sonar.core.util.FileUtils.humanReadableByteCountSI;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class PersistIssuesStep implements ComputationStep {
// holding up to 1000 DefaultIssue (max size of addedIssues and updatedIssues at any given time) in memory should not
@@ -158,7 +158,7 @@ public class PersistIssuesStep implements ComputationStep {
List<String> updatedIssueKeys = updatedIssues.stream().map(DefaultIssue::key).toList();
List<IssueDto> conflictIssueKeys = mapper.selectByKeysIfNotUpdatedAt(updatedIssueKeys, now);
if (!conflictIssueKeys.isEmpty()) {
- Map<String, DefaultIssue> issuesByKeys = updatedIssues.stream().collect(uniqueIndex(DefaultIssue::key, updatedIssues.size()));
+ Map<String, DefaultIssue> issuesByKeys = updatedIssues.stream().collect(Collectors.toMap(DefaultIssue::key, Function.identity()));
conflictIssueKeys
.forEach(dbIssue -> {
DefaultIssue updatedIssue = issuesByKeys.get(dbIssue.getKey());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerExecutionTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerExecutionTest.java
index a16a1a4d641..592cdfb029b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerExecutionTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerExecutionTest.java
@@ -23,6 +23,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Test;
import org.sonar.api.issue.Issue;
@@ -42,7 +44,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class TrackerExecutionTest {
private final TrackerBaseInputFactory baseInputFactory = mock(TrackerBaseInputFactory.class);
@@ -128,7 +129,7 @@ public class TrackerExecutionTest {
ArrayList<DefaultIssue> mappedBaseIssues = new ArrayList<>(mappedClosedIssues);
Issue.STATUSES.stream().filter(t -> !Issue.STATUS_CLOSED.equals(t)).forEach(s -> mappedBaseIssues.add(new DefaultIssue().setKey(s).setStatus(s)));
Collections.shuffle(mappedBaseIssues);
- when(closedTracking.getMatchedRaws()).thenReturn(mappedBaseIssues.stream().collect(uniqueIndex(i -> new DefaultIssue().setKey("raw_for_" + i.key()), i -> i)));
+ when(closedTracking.getMatchedRaws()).thenReturn(mappedBaseIssues.stream().collect(Collectors.toMap(i -> new DefaultIssue().setKey("raw_for_" + i.key()), Function.identity())));
Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java
index 6d0995fc721..eca9c0d0269 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java
@@ -29,6 +29,7 @@ import java.util.Collections;
import java.util.Map;
import java.util.Random;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@@ -71,7 +72,6 @@ import static org.sonar.api.issue.Issue.STATUS_OPEN;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
@RunWith(DataProviderRunner.class)
public class NotificationFactoryTest {
@@ -140,7 +140,7 @@ public class NotificationFactoryTest {
.collect(Collectors.toSet());
MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(
- users.stream().collect(uniqueIndex(UserDto::getUuid)));
+ users.stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity())));
DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
assertThat(detailsSupplier.getUserNameByUuid("foo")).isEmpty();
@@ -184,7 +184,7 @@ public class NotificationFactoryTest {
.collect(Collectors.toSet());
NewIssuesNotification underTest = this.underTest.newNewIssuesNotification(
- users.stream().collect(uniqueIndex(UserDto::getUuid)));
+ users.stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity())));
DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
assertThat(detailsSupplier.getUserNameByUuid("foo")).isEmpty();
@@ -722,7 +722,7 @@ public class NotificationFactoryTest {
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(issues.size());
Map<String, ChangedIssue> changedIssuesByKey = builder.getIssues().stream()
- .collect(uniqueIndex(ChangedIssue::getKey));
+ .collect(Collectors.toMap(ChangedIssue::getKey, Function.identity()));
issues.forEach(
issue -> {
ChangedIssue changedIssue = changedIssuesByKey.get(issue.key());
@@ -737,7 +737,7 @@ public class NotificationFactoryTest {
private static Map<String, UserDto> nonEmptyAssigneesByUuid() {
return IntStream.range(0, 1 + new Random().nextInt(3))
.boxed()
- .collect(uniqueIndex(i -> "uuid_" + i, i -> new UserDto()));
+ .collect(Collectors.toMap(i -> "uuid_" + i, i1 -> new UserDto()));
}
private IssuesChangesNotificationBuilder verifyAndCaptureIssueChangeNotificationBuilder() {
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
index 5e42f5f2f10..517e845d412 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
@@ -27,12 +27,13 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.utils.System2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.utils.System2;
import org.sonar.ce.container.ComputeEngineStatus;
import org.sonar.ce.monitoring.CEQueueStatus;
import org.sonar.ce.task.CeTask;
@@ -51,7 +52,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
@ComputeEngineSide
public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue {
@@ -86,7 +86,7 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
}
CeQueueDto taskDto = opt.get();
Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream()
- .collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
+ .collect(Collectors.toMap(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
CeTask task = convertToTask(dbSession, taskDto, characteristics);
queueStatus.addInProgress();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/KeyLongValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/KeyLongValue.java
index 14e747b07ff..2d284003a14 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/KeyLongValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/KeyLongValue.java
@@ -21,8 +21,7 @@ package org.sonar.db;
import java.util.List;
import java.util.Map;
-
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
+import java.util.stream.Collectors;
public class KeyLongValue {
@@ -52,6 +51,6 @@ public class KeyLongValue {
public static Map<String, Long> toMap(List<KeyLongValue> values) {
return values
.stream()
- .collect(uniqueIndex(KeyLongValue::getKey, KeyLongValue::getValue, values.size()));
+ .collect(Collectors.toMap(KeyLongValue::getKey, KeyLongValue::getValue));
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java
index 4809465c5c5..3a0e8a82eca 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java
@@ -24,6 +24,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Before;
@@ -34,7 +35,6 @@ import org.sonar.api.utils.Version;
import org.sonar.core.platform.SonarQubeVersion;
import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.CoreDbTester;
import static org.assertj.core.api.Assertions.assertThat;
@@ -158,7 +158,7 @@ public class PopulateInitialSchemaTest {
" from internal_properties");
assertThat(rows).hasSize(2);
- Map<String, Map<String, Object>> rowsByKey = rows.stream().collect(MoreCollectors.uniqueIndex(t -> (String) t.get("KEE")));
+ Map<String, Map<String, Object>> rowsByKey = rows.stream().collect(Collectors.toMap(t -> (String) t.get("KEE"), Function.identity()));
verifyInternalProperty(rowsByKey, "installation.date", String.valueOf(system2.now()));
verifyInternalProperty(rowsByKey, "installation.version", version.toString());
}
@@ -181,7 +181,7 @@ public class PopulateInitialSchemaTest {
" from properties");
assertThat(rows).hasSize(3);
- Map<String, Map<String, Object>> rowsByKey = rows.stream().collect(MoreCollectors.uniqueIndex(t -> (String) t.get("PROP_KEY")));
+ Map<String, Map<String, Object>> rowsByKey = rows.stream().collect(Collectors.toMap(t -> (String) t.get("PROP_KEY"), Function.identity()));
verifyProperty(rowsByKey, "sonar.forceAuthentication", "true");
verifyProperty(rowsByKey, "projects.default.visibility", "public");
verifyProperty(rowsByKey, "qualitygate.default", qualityGateUuid);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java
index 40f88950a0a..fa5938cab2b 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java
@@ -23,11 +23,11 @@ import com.google.common.collect.ImmutableSortedMap;
import java.util.Arrays;
import java.util.Map;
import java.util.SortedMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.commons.codec.digest.DigestUtils;
import org.sonar.server.es.newindex.BuiltIndex;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
-
/**
* Hash of index definition is stored in the index itself in order to detect changes of mappings
* between SonarQube versions. In this case, contrary to database tables, indices are dropped
@@ -44,7 +44,7 @@ class IndexDefinitionHash {
return of(
index.getSettings().toString(),
Map.of(mainType.getIndex(), mainType),
- index.getRelationTypes().stream().collect(uniqueIndex(IndexType.IndexRelationType::getName, t -> t)),
+ index.getRelationTypes().stream().collect(Collectors.toMap(IndexType.IndexRelationType::getName, Function.identity())),
index.getAttributes());
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java
index 872e589de6c..6f705071d26 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -36,7 +37,6 @@ import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Optional.ofNullable;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class IssuesChangesNotificationSerializer {
private static final String FIELD_ISSUES_COUNT = "issues.count";
@@ -173,7 +173,7 @@ public class IssuesChangesNotificationSerializer {
.collect(Collectors.toSet())
.stream()
.map(ruleKey -> readRule(notification, ruleKey))
- .collect(uniqueIndex(Rule::getKey, t -> t));
+ .collect(Collectors.toMap(Rule::getKey, Function.identity()));
}
private static Rule readRule(IssuesChangesNotification notification, RuleKey ruleKey) {
@@ -210,7 +210,7 @@ public class IssuesChangesNotificationSerializer {
.setBranchName(notification.getFieldValue(projectPropertyPrefix + ".branchName"))
.build();
})
- .collect(uniqueIndex(Project::getUuid, t -> t));
+ .collect(Collectors.toMap(Project::getUuid, Function.identity()));
}
private static String getProjectFieldValue(IssuesChangesNotification notification, String fieldName, String uuid) {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationHandler.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationHandler.java
index c0fc5147598..e9971df1699 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationHandler.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationHandler.java
@@ -25,10 +25,10 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.server.notification.EmailNotificationHandler;
import org.sonar.server.notification.NotificationDispatcherMetadata;
import org.sonar.server.notification.NotificationManager;
@@ -91,7 +91,7 @@ public class MyNewIssuesNotificationHandler extends EmailNotificationHandler<MyN
Map<String, NotificationManager.EmailRecipient> recipientsByLogin = notificationManager
.findSubscribedEmailRecipients(KEY, projectKey, assignees, ALL_MUST_HAVE_ROLE_USER)
.stream()
- .collect(MoreCollectors.uniqueIndex(NotificationManager.EmailRecipient::login));
+ .collect(Collectors.toMap(NotificationManager.EmailRecipient::login, Function.identity()));
return notifications.stream()
.map(notification -> toEmailDeliveryRequest(recipientsByLogin, notification))
.filter(Objects::nonNull);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java
index 0512e88e685..80f8f8c2111 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java
@@ -26,13 +26,13 @@ import java.io.StringWriter;
import java.util.Comparator;
import java.util.Map;
import java.util.SortedSet;
+import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.util.UtcDateUtils;
import static java.util.function.Function.identity;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
/**
* Represents the array of JSON objects stored in the value of the
@@ -82,7 +82,7 @@ public class QPMeasureData {
}
public Map<String, QualityProfile> getProfilesByKey() {
- return profiles.stream().collect(uniqueIndex(QualityProfile::getQpKey, identity()));
+ return profiles.stream().collect(Collectors.toMap(QualityProfile::getQpKey, identity()));
}
private enum QualityProfileComparator implements Comparator<QualityProfile> {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java b/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java
index 906484ef5a1..767c1ac314c 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -41,7 +42,6 @@ import static java.util.Arrays.stream;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.sonar.api.server.rule.RulesDefinition.PciDssVersion.V3_2;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.security.SecurityStandards.VulnerabilityProbability.HIGH;
import static org.sonar.server.security.SecurityStandards.VulnerabilityProbability.LOW;
import static org.sonar.server.security.SecurityStandards.VulnerabilityProbability.MEDIUM;
@@ -192,7 +192,7 @@ public final class SecurityStandards {
PERMISSION("permission", MEDIUM),
OTHERS("others", LOW);
- private static final Map<String, SQCategory> SQ_CATEGORY_BY_KEY = stream(values()).collect(uniqueIndex(SQCategory::getKey));
+ private static final Map<String, SQCategory> SQ_CATEGORY_BY_KEY = stream(values()).collect(Collectors.toMap(SQCategory::getKey, Function.identity()));
private final String key;
private final VulnerabilityProbability vulnerability;
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java b/server/sonar-server-common/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java
index 23bda610840..4b91344f255 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java
@@ -20,7 +20,7 @@
package org.sonar.server.setting;
import java.util.Map;
-import org.sonar.core.util.stream.MoreCollectors;
+import java.util.stream.Collectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.property.PropertyDto;
@@ -49,7 +49,7 @@ public class DatabaseSettingLoader implements SettingLoader {
try (DbSession dbSession = dbClient.openSession(false)) {
return dbClient.propertiesDao().selectGlobalProperties(dbSession)
.stream()
- .collect(MoreCollectors.uniqueIndex(PropertyDto::getKey, p -> defaultString(p.getValue())));
+ .collect(Collectors.toMap(PropertyDto::getKey, p -> defaultString(p.getValue())));
}
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java
index 5d15db39475..5f6b2e0bc18 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java
@@ -40,7 +40,6 @@ import org.sonar.api.utils.System2;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.platform.EditionProvider;
import org.sonar.core.telemetry.TelemetryExtension;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.user.UserTelemetryDto;
import static java.util.stream.Collectors.joining;
@@ -160,7 +159,7 @@ public class TelemetryDataJsonWriterTest {
public void writes_all_plugins() {
Map<String, String> plugins = IntStream.range(0, 1 + random.nextInt(10))
.boxed()
- .collect(MoreCollectors.uniqueIndex(i -> "P" + i, i -> "V" + i));
+ .collect(Collectors.toMap(i -> "P" + i, i1 -> "V" + i1));
TelemetryData data = telemetryBuilder()
.setPlugins(plugins)
.build();
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
index f024c733ed9..23f9ecec869 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
@@ -44,7 +44,6 @@ import org.sonar.db.rule.RuleParamDto;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableMap;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
/**
* A {@link RuleFinder} implementation that retrieves all rule definitions and their parameter when instantiated, cache
@@ -68,7 +67,7 @@ public class CachingRuleFinder implements ServerRuleFinder {
this.ruleDtosByUuid = dtos.stream().collect(Collectors.toMap(RuleDto::getUuid, d -> d));
this.ruleByRuleDto = buildRulesByRuleDefinitionDto(dbClient, dbSession, dtos);
this.rulesByKey = this.ruleByRuleDto.entrySet().stream()
- .collect(uniqueIndex(entry -> entry.getKey().getKey(), Map.Entry::getValue));
+ .collect(Collectors.toMap(entry -> entry.getKey().getKey(), Map.Entry::getValue));
}
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java
index aa70ab9bdab..6352fbb86fb 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java
@@ -29,12 +29,14 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.sonar.api.server.authentication.IdentityProvider;
-import org.sonar.api.server.authentication.UserIdentity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.server.authentication.IdentityProvider;
+import org.sonar.api.server.authentication.UserIdentity;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.user.GroupDto;
@@ -51,7 +53,6 @@ import org.sonar.server.usergroups.DefaultGroupFinder;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.user.UserSession.IdentityProvider.SONARQUBE;
public class UserRegistrarImpl implements UserRegistrar {
@@ -235,7 +236,7 @@ public class UserRegistrarImpl implements UserRegistrar {
allGroups.addAll(groupsToRemove);
Map<String, GroupDto> groupsByName = dbClient.groupDao().selectByNames(dbSession, allGroups)
.stream()
- .collect(uniqueIndex(GroupDto::getName));
+ .collect(Collectors.toMap(GroupDto::getName, Function.identity()));
addGroups(dbSession, userDto, groupsToAdd, groupsByName);
removeGroups(dbSession, userDto, groupsToRemove, groupsByName);
diff --git a/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterMetricsIT.java b/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterMetricsIT.java
index 1f1b1db9017..bf19912492a 100644
--- a/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterMetricsIT.java
+++ b/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterMetricsIT.java
@@ -23,6 +23,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Rule;
import org.junit.Test;
@@ -39,7 +41,6 @@ import org.sonar.db.metric.MetricDto;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class RegisterMetricsIT {
@@ -174,7 +175,7 @@ public class RegisterMetricsIT {
private Map<String, MetricDto> selectAllMetrics() {
return dbTester.getDbClient().metricDao().selectAll(dbTester.getSession())
.stream()
- .collect(uniqueIndex(MetricDto::getKey));
+ .collect(Collectors.toMap(MetricDto::getKey, Function.identity()));
}
private void assertEquals(Metric expected, MetricDto actual) {
diff --git a/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterPluginsIT.java b/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterPluginsIT.java
index 52f24f023df..409cdf8a297 100644
--- a/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterPluginsIT.java
+++ b/server/sonar-webserver-core/src/it/java/org/sonar/server/startup/RegisterPluginsIT.java
@@ -23,6 +23,8 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
@@ -31,20 +33,19 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.utils.System2;
import org.sonar.core.platform.PluginInfo;
+import org.sonar.core.plugin.PluginType;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.plugin.PluginDto;
import org.sonar.db.plugin.PluginDto.Type;
import org.sonar.server.plugins.PluginFilesAndMd5;
-import org.sonar.core.plugin.PluginType;
import org.sonar.server.plugins.ServerPlugin;
import org.sonar.server.plugins.ServerPluginRepository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class RegisterPluginsIT {
@@ -223,7 +224,7 @@ public class RegisterPluginsIT {
private Map<String, PluginDto> selectAllPlugins() {
return dbTester.getDbClient().pluginDao().selectAll(dbTester.getSession()).stream()
- .collect(uniqueIndex(PluginDto::getKee));
+ .collect(Collectors.toMap(PluginDto::getKee, Function.identity()));
}
private void verify(PluginDto pluginDto, Type type, @Nullable String basePluginKey, String fileHash, boolean removed, @Nullable Long createdAt, long updatedAt) {
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
index 5d84e034432..81bc58417b5 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -32,6 +32,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -77,7 +78,6 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableMap;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
/**
* Register rules at server startup
@@ -156,7 +156,7 @@ public class RegisterRules implements Startable {
private RegisterRulesContext createRegisterRulesContext(DbSession dbSession) {
Map<RuleKey, RuleDto> allRules = dbClient.ruleDao().selectAll(dbSession).stream()
- .collect(uniqueIndex(RuleDto::getKey));
+ .collect(Collectors.toMap(RuleDto::getKey, Function.identity()));
Map<String, Set<SingleDeprecatedRuleKey>> existingDeprecatedKeysById = loadDeprecatedRuleKeys(dbSession);
Map<String, List<RuleParamDto>> ruleParamsByRuleUuid = loadAllRuleParameters(dbSession);
return new RegisterRulesContext(allRules, existingDeprecatedKeysById, ruleParamsByRuleUuid);
@@ -199,7 +199,7 @@ public class RegisterRules implements Startable {
private static Map<RuleKey, RuleDto> buildDbRulesByDbDeprecatedKey(Map<String, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysByUuid,
Map<RuleKey, RuleDto> dbRules) {
Map<String, RuleDto> dbRulesByRuleUuid = dbRules.values().stream()
- .collect(uniqueIndex(RuleDto::getUuid));
+ .collect(Collectors.toMap(RuleDto::getUuid, Function.identity()));
Map<RuleKey, RuleDto> rulesByKey = new LinkedHashMap<>();
for (Map.Entry<String, Set<SingleDeprecatedRuleKey>> entry : dbDeprecatedKeysByUuid.entrySet()) {
@@ -236,7 +236,7 @@ public class RegisterRules implements Startable {
private Map<RuleKey, SingleDeprecatedRuleKey> getDbDeprecatedKeysByOldRuleKey() {
return dbDeprecatedKeysByUuid.values().stream()
.flatMap(Collection::stream)
- .collect(uniqueIndex(SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey));
+ .collect(Collectors.toMap(SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey, Function.identity()));
}
private Set<SingleDeprecatedRuleKey> getDBDeprecatedKeysFor(RuleDto rule) {
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
index 21c097c3c3c..969e44fadc9 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
@@ -42,7 +42,6 @@ import org.sonar.api.server.ServerSide;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.alm.setting.ALM;
@@ -151,8 +150,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
data.setVersion(server.getVersion());
data.setEdition(editionProvider.get().orElse(null));
Function<PluginInfo, String> getVersion = plugin -> plugin.getVersion() == null ? "undefined" : plugin.getVersion().getName();
- Map<String, String> plugins = pluginRepository.getPluginInfos().stream().collect(MoreCollectors.uniqueIndex(PluginInfo::getKey,
- getVersion));
+ Map<String, String> plugins = pluginRepository.getPluginInfos().stream().collect(toMap(PluginInfo::getKey, getVersion));
data.setPlugins(plugins);
try (DbSession dbSession = dbClient.openSession(false)) {
var branchMeasuresDtos = dbClient.branchDao().selectBranchMeasuresWithCaycMetric(dbSession);
diff --git a/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java b/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
index f61242f47e1..8bc2b38bc0f 100644
--- a/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
+++ b/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
@@ -24,17 +24,16 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
+import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.core.util.Uuids;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ProjectData;
import org.sonar.db.permission.GroupPermissionDto;
import org.sonar.db.portfolio.PortfolioDto;
@@ -126,7 +125,7 @@ public class PermissionIndexerDaoIT {
.selectByUuids(dbClient, dbSession,
asList(publicProject.getUuid(), privateProject1.getUuid(), privateProject2.getUuid(), view1.getUuid(), view2.getUuid(), application.getUuid()))
.stream()
- .collect(MoreCollectors.uniqueIndex(IndexPermissions::getEntityUuid, Function.identity()));
+ .collect(Collectors.toMap(IndexPermissions::getEntityUuid, Function.identity()));
Assertions.assertThat(dtos).hasSize(6);
IndexPermissions publicProjectAuthorization = dtos.get(publicProject.getUuid());
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
index 64d5573ff73..9d30e3e5ec0 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
@@ -33,6 +33,7 @@ import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@@ -106,7 +107,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
import static org.sonar.api.rules.RuleType.VULNERABILITY;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.es.EsUtils.escapeSpecialRegexChars;
import static org.sonar.server.es.IndexType.FIELD_INDEX_TYPE;
import static org.sonar.server.es.searchrequest.TopAggregationDefinition.NON_STICKY;
@@ -304,7 +304,7 @@ public class IssueIndex {
}
private static final Map<String, Facet> FACETS_BY_NAME = Arrays.stream(Facet.values())
- .collect(uniqueIndex(Facet::getName));
+ .collect(Collectors.toMap(Facet::getName, Function.identity()));
private static final String SUBSTRING_MATCH_REGEXP = ".*%s.*";
// TODO to be documented
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 00f6bce645f..76cc62d76c7 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.uniqueIndex;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS;
@@ -394,7 +393,7 @@ public class IssueQueryFactory {
Map<String, PeriodStart> leakByProjects = snapshots
.stream()
.filter(s -> s.getPeriodDate() != null && !isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, s))
- .collect(uniqueIndex(SnapshotDto::getRootComponentUuid, s -> new PeriodStart(longToDate(s.getPeriodDate()), false)));
+ .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s1 -> new PeriodStart(longToDate(s1.getPeriodDate()), false)));
builder.createdAfterByProjectUuids(leakByProjects);
builder.newCodeOnReferenceByProjectUuids(newCodeReferenceByProjects);
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
index 5afb31a68f8..b213bcfa800 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
@@ -59,7 +59,6 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.System2;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
@@ -105,7 +104,6 @@ import static org.sonar.api.measures.CoreMetrics.SECURITY_HOTSPOTS_REVIEWED_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_REVIEW_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.es.EsUtils.escapeSpecialRegexChars;
import static org.sonar.server.es.EsUtils.termsToMap;
import static org.sonar.server.es.IndexType.FIELD_INDEX_TYPE;
@@ -204,7 +202,7 @@ public class ProjectMeasuresIndex {
}
private static final Map<String, Facet> FACETS_BY_NAME = Arrays.stream(Facet.values())
- .collect(uniqueIndex(Facet::getName));
+ .collect(Collectors.toMap(Facet::getName, Function.identity()));
private final EsClient client;
private final WebAuthorizationTypeSupport authorizationTypeSupport;
@@ -289,7 +287,7 @@ public class ProjectMeasuresIndex {
Map<String, Long> nclocByLanguage = Stream.of((Nested) response.getAggregations().get(FIELD_NCLOC_DISTRIBUTION))
.map(nested -> (Terms) nested.getAggregations().get(nested.getName() + "_terms"))
.flatMap(terms -> terms.getBuckets().stream())
- .collect(MoreCollectors.uniqueIndex(Bucket::getKeyAsString, bucketToNcloc));
+ .collect(Collectors.toMap(Bucket::getKeyAsString, bucketToNcloc));
statistics.setNclocByLanguage(nclocByLanguage);
return statistics.build();
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 5e31297d933..55100bfbb4d 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
@@ -27,9 +27,9 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.es.EsQueueDto;
@@ -70,7 +70,7 @@ public class PermissionIndexer implements EventIndexer {
this.authorizationScopes = authorizationScopes;
this.indexTypeByFormat = authorizationScopes.stream()
.map(AuthorizationScope::getIndexType)
- .collect(MoreCollectors.uniqueIndex(IndexType.IndexMainType::format, t -> t, authorizationScopes.size()));
+ .collect(Collectors.toMap(IndexType.IndexMainType::format, Function.identity()));
}
@Override
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java
index 26845b14251..054b6638dc9 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.ce.queue;
-import com.google.common.collect.ImmutableMap;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.awt.event.ComponentEvent;
import java.io.InputStream;
@@ -27,6 +26,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
@@ -73,7 +73,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
@@ -291,10 +290,10 @@ public class BranchReportSubmitterIT {
return componentKey;
}
- private static ImmutableMap<String, String> randomNonEmptyMap() {
+ private static Map<String, String> randomNonEmptyMap() {
return IntStream.range(0, 1 + new Random().nextInt(5))
.boxed()
- .collect(uniqueIndex(i -> "key_" + i, i -> "val_" + i));
+ .collect(Collectors.toMap(i -> "key_" + i, i1 -> "val_" + i1));
}
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
index ec0a9ac2a18..edd8ac74eec 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
@@ -22,6 +22,7 @@ package org.sonar.server.ce.queue;
import java.io.InputStream;
import java.util.Map;
import java.util.Random;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
@@ -66,7 +67,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
@@ -114,7 +114,7 @@ public class ReportSubmitterIT {
.thenReturn(true);
Map<String, String> nonEmptyCharacteristics = IntStream.range(0, 1 + new Random().nextInt(5))
.boxed()
- .collect(uniqueIndex(i -> randomAlphabetic(i + 10), i -> randomAlphabetic(i + 20)));
+ .collect(Collectors.toMap(i -> randomAlphabetic(i + 10), i1 -> randomAlphabetic(i1 + 20)));
InputStream reportInput = IOUtils.toInputStream("{binary}", UTF_8);
assertThatThrownBy(() -> underTest.submit(PROJECT_KEY, PROJECT_NAME, nonEmptyCharacteristics, reportInput))
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
index 4c2d0cde547..66551da50c4 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
@@ -33,6 +33,8 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -106,7 +108,6 @@ import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW;
import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newDirectoryOnBranch;
import static org.sonar.db.component.ComponentTesting.newFileDto;
@@ -1109,7 +1110,7 @@ public class SearchActionIT {
assertThat(response.getComponentsList())
.extracting(Component::getKey)
.containsOnly(project.getKey(), directory.getKey(), file.getKey());
- Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
+ Map<String, Component> componentByKey = response.getComponentsList().stream().collect(Collectors.toMap(Component::getKey, Function.identity()));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.getQualifier()).isEqualTo(project.qualifier());
assertThat(actualProject.getName()).isEqualTo(project.name());
@@ -1158,7 +1159,7 @@ public class SearchActionIT {
assertThat(response.getComponentsList())
.extracting(Component::getKey)
.containsOnly(project.getKey(), directory.getKey(), file.getKey());
- Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
+ Map<String, Component> componentByKey = response.getComponentsList().stream().collect(Collectors.toMap(Component::getKey, Function.identity()));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.getBranch()).isEqualTo(branchName);
assertThat(actualProject.hasPullRequest()).isFalse();
@@ -1196,7 +1197,7 @@ public class SearchActionIT {
assertThat(response.getComponentsList())
.extracting(Component::getKey)
.containsOnly(project.getKey(), directory.getKey(), file.getKey());
- Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
+ Map<String, Component> componentByKey = response.getComponentsList().stream().collect(Collectors.toMap(Component::getKey, Function.identity()));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.hasBranch()).isFalse();
assertThat(actualProject.getPullRequest()).isEqualTo(pullRequestKey);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationIT.java
index f252d34add8..0d259e67a3e 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationIT.java
@@ -26,6 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -35,10 +37,9 @@ import org.sonar.api.rules.RulePriority;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile;
-import org.sonar.api.utils.System2;
import org.sonar.api.testfixtures.log.LogTester;
+import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.ActiveRuleDto;
@@ -322,7 +323,7 @@ public class RegisterQualityProfilesNotificationIT {
private static BuiltInQProfile.ActiveRule[] toActiveRules(List<BuiltInActiveRule> rules, RuleDto[] dbRules) {
Map<RuleKey, RuleDto> dbRulesByRuleKey = Arrays.stream(dbRules)
- .collect(MoreCollectors.uniqueIndex(RuleDto::getKey));
+ .collect(Collectors.toMap(RuleDto::getKey, Function.identity()));
return rules.stream()
.map(r -> {
RuleKey ruleKey = RuleKey.of(r.repoKey(), r.ruleKey());
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java
index e61b9ff6417..da214fc9dd4 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java
@@ -25,11 +25,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.junit.rules.ExternalResource;
import org.sonar.api.resources.Language;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.rule.RuleDto;
import static com.google.common.base.Preconditions.checkState;
@@ -90,7 +91,7 @@ public class BuiltInQProfileRepositoryRule extends ExternalResource implements B
.setName(api.name())
.setDeclaredDefault(api.isDefault());
Map<RuleKey, RuleDto> rulesByRuleKey = Arrays.stream(rules)
- .collect(MoreCollectors.uniqueIndex(RuleDto::getKey));
+ .collect(Collectors.toMap(RuleDto::getKey, Function.identity()));
api.rules().forEach(rule -> {
RuleKey ruleKey = RuleKey.of(rule.repoKey(), rule.ruleKey());
RuleDto ruleDto = rulesByRuleKey.get(ruleKey);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
index e644ec8ed8a..4ff24d7362b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
@@ -23,6 +23,8 @@ import com.google.common.io.Resources;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
@@ -46,7 +48,6 @@ import static java.util.Optional.ofNullable;
import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.permission.GlobalPermission.SCAN;
import static org.sonar.server.branch.ws.BranchesWs.addProjectParam;
@@ -93,10 +94,10 @@ public class ListAction implements BranchWsAction {
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao()
.selectByComponentUuidsAndMetricKeys(dbSession, branchUuids, singletonList(ALERT_STATUS_KEY)).stream()
- .collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
+ .collect(Collectors.toMap(LiveMeasureDto::getComponentUuid, Function.identity()));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao()
.selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream()
- .collect(uniqueIndex(SnapshotDto::getRootComponentUuid, s -> formatDateTime(s.getCreatedAt())));
+ .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s -> formatDateTime(s.getCreatedAt())));
ProjectBranches.ListWsResponse.Builder protobufResponse = ProjectBranches.ListWsResponse.newBuilder();
branches.forEach(b -> addBranch(protobufResponse, b, qualityGateMeasuresByComponentUuids.get(b.getUuid()),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java
index 2db2ecd3a13..21f5d7d5dfa 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -48,7 +49,6 @@ import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Optional.ofNullable;
import static org.sonar.api.utils.DateUtils.formatDateTime;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
/**
* Converts {@link CeActivityDto} and {@link CeQueueDto} to the protobuf objects
@@ -179,12 +179,12 @@ public class TaskFormatter {
static DtoCache forQueueDtos(DbClient dbClient, DbSession dbSession, Collection<CeQueueDto> ceQueueDtos) {
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuidsOfCeQueues(ceQueueDtos))
.stream()
- .collect(uniqueIndex(ComponentDto::uuid));
+ .collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao()
.selectByTaskUuids(dbSession, ceQueueDtos.stream().map(CeQueueDto::getUuid).toList())
.stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
Set<String> submitterUuids = ceQueueDtos.stream().map(CeQueueDto::getSubmitterUuid).filter(Objects::nonNull).collect(Collectors.toSet());
- Map<String, UserDto> usersByUuid = dbClient.userDao().selectByUuids(dbSession, submitterUuids).stream().collect(uniqueIndex(UserDto::getUuid));
+ Map<String, UserDto> usersByUuid = dbClient.userDao().selectByUuids(dbSession, submitterUuids).stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
return new DtoCache(componentsByUuid, characteristicsByTaskUuid, usersByUuid);
}
@@ -201,12 +201,12 @@ public class TaskFormatter {
dbSession,
getComponentUuidsOfCeActivities(ceActivityDtos))
.stream()
- .collect(uniqueIndex(ComponentDto::uuid));
+ .collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao()
.selectByTaskUuids(dbSession, ceActivityDtos.stream().map(CeActivityDto::getUuid).toList())
.stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
Set<String> submitterUuids = ceActivityDtos.stream().map(CeActivityDto::getSubmitterUuid).filter(Objects::nonNull).collect(Collectors.toSet());
- Map<String, UserDto> usersByUuid = dbClient.userDao().selectByUuids(dbSession, submitterUuids).stream().collect(uniqueIndex(UserDto::getUuid));
+ Map<String, UserDto> usersByUuid = dbClient.userDao().selectByUuids(dbSession, submitterUuids).stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
return new DtoCache(componentsByUuid, characteristicsByTaskUuid, usersByUuid);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
index ac603725ed7..858be07cc80 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -262,7 +263,7 @@ public class SuggestionsAction implements ComponentsWsAction {
private SuggestionsWsResponse.Builder buildResponse(Set<String> recentlyBrowsedKeys, Set<String> favoriteUuids, ComponentIndexResults componentsPerQualifiers,
List<EntityDto> entities, int coveredItems) {
- Map<String, EntityDto> entitiesByUuids = entities.stream().collect(MoreCollectors.uniqueIndex(EntityDto::getUuid));
+ Map<String, EntityDto> entitiesByUuids = entities.stream().collect(Collectors.toMap(EntityDto::getUuid, Function.identity()));
return toResponse(componentsPerQualifiers, recentlyBrowsedKeys, favoriteUuids, entitiesByUuids, coveredItems);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java
index 3dd7b8b04f3..7257498e38c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java
@@ -42,7 +42,6 @@ import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.Paging;
import org.sonar.api.web.UserRole;
import org.sonar.core.i18n.I18n;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
@@ -66,8 +65,8 @@ import static org.sonar.server.component.ws.ComponentDtoToWsComponent.projectOrA
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
-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_TREE;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
@@ -211,7 +210,7 @@ public class TreeAction implements ComponentsWsAction {
}
return dbClient.componentDao().selectByUuids(dbSession, referenceComponentIds).stream()
- .collect(MoreCollectors.uniqueIndex(ComponentDto::uuid));
+ .collect(Collectors.toMap(ComponentDto::uuid, java.util.function.Function.identity()));
}
private void checkPermissions(ComponentDto baseComponent) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java
index 1e1454f1704..1d31e5c8d6e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -58,7 +59,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Comparator.comparing;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.utils.DateUtils.parseDateTimeQuietly;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.server.developers.ws.UuidFromPairs.fromDates;
@@ -132,7 +132,7 @@ public class SearchEventsAction implements DevelopersWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
List<ProjectDto> authorizedProjects = searchProjects(dbSession, projectKeys);
- Map<String, ProjectDto> projectsByUuid = authorizedProjects.stream().collect(uniqueIndex(ProjectDto::getUuid));
+ Map<String, ProjectDto> projectsByUuid = authorizedProjects.stream().collect(Collectors.toMap(ProjectDto::getUuid, Function.identity()));
List<UuidFromPair> uuidFromPairs = buildUuidFromPairs(fromDates, projectKeys, authorizedProjects);
List<SnapshotDto> analyses = dbClient.snapshotDao().selectFinishedByProjectUuidsAndFromDates(dbSession, projectUuids(uuidFromPairs), fromDates(uuidFromPairs));
@@ -141,7 +141,8 @@ public class SearchEventsAction implements DevelopersWsAction {
}
List<String> branchUuids = analyses.stream().map(SnapshotDto::getRootComponentUuid).toList();
- Map<String, BranchDto> branchesByUuids = dbClient.branchDao().selectByUuids(dbSession, branchUuids).stream().collect(uniqueIndex(BranchDto::getUuid));
+ Map<String, BranchDto> branchesByUuids = dbClient.branchDao().selectByUuids(dbSession, branchUuids)
+ .stream().collect(Collectors.toMap(BranchDto::getUuid, Function.identity()));
return Stream.concat(
computeQualityGateChangeEvents(dbSession, projectsByUuid, branchesByUuids, analyses),
@@ -226,7 +227,7 @@ public class SearchEventsAction implements DevelopersWsAction {
private static List<UuidFromPair> buildUuidFromPairs(List<Long> fromDates, List<String> projectKeys, List<ProjectDto> authorizedProjects) {
checkRequest(projectKeys.size() == fromDates.size(), "The number of components (%s) and from dates (%s) must be the same.", projectKeys.size(), fromDates.size());
Map<String, Long> fromDatesByProjectKey = IntStream.range(0, projectKeys.size()).boxed()
- .collect(uniqueIndex(projectKeys::get, fromDates::get));
+ .collect(Collectors.toMap(projectKeys::get, fromDates::get));
return authorizedProjects.stream()
.map(dto -> new UuidFromPair(dto.getUuid(), fromDatesByProjectKey.get(dto.getKey())))
.toList();
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java
index 424104c802c..c5c4e893d09 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -87,7 +88,6 @@ import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.utils.DateUtils.longToDate;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_INSECURE_INTERACTION;
import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_POROUS_DEFENSES;
@@ -359,7 +359,7 @@ public class SearchAction implements HotspotsWsAction {
List<IssueDto> unorderedHotspots = dbClient.issueDao().selectByKeys(dbSession, issueKeys);
Map<String, IssueDto> hotspotsByKey = unorderedHotspots
.stream()
- .collect(uniqueIndex(IssueDto::getKey, unorderedHotspots.size()));
+ .collect(Collectors.toMap(IssueDto::getKey, Function.identity()));
return issueKeys.stream()
.map(hotspotsByKey::get)
@@ -508,7 +508,7 @@ public class SearchAction implements HotspotsWsAction {
Map<String, IssueQuery.PeriodStart> leakByProjects = snapshots
.stream()
.filter(s -> isNullOrEmpty(s.getPeriodMode()) || !s.getPeriodMode().equals(REFERENCE_BRANCH.name()))
- .collect(uniqueIndex(SnapshotDto::getRootComponentUuid, s -> new IssueQuery.PeriodStart(longToDate(s.getPeriodDate() == null ? now : s.getPeriodDate()), false)));
+ .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s1 -> new IssueQuery.PeriodStart(longToDate(s1.getPeriodDate() == null ? now : s1.getPeriodDate()), false)));
builder.createdAfterByProjectUuids(leakByProjects);
builder.newCodeOnReferenceByProjectUuids(newCodeReferenceByProjects);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java
index e431b951e96..3d98042ed15 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java
@@ -55,7 +55,6 @@ import static java.util.Collections.emptyMap;
import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;
import static org.sonar.api.utils.DateUtils.formatDateTime;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.issue.IssueChangeDto.TYPE_COMMENT;
import static org.sonar.db.issue.IssueChangeDto.TYPE_FIELD_CHANGE;
import static org.sonar.server.issue.IssueFieldsSetter.FILE;
@@ -134,12 +133,10 @@ public class IssueChangeWSSupport {
Multimap<String, IssueChangeDto> unordered = changes.stream()
.collect(MoreCollectors.index(IssueChangeDto::getIssueKey, t -> t));
return unordered.asMap().entrySet().stream()
- .collect(uniqueIndex(
- Map.Entry::getKey,
- t -> t.getValue().stream()
- .map(transform)
- .sorted(sortingComparator)
- .toList()));
+ .collect(Collectors.toMap(Map.Entry::getKey, t -> t.getValue().stream()
+ .map(transform)
+ .sorted(sortingComparator)
+ .toList()));
}
private Map<String, UserDto> loadUsers(DbSession dbSession, Map<String, List<FieldDiffs>> changesByRuleKey,
@@ -165,14 +162,14 @@ public class IssueChangeWSSupport {
if (missingUsersUuids.isEmpty()) {
return preloadedUsers.stream()
.filter(t -> userUuids.contains(t.getUuid()))
- .collect(uniqueIndex(UserDto::getUuid, userUuids.size()));
+ .collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
}
return Stream.concat(
preloadedUsers.stream(),
dbClient.userDao().selectByUuids(dbSession, missingUsersUuids).stream())
.filter(t -> userUuids.contains(t.getUuid()))
- .collect(uniqueIndex(UserDto::getUuid, userUuids.size()));
+ .collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
}
private Map<String, ComponentDto> loadFiles(DbSession dbSession, Map<String, List<FieldDiffs>> changesByRuleKey, Set<ComponentDto> preloadedComponents) {
@@ -197,14 +194,14 @@ public class IssueChangeWSSupport {
if (missingFileUuids.isEmpty()) {
return preloadedComponents.stream()
.filter(t -> fileUuids.contains(t.uuid()))
- .collect(uniqueIndex(ComponentDto::uuid, fileUuids.size()));
+ .collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
}
return Stream.concat(
preloadedComponents.stream(),
dbClient.componentDao().selectByUuids(dbSession, missingFileUuids).stream())
.filter(t -> fileUuids.contains(t.uuid()))
- .collect(uniqueIndex(ComponentDto::uuid, fileUuids.size()));
+ .collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
}
private Map<String, Boolean> loadUpdatableFlag(Map<String, List<IssueChangeDto>> commentsByIssueKey) {
@@ -218,7 +215,7 @@ public class IssueChangeWSSupport {
return commentsByIssueKey.values().stream()
.flatMap(Collection::stream)
- .collect(uniqueIndex(IssueChangeDto::getKey, t -> userUuid.equals(t.getUserUuid())));
+ .collect(Collectors.toMap(IssueChangeDto::getKey, t -> userUuid.equals(t.getUserUuid())));
}
public Stream<Common.Changelog> formatChangelog(IssueDto dto, FormattingContext formattingContext) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
index e45dd7c5107..7f37b26e90f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
@@ -90,7 +90,6 @@ import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
import static org.sonar.core.issue.IssueChangeContext.issueChangeContextByUserBuilder;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.issue.AbstractChangeTagsAction.TAGS_PARAMETER;
import static org.sonar.server.issue.AssignAction.ASSIGNEE_PARAMETER;
@@ -385,16 +384,16 @@ public class BulkChangeAction implements IssuesWsAction {
.toList();
List<ComponentDto> allBranches = getComponents(dbSession, allIssues.stream().map(IssueDto::getProjectUuid).collect(Collectors.toSet()));
- this.branchComponentByUuid = getAuthorizedComponents(allBranches).stream().collect(uniqueIndex(ComponentDto::uuid, identity()));
+ this.branchComponentByUuid = getAuthorizedComponents(allBranches).stream().collect(toMap(ComponentDto::uuid, identity()));
this.branchesByProjectUuid = dbClient.branchDao().selectByUuids(dbSession, branchComponentByUuid.keySet()).stream()
- .collect(uniqueIndex(BranchDto::getUuid, identity()));
+ .collect(toMap(BranchDto::getUuid, identity()));
this.issues = getAuthorizedIssues(allIssues);
this.componentsByUuid = getComponents(dbSession,
issues.stream().map(DefaultIssue::componentUuid).collect(Collectors.toSet())).stream()
- .collect(uniqueIndex(ComponentDto::uuid, identity()));
+ .collect(toMap(ComponentDto::uuid, identity()));
this.rulesByKey = dbClient.ruleDao().selectByKeys(dbSession,
issues.stream().map(DefaultIssue::ruleKey).collect(Collectors.toSet())).stream()
- .collect(uniqueIndex(RuleDto::getKey, identity()));
+ .collect(toMap(RuleDto::getKey, identity()));
this.availableActions = actions.stream()
.filter(action -> propertiesByActions.containsKey(action.key()))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
index 8038a25ff58..843aecd9ed8 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
@@ -73,7 +74,6 @@ import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
import static org.sonar.api.rule.RuleKey.EXTERNAL_RULE_REPO_PREFIX;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.issue.index.IssueIndex.FACET_ASSIGNED_TO_ME;
import static org.sonar.server.issue.index.IssueIndex.FACET_PROJECTS;
import static org.sonar.server.issue.ws.SearchAdditionalField.ACTIONS;
@@ -439,7 +439,7 @@ public class SearchResponseFormat {
return;
}
- Map<String, RuleKey> ruleUuidsByRuleKeys = data.getRules().stream().collect(uniqueIndex(RuleDto::getUuid, RuleDto::getKey));
+ Map<String, RuleKey> ruleUuidsByRuleKeys = data.getRules().stream().collect(Collectors.toMap(RuleDto::getUuid, RuleDto::getKey));
Common.Facet.Builder wsFacet = wsFacets.addFacetsBuilder();
wsFacet.setProperty(PARAM_RULES);
facet.forEach((ruleUuid, count) -> wsFacet.addValuesBuilder()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
index ab751711676..f0b97838fbc 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
@@ -34,7 +34,6 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.rules.RuleType;
import org.sonar.core.issue.DefaultIssue;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
@@ -226,7 +225,7 @@ public class SearchResponseLoader {
Map<String, ComponentDto> componentsByProjectUuid = result.getComponents()
.stream()
.filter(ComponentDto::isRootProject)
- .collect(MoreCollectors.uniqueIndex(ComponentDto::branchUuid));
+ .collect(Collectors.toMap(ComponentDto::branchUuid, Function.identity()));
for (IssueDto issueDto : result.getIssues()) {
// so that IssueDto can be used.
if (fields.contains(ACTIONS)) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
index 0a2d0bf7cd8..166180a7c79 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
@@ -26,6 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.slf4j.LoggerFactory;
import org.sonar.api.config.Configuration;
@@ -49,7 +51,6 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
import static java.util.stream.Collectors.groupingBy;
import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class LiveMeasureComputerImpl implements LiveMeasureComputer {
@@ -112,7 +113,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
private MeasureMatrix loadMeasureMatrix(DbSession dbSession, Set<String> componentUuids, QualityGate qualityGate) {
Collection<String> metricKeys = getKeysOfAllInvolvedMetrics(qualityGate);
- Map<String, MetricDto> metricsPerUuid = dbClient.metricDao().selectByKeys(dbSession, metricKeys).stream().collect(uniqueIndex(MetricDto::getUuid));
+ Map<String, MetricDto> metricsPerUuid = dbClient.metricDao().selectByKeys(dbSession, metricKeys).stream().collect(Collectors.toMap(MetricDto::getUuid, Function.identity()));
List<LiveMeasureDto> measures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, componentUuids, metricsPerUuid.keySet());
return new MeasureMatrix(componentUuids, metricsPerUuid.values(), measures);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
index 827e3971b67..e220f1e3430 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.sonar.api.config.Configuration;
@@ -47,8 +48,6 @@ import org.sonar.server.qualitygate.QualityGateEvaluator;
import org.sonar.server.qualitygate.QualityGateFinder;
import org.sonar.server.qualitygate.QualityGateFinder.QualityGateData;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
-
public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
private final DbClient dbClient;
@@ -66,7 +65,7 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
QualityGateData qg = qGateFinder.getEffectiveQualityGate(dbSession, project);
Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qg.getUuid());
Set<String> metricUuids = conditionDtos.stream().map(QualityGateConditionDto::getMetricUuid).collect(Collectors.toSet());
- Map<String, MetricDto> metricsByUuid = dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream().collect(uniqueIndex(MetricDto::getUuid));
+ Map<String, MetricDto> metricsByUuid = dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream().collect(Collectors.toMap(MetricDto::getUuid, Function.identity()));
Stream<Condition> conditions = conditionDtos.stream().map(conditionDto -> {
String metricKey = metricsByUuid.get(conditionDto.getMetricUuid()).getKey();
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
index a6aa1ae20a4..a5764f6459e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
@@ -23,9 +23,10 @@ import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Function;
import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
@@ -60,8 +61,8 @@ class SearchHistoryResponseFactory {
}
private UnaryOperator<SearchHistoryResponse.Builder> addMeasures() {
- Map<String, MetricDto> metricsByUuid = result.getMetrics().stream().collect(MoreCollectors.uniqueIndex(MetricDto::getUuid));
- Map<String, SnapshotDto> analysesByUuid = result.getAnalyses().stream().collect(MoreCollectors.uniqueIndex(SnapshotDto::getUuid));
+ Map<String, MetricDto> metricsByUuid = result.getMetrics().stream().collect(Collectors.toMap(MetricDto::getUuid, Function.identity()));
+ Map<String, SnapshotDto> analysesByUuid = result.getAnalyses().stream().collect(Collectors.toMap(SnapshotDto::getUuid, Function.identity()));
Table<MetricDto, SnapshotDto, MeasureDto> measuresByMetricByAnalysis = HashBasedTable.create(result.getMetrics().size(), result.getAnalyses().size());
result.getMeasures().forEach(m -> measuresByMetricByAnalysis.put(metricsByUuid.get(m.getMetricUuid()), analysesByUuid.get(m.getAnalysisUuid()), m));
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
index 728f14e378a..27a0d0e3f6d 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
@@ -34,7 +34,6 @@ import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.web.UserRole;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.entity.EntityDto;
@@ -163,7 +162,7 @@ public class ListAction implements NotificationsWsAction {
return dbClient.entityDao().selectByUuids(dbSession, entityUuids)
.stream()
.filter(c -> authorizedProjectUuids.contains(c.getUuid()))
- .collect(MoreCollectors.uniqueIndex(EntityDto::getUuid));
+ .collect(Collectors.toMap(EntityDto::getUuid, Function.identity()));
}
private static Function<PropertyDto, Notification> toWsNotification(Notification.Builder notification, Map<String, EntityDto> projectsByUuid) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java
index bcc90f8524c..c6a746b70c2 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java
@@ -31,7 +31,6 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.Paging;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -166,7 +165,7 @@ public class SearchAction implements ProjectsWsAction {
.collect(Collectors.toMap(ProjectLastAnalysisDateDto::getProjectUuid, ProjectLastAnalysisDateDto::getDate));
Map<String, SnapshotDto> snapshotsByComponentUuid = dbClient.snapshotDao()
.selectLastAnalysesByRootComponentUuids(dbSession, componentUuids).stream()
- .collect(MoreCollectors.uniqueIndex(SnapshotDto::getRootComponentUuid, identity()));
+ .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, identity()));
return buildResponse(components, snapshotsByComponentUuid, lastAnalysisDateByComponentUuid, projectUuidByComponentUuid, paging);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
index 3cc20fc91b8..6c2f03f581c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
@@ -35,7 +35,6 @@ import org.sonar.db.project.ProjectDto;
import static com.google.common.collect.ImmutableList.copyOf;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
class SearchMyProjectsData {
@@ -50,7 +49,7 @@ class SearchMyProjectsData {
this.projects = copyOf(builder.projects);
this.branchUuidByProjectUuids = buildBranchUuidByProjectUuidMap(builder.branches);
this.projectLinksByProjectUuid = buildProjectLinks(builder.projectLinks);
- this.snapshotsByComponentUuid =builder.snapshots.stream().collect(uniqueIndex(SnapshotDto::getRootComponentUuid, identity()));
+ this.snapshotsByComponentUuid =builder.snapshots.stream().collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, identity()));
this.qualityGateStatuses = buildQualityGateStatuses(builder.qualityGates);
this.totalNbOfProject = builder.totalNbOfProjects;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateCaycChecker.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateCaycChecker.java
index 6dcc8a71ee2..58322389702 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateCaycChecker.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateCaycChecker.java
@@ -24,6 +24,8 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.sonar.api.measures.Metric;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -39,7 +41,6 @@ import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING;
import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_HOTSPOTS_REVIEWED;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.qualitygate.QualityGateCaycStatus.COMPLIANT;
import static org.sonar.server.qualitygate.QualityGateCaycStatus.NON_COMPLIANT;
import static org.sonar.server.qualitygate.QualityGateCaycStatus.OVER_COMPLIANT;
@@ -73,7 +74,7 @@ public class QualityGateCaycChecker {
public QualityGateCaycStatus checkCaycCompliant(DbSession dbSession, String qualityGateUuid) {
var conditionsByMetricId = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateUuid)
.stream()
- .collect(uniqueIndex(QualityGateConditionDto::getMetricUuid));
+ .collect(Collectors.toMap(QualityGateConditionDto::getMetricUuid, Function.identity()));
if (conditionsByMetricId.size() < CAYC_METRICS.size()) {
return NON_COMPLIANT;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchGroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchGroupsAction.java
index ffa30688c6c..eb331d952eb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchGroupsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchGroupsAction.java
@@ -21,11 +21,11 @@ package org.sonar.server.qualitygate.ws;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualitygate.QualityGateDto;
@@ -105,7 +105,7 @@ public class SearchGroupsAction implements QualityGatesWsAction {
Map<String, GroupDto> groupsByUuid = dbClient.groupDao().selectByUuids(dbSession,
groupMemberships.stream().map(SearchGroupMembershipDto::getGroupUuid).toList())
.stream()
- .collect(MoreCollectors.uniqueIndex(GroupDto::getUuid));
+ .collect(Collectors.toMap(GroupDto::getUuid, Function.identity()));
writeProtobuf(
Qualitygates.SearchGroupsResponse.newBuilder()
.addAllGroups(groupMemberships.stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchUsersAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchUsersAction.java
index 17eb0271dc7..79605cf7c36 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchUsersAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchUsersAction.java
@@ -21,6 +21,7 @@ package org.sonar.server.qualitygate.ws;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
@@ -45,7 +46,6 @@ import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.api.server.ws.WebService.SelectionMode.ALL;
import static org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED;
import static org.sonar.api.server.ws.WebService.SelectionMode.fromParam;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.Pagination.forPage;
import static org.sonar.db.qualitygate.SearchQualityGatePermissionQuery.builder;
import static org.sonar.db.user.SearchPermissionQuery.ANY;
@@ -108,7 +108,7 @@ public class SearchUsersAction implements QualityGatesWsAction {
List<SearchUserMembershipDto> usersMembership = dbClient.qualityGateUserPermissionDao().selectByQuery(dbSession, query,
forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize()));
Map<String, UserDto> usersById = dbClient.userDao().selectByUuids(dbSession, usersMembership.stream().map(SearchUserMembershipDto::getUserUuid).toList())
- .stream().collect(uniqueIndex(UserDto::getUuid));
+ .stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
writeProtobuf(
SearchUsersResponse.newBuilder()
.addAllUsers(usersMembership.stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
index 398699b46f5..69eafd56a70 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
@@ -41,7 +41,6 @@ import org.sonarqube.ws.Qualitygates.ShowWsResponse;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Optional.ofNullable;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
@@ -103,7 +102,7 @@ public class ShowAction implements QualityGatesWsAction {
private Map<String, MetricDto> getMetricsByUuid(DbSession dbSession, Collection<QualityGateConditionDto> conditions) {
Set<String> metricUuids = conditions.stream().map(QualityGateConditionDto::getMetricUuid).collect(Collectors.toSet());
- return dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream().filter(MetricDto::isEnabled).collect(uniqueIndex(MetricDto::getUuid));
+ return dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream().filter(MetricDto::isEnabled).collect(Collectors.toMap(MetricDto::getUuid, Function.identity()));
}
private ShowWsResponse buildResponse(DbSession dbSession, QualityGateDto qualityGate, QualityGateDto defaultQualityGate, Collection<QualityGateConditionDto> conditions,
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
index b795da34c92..14fb87c9870 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.ArrayUtils;
@@ -46,7 +47,6 @@ import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.ValidationMessages;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
@@ -167,7 +167,7 @@ public class QProfileExporters {
private List<ActiveRuleChange> importProfile(QProfileDto profile, RulesProfile definition, DbSession dbSession) {
Map<RuleKey, RuleDto> rulesByRuleKey = dbClient.ruleDao().selectAll(dbSession)
.stream()
- .collect(MoreCollectors.uniqueIndex(RuleDto::getKey));
+ .collect(Collectors.toMap(RuleDto::getKey, Function.identity()));
List<ActiveRule> activeRules = definition.getActiveRules();
List<RuleActivation> activations = activeRules.stream()
.map(activeRule -> toRuleActivation(activeRule, rulesByRuleKey))
@@ -200,7 +200,7 @@ public class QProfileExporters {
}
String severity = activeRule.getSeverity().name();
Map<String, String> params = activeRule.getActiveRuleParams().stream()
- .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue));
+ .collect(Collectors.toMap(ActiveRuleParam::getKey, ActiveRuleParam::getValue));
return RuleActivation.create(ruleDto.getUuid(), severity, params);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
index 158c829f36c..03eab5fc21c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
@@ -39,7 +39,6 @@ import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
@@ -130,7 +129,7 @@ public class RegisterQualityProfiles implements Startable {
private Map<QProfileName, RulesProfileDto> loadPersistedProfiles(DbSession dbSession) {
return dbClient.qualityProfileDao().selectBuiltInRuleProfiles(dbSession).stream()
- .collect(MoreCollectors.uniqueIndex(rp -> new QProfileName(rp.getLanguage(), rp.getName())));
+ .collect(toMap(rp -> new QProfileName(rp.getLanguage(), rp.getName()), Function.identity()));
}
private void create(DbSession dbSession, DbSession batchDbSession, BuiltInQProfile builtIn) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java
index f3bf2aaf393..4787bde7201 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.rule.RuleKey;
@@ -35,7 +36,6 @@ import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
@@ -152,7 +152,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
private List<ActiveRuleParamDto> insertActiveRuleParams(DbSession session, BuiltInQProfile.ActiveRule activeRule, ActiveRuleDto activeRuleDto) {
Map<String, String> valuesByParamKey = activeRule.getParams().stream()
- .collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
+ .collect(Collectors.toMap(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
List<ActiveRuleParamDto> rules = ruleRepository.getRuleParams(activeRule.getRuleKey()).stream()
.map(param -> createParamDto(param, Optional.ofNullable(valuesByParamKey.get(param.getName())).orElse(param.getDefaultValue())))
.filter(Objects::nonNull)
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java
index 1a759efff0f..c09109115b6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java
@@ -133,9 +133,7 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository
Map<String, List<BuiltInQProfile.Builder>> buildersByLanguage = rulesProfilesByLanguage
.entrySet()
.stream()
- .collect(MoreCollectors.uniqueIndex(
- Map.Entry::getKey,
- rulesProfilesByLanguageAndName -> toQualityProfileBuilders(rulesProfilesByLanguageAndName, rulesByRuleKey)));
+ .collect(Collectors.toMap(Map.Entry::getKey, rulesProfilesByLanguageAndName -> toQualityProfileBuilders(rulesProfilesByLanguageAndName, rulesByRuleKey)));
return buildersByLanguage
.entrySet()
.stream()
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 30bb63dd1bc..aeb72f1a246 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
@@ -27,7 +27,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
@@ -90,7 +89,7 @@ public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
private static RuleActivation convert(BuiltInQProfile.ActiveRule ar) {
Map<String, String> params = ar.getParams().stream()
- .collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
+ .collect(Collectors.toMap(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
return RuleActivation.create(ar.getRuleUuid(), ar.getSeverity(), params);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java
index 08b4ea02b67..0f0728b259b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.sonar.api.rule.RuleKey;
@@ -41,7 +42,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.sonar.core.util.stream.MoreCollectors.index;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
/**
@@ -312,7 +312,7 @@ public class RuleActivationContext {
private RuleWrapper(RuleDto rule, Collection<RuleParamDto> params) {
this.rule = rule;
- this.paramsByKey = params.stream().collect(uniqueIndex(RuleParamDto::getName));
+ this.paramsByKey = params.stream().collect(Collectors.toMap(RuleParamDto::getName, Function.identity()));
}
public RuleDto get() {
@@ -341,7 +341,7 @@ public class RuleActivationContext {
private ActiveRuleWrapper(ActiveRuleDto activeRule, Collection<ActiveRuleParamDto> params) {
this.activeRule = activeRule;
- this.paramsByKey = params.stream().collect(uniqueIndex(ActiveRuleParamDto::getKey));
+ this.paramsByKey = params.stream().collect(Collectors.toMap(ActiveRuleParamDto::getKey, Function.identity()));
}
ActiveRuleDto get() {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
index 2ba0d70c810..57b3a8b902b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.sonar.api.resources.Languages;
@@ -46,7 +47,6 @@ import org.sonar.db.user.UserDto;
import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SINCE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO;
@@ -126,7 +126,7 @@ public class ChangelogAction implements QProfileWsAction {
return dbClient.userDao()
.selectByUuids(dbSession, userUuids)
.stream()
- .collect(uniqueIndex(UserDto::getUuid));
+ .collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
}
private Map<String, RuleDto> getRulesByRuleUuids(DbSession dbSession, List<Change> changes) {
@@ -137,7 +137,7 @@ public class ChangelogAction implements QProfileWsAction {
return dbClient.ruleDao()
.selectByUuids(dbSession, Lists.newArrayList(ruleUuids))
.stream()
- .collect(uniqueIndex(RuleDto::getUuid));
+ .collect(Collectors.toMap(RuleDto::getUuid, Function.identity()));
}
private static void writeResponse(JsonWriter json, int total, int page, int pageSize, List<Change> changelogs,
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
index fe01fbaff19..b3aeca93536 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
@@ -38,7 +38,6 @@ import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.project.ProjectDto;
@@ -217,7 +216,7 @@ public class SearchAction implements QProfileWsAction {
}
Map<String, QProfileDto> effectiveProfiles = defaultProfiles.stream().collect(Collectors.toMap(QProfileDto::getLanguage, identity()));
effectiveProfiles.putAll(dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguages(dbSession, project, getLanguageKeys()).stream()
- .collect(MoreCollectors.uniqueIndex(QProfileDto::getLanguage)));
+ .collect(Collectors.toMap(QProfileDto::getLanguage, identity())));
return p -> Objects.equals(p.getKee(), effectiveProfiles.get(p.getLanguage()).getKee());
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java
index 8aab38b248b..2affb67286b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java
@@ -22,13 +22,13 @@ package org.sonar.server.qualityprofile.ws;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QProfileDto;
@@ -118,7 +118,7 @@ public class SearchGroupsAction implements QProfileWsAction {
Map<String, GroupDto> groupsByUuid = dbClient.groupDao().selectByUuids(dbSession,
groupMemberships.stream().map(SearchGroupMembershipDto::getGroupUuid).toList())
.stream()
- .collect(MoreCollectors.uniqueIndex(GroupDto::getUuid));
+ .collect(Collectors.toMap(GroupDto::getUuid, Function.identity()));
writeProtobuf(
Qualityprofiles.SearchGroupsResponse.newBuilder()
.addAllGroups(groupMemberships.stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java
index 54ce029eac4..d2525aef6cf 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
@@ -49,7 +50,6 @@ import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.api.server.ws.WebService.SelectionMode.ALL;
import static org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED;
import static org.sonar.api.server.ws.WebService.SelectionMode.fromParam;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.Pagination.forPage;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.ANY;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.IN;
@@ -122,7 +122,7 @@ public class SearchUsersAction implements QProfileWsAction {
List<SearchUserMembershipDto> usersMembership = dbClient.qProfileEditUsersDao().selectByQuery(dbSession, query,
forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize()));
Map<String, UserDto> usersById = dbClient.userDao().selectByUuids(dbSession, usersMembership.stream().map(SearchUserMembershipDto::getUserUuid).toList())
- .stream().collect(uniqueIndex(UserDto::getUuid));
+ .stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
writeProtobuf(
SearchUsersResponse.newBuilder()
.addAllUsers(usersMembership.stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
index 98209cd182d..1b63f21856c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
@@ -55,7 +55,6 @@ import org.sonarqube.ws.Rules.SearchResponse;
import static com.google.common.base.Strings.nullToEmpty;
import static java.util.Collections.singletonList;
import static java.util.Optional.ofNullable;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
/**
* Add details about active rules to api/rules/search and api/rules/show
@@ -86,7 +85,7 @@ public class ActiveRuleCompleter {
// Load details of active rules on the selected profile
List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByProfile(dbSession, profile);
Map<RuleKey, OrgActiveRuleDto> activeRuleByRuleKey = activeRules.stream()
- .collect(uniqueIndex(ActiveRuleDto::getRuleKey));
+ .collect(Collectors.toMap(ActiveRuleDto::getRuleKey, Function.identity()));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = loadParams(dbSession, activeRules);
for (RuleDto rule : rules) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java
index 0aa417e98e5..58702cedae1 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
@@ -45,7 +46,6 @@ import static org.sonar.api.server.ws.WebService.Param.SORT;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVATION;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVE_SEVERITIES;
@@ -88,7 +88,7 @@ public class RuleWsSupport {
Map<String, UserDto> getUsersByUuid(DbSession dbSession, List<RuleDto> rules) {
Set<String> userUuids = rules.stream().map(RuleDto::getNoteUserUuid).filter(Objects::nonNull).collect(Collectors.toSet());
- return dbClient.userDao().selectByUuids(dbSession, userUuids).stream().collect(uniqueIndex(UserDto::getUuid));
+ return dbClient.userDao().selectByUuids(dbSession, userUuids).stream().collect(Collectors.toMap(UserDto::getUuid, Function.identity()));
}
public static void defineGenericRuleSearchParameters(WebService.NewAction action) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
index d170b27c5cc..fec04e75fd7 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
@@ -25,7 +25,9 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.config.Configuration;
import org.sonar.api.resources.Qualifiers;
@@ -67,7 +69,6 @@ import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
@@ -253,7 +254,7 @@ public class ComponentAction implements NavigationWsAction {
.orElse(emptySortedSet());
Map<String, QProfileDto> dtoByQPKey = dbClient.qualityProfileDao().selectByUuids(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).toList())
.stream()
- .collect(uniqueIndex(QProfileDto::getKee));
+ .collect(Collectors.toMap(QProfileDto::getKee, Function.identity()));
json.name("qualityProfiles").beginArray();
qualityProfiles.forEach(qp -> writeToJson(json, qp, !dtoByQPKey.containsKey(qp.getQpKey())));
json.endArray();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java
index 5edf31cf7df..8f825538eb6 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java
@@ -24,6 +24,7 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.util.Collections;
import java.util.Map;
import java.util.Random;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,7 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
@RunWith(DataProviderRunner.class)
public class BranchSupportTest {
@@ -109,6 +109,6 @@ public class BranchSupportTest {
}
private static Map<String, String> newRandomNonEmptyMap() {
- return IntStream.range(0, 1 + new Random().nextInt(10)).boxed().collect(uniqueIndex(i -> "key_" + i, i -> "val_" + i));
+ return IntStream.range(0, 1 + new Random().nextInt(10)).boxed().collect(Collectors.toMap(i -> "key_" + i, i1 -> "val_" + i1));
}
}