]> source.dussan.org Git - sonarqube.git/commitdiff
[NO-JIRA] explicitly declare toList collector mutable or not
authorZipeng WU <zipeng.wu@sonarsource.com>
Thu, 12 Jan 2023 14:07:29 +0000 (15:07 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 13 Jan 2023 20:02:46 +0000 (20:02 +0000)
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java
server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java

index fe7fdd6179a355f8dc4557b84082f7679c8f373b..b124b509c02154b4cffdd64eb487138722598b03 100644 (file)
@@ -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;
index c5005990651c3ae8a054879fbbeeacabaefc767c..d331d3c477ba74a3420fd8a38a0f8297f5eee8b6 100644 (file)
@@ -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));
index a0a4b8f0206c4a19e9ced77cca27d25d0152da55..8918d48bd2a61cfc3dd98d7402b1e1fed50613c6 100644 (file)
@@ -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);
index 0eddf3ffe482aac3b11d4c025b4493c73328b619..ab82344352366f74c97986f08e44a1f3484748b4 100644 (file)
@@ -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);
index a43fbf2c29a030a4e68c8ba00fbf9b1edd91d057..6061483b15a68fde6a1dc7ecf0ca50cd04362ccb 100644 (file)
 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();
   }
 
 }