]> source.dussan.org Git - sonarqube.git/commitdiff
review
authorPierre Guillot <pierre.guillot@sonarsource.com>
Fri, 8 Nov 2019 15:50:36 +0000 (16:50 +0100)
committerSonarTech <sonartech@sonarsource.com>
Wed, 27 Nov 2019 19:53:09 +0000 (20:53 +0100)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/MigrateNoMoreUsedQualityGateConditions.java

index b7400e07f1005a20fc89011b36e32b7151a50f55..e19563923a72c6b21ff9a3233d351996e5763bfd 100644 (file)
@@ -169,23 +169,11 @@ public class MigrateNoMoreUsedQualityGateConditions extends DataChange {
   }
 
   private static void markConditionsUsingLeakPeriodUsingSameMetricAsOtherConditionOnOverallAsToBeDeleted(List<QualityGateCondition> allConditions) {
-    Map<Integer, List<QualityGateCondition>> conditionsByMetricId = new HashMap<>();
-    for (QualityGateCondition c : allConditions) {
-      if (c.isToBeDeleted()) {
-        return;
-      }
-      int metricId = c.getMetricId();
-      if (!conditionsByMetricId.containsKey(metricId)) {
-        conditionsByMetricId.put(metricId, new ArrayList<>(singletonList(c)));
-      } else {
-        List<QualityGateCondition> qualityGateConditions = conditionsByMetricId.get(metricId);
-        qualityGateConditions.add(c);
-        conditionsByMetricId.put(metricId, qualityGateConditions);
-      }
-    }
+    Map<Integer, List<QualityGateCondition>> conditionsByMetricId = allConditions.stream()
+      .filter(c -> !c.isToBeDeleted())
+      .collect(Collectors.groupingBy(QualityGateCondition::getMetricId));
 
-    for (Map.Entry<Integer, List<QualityGateCondition>> entry : conditionsByMetricId.entrySet()) {
-      List<QualityGateCondition> conditions = entry.getValue();
+    for (List<QualityGateCondition> conditions : conditionsByMetricId.values()) {
       if (conditions.size() > 1) {
         conditions.stream()
           .filter(QualityGateCondition::hasLeakPeriod)