package org.sonar.plugins.stash;

import org.sonar.api.issue.Issue;
import org.sonar.api.resources.Project;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public final class StashPluginUtils {

  private StashPluginUtils() {}

  public static String formatPercentage(double d) {

    // Defining that our percentage is precise down to 0.1%
    DecimalFormat df = new DecimalFormat("0.0");

    // Protecting this method against non-US locales that would not use '.' as decimal separation
    DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
    decimalFormatSymbols.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(decimalFormatSymbols);

    // Making sure that we round the 0.1% properly out of the double value
    df.setRoundingMode(RoundingMode.HALF_UP);
    return df.format(d);
  }

  public static boolean roundedPercentageGreaterThan(double left, double right) {
    return (left > right) && !formatPercentage(left).equals(formatPercentage(right));
  }

  public static long countIssuesBySeverity(List<Issue> issues, final String severity) {
    return issues.stream().filter(i -> severity.equals(i.severity())).count();
  }

  public static boolean isProjectWide(Issue issue, Project project) {
    String k = issue.componentKey();
    return (k != null && Objects.equals(k, project.getKey()));
  }
}

@@ -67,49 +67,8 @@
 ue;%0D
-%0Aimport org.sonar.api.resources.Project;%0D
 %0A%0D%0Ai
@@ -175,35 +175,8 @@
 s;%0D%0A
-import java.util.HashMap;%0D%0A
 impo
@@ -199,31 +199,8 @@
 t;%0D%0A
-import java.util.Map;%0D%0A
 impo
@@ -233,35 +233,39 @@
 ort 
-java.util.stream.Collectors
+org.sonar.api.resources.Project
 ;%0D%0A%0D

remove dead imports