]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12691 Minor refactoring
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 19 Mar 2020 15:16:59 +0000 (10:16 -0500)
committersonartech <sonartech@sonarsource.com>
Mon, 30 Mar 2020 20:03:43 +0000 (20:03 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java

index 2b2064cb8a552f8ed365c03631062ba21ffdaba3..3e2eff15265059e2922157513991923801bb3af0 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.ce.task.projectanalysis.metric;
 
-import com.google.common.base.Function;
+import java.util.function.Function;
 import javax.annotation.Nonnull;
 import org.sonar.ce.task.projectanalysis.measure.Measure;
 import org.sonar.ce.task.projectanalysis.util.cache.DoubleCache;
index 6fb34ba2a9d672986c9cd877edf58066ad3453c7..adc72db9031ff6c48d29db8a9b91eb5d7dfb245c 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.metric;
 
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Collectors;
 import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
 import org.picocontainer.Startable;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.metric.MetricDto;
 
-import static com.google.common.collect.FluentIterable.from;
 import static java.util.Objects.requireNonNull;
 
 public class MetricRepositoryImpl implements MetricRepository, Startable {
@@ -50,8 +47,8 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
   public void start() {
     try (DbSession dbSession = dbClient.openSession(false)) {
       List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession);
-      this.metricsByKey = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToKey.INSTANCE);
-      this.metricsById = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToId.INSTANCE);
+      this.metricsByKey = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(Metric::getKey, x -> x));
+      this.metricsById = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(m -> (long) m.getId(), x -> x));
     }
   }
 
@@ -87,7 +84,7 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
 
   @Override
   public Iterable<Metric> getAll() {
-    return FluentIterable.from(metricsByKey.values()).toSet();
+    return metricsByKey.values();
   }
 
   private void verifyMetricsInitialized() {
@@ -95,25 +92,4 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
       throw new IllegalStateException("Metric cache has not been initialized");
     }
   }
-
-  private enum MetricToKey implements Function<Metric, String> {
-    INSTANCE;
-
-    @Override
-    @Nonnull
-    public String apply(@Nonnull Metric metric) {
-      return metric.getKey();
-    }
-  }
-
-  private enum MetricToId implements Function<Metric, Long> {
-    INSTANCE;
-
-    @Override
-    @Nonnull
-    public Long apply(@Nonnull Metric metric) {
-      return (long) metric.getId();
-    }
-  }
-
 }