diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2023-01-12 15:07:29 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-01-13 20:02:46 +0000 |
commit | b6cb156530b5012f589d097fbbe84b855391accc (patch) | |
tree | f2e9484644bef2e38c29712da190875863346cb5 | |
parent | c9aa7b5f35066a7c2e3583eb679062d142977beb (diff) | |
download | sonarqube-b6cb156530b5012f589d097fbbe84b855391accc.tar.gz sonarqube-b6cb156530b5012f589d097fbbe84b855391accc.zip |
[NO-JIRA] explicitly declare toList collector mutable or not
5 files changed, 13 insertions, 13 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 fe7fdd6179a..b124b509c02 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 @@ -138,7 +138,7 @@ public class CeQueueImpl implements CeQueue { List<CeQueueDto> taskDtos = submissions.stream() .filter(filterBySubmitOptions(options, submissions, dbSession)) .map(submission -> addToQueueInDb(dbSession, submission)) - .collect(Collectors.toList()); + .toList(); List<CeTask> tasks = loadTasks(dbSession, taskDtos); dbSession.commit(); return tasks; diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java index c5005990651..d331d3c477b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java @@ -46,7 +46,7 @@ public class TokenExpirationNotificationSender { try (var dbSession = dbClient.openSession(false)) { var expiringTokens = dbClient.userTokenDao().selectTokensExpiredInDays(dbSession, 7); var expiredTokens = dbClient.userTokenDao().selectTokensExpiredInDays(dbSession, 0); - var tokensToNotify = Stream.concat(expiringTokens.stream(), expiredTokens.stream()).collect(Collectors.toList()); + var tokensToNotify = Stream.concat(expiringTokens.stream(), expiredTokens.stream()).toList(); var usersToNotify = tokensToNotify.stream().map(UserTokenDto::getUserUuid).collect(Collectors.toSet()); Map<String, String> userUuidToEmail = dbClient.userDao().selectByUuids(dbSession, usersToNotify).stream() .collect(Collectors.toMap(UserDto::getUuid, UserDto::getEmail)); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java index a0a4b8f0206..8918d48bd2a 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java @@ -41,6 +41,7 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.SnapshotDto; +import static java.util.stream.Collectors.toCollection; import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY; import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY; import static org.sonar.db.ce.CeTaskCharacteristicDto.PULL_REQUEST; @@ -75,7 +76,7 @@ public class AsyncIssueIndexingImpl implements AsyncIssueIndexing { return; } - List<String> projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(Collectors.toList()); + List<String> projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(toCollection(ArrayList<String>::new)); LOG.info("{} projects found in need of issue sync.", projectUuids.size()); sortProjectUuids(dbSession, projectUuids); 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 0eddf3ffe48..ab823443523 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 @@ -99,7 +99,7 @@ import org.springframework.util.CollectionUtils; import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toCollection; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.existsQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; @@ -1245,7 +1245,8 @@ public class IssueIndex { List<SecurityStandardCategoryStatistics> children = new ArrayList<>(); if (includeDistribution) { Stream<? extends Terms.Bucket> stream = ((ParsedStringTerms) categoryBucket.getAggregations().get(AGG_DISTRIBUTION)).getBuckets().stream(); - children = stream.map(cweBucket -> processSecurityReportCategorySearchResults(cweBucket, cweBucket.getKeyAsString(), null, null)).collect(toList()); + children = stream.map(cweBucket -> processSecurityReportCategorySearchResults(cweBucket, cweBucket.getKeyAsString(), null, null)) + .collect(toCollection(ArrayList<SecurityStandardCategoryStatistics>::new)); } return processSecurityReportCategorySearchResults(categoryBucket, categoryBucket.getName(), children, version); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java index a43fbf2c29a..6061483b15a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java @@ -20,11 +20,10 @@ package org.sonar.server.setting.ws; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableTable; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.config.PropertyDefinition; @@ -97,18 +96,17 @@ public class Setting { if (propertySets.isEmpty()) { return Collections.emptyList(); } - ImmutableTable.Builder<String, String, String> tableBuilder = new ImmutableTable.Builder<>(); + Map<String, Map<String, String>> table = new HashMap<>(); propertySets.forEach(property -> { String keyWithoutSettingKey = property.getKey().replace(propertyKey + ".", ""); List<String> setIdWithFieldKey = DOT_SPLITTER.splitToList(keyWithoutSettingKey); String setId = setIdWithFieldKey.get(0); String fieldKey = keyWithoutSettingKey.replaceFirst(setId + ".", ""); - tableBuilder.put(setId, fieldKey, property.getValue()); + table.computeIfAbsent(setId, k -> new HashMap<>()).put(fieldKey, property.getValue()); }); - ImmutableTable<String, String, String> table = tableBuilder.build(); - return table.rowKeySet().stream() - .map(table::row) - .collect(Collectors.toList()); + return table.keySet().stream() + .map(table::get) + .toList(); } } |