Skip to content

Commit

Permalink
JENKINS-6425 Avoid EnumSet.copyOf of empty sets
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrien committed Apr 25, 2017
1 parent 1cf41b4 commit 1196149
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -351,14 +351,16 @@ public Ratio getCoverageWithEmpty(CoverageMetric metric) {
* @return Value for property 'metrics'.
*/
public Set<CoverageMetric> getMetrics() {
return Collections.unmodifiableSet(EnumSet.copyOf(aggregateResults.keySet()));
return Collections.unmodifiableSet(
aggregateResults.isEmpty() ? EnumSet.noneOf(CoverageMetric.class) : EnumSet.copyOf(aggregateResults.keySet()));
}

public Set<CoverageMetric> getMetricsWithEmpty() {
Map<CoverageMetric, Ratio> currMetricSet = new EnumMap<CoverageMetric, Ratio>(CoverageMetric.class);
currMetricSet.putAll(aggregateResults);
fixEmptyMetrics(findEmptyMetrics(currMetricSet), currMetricSet);
return Collections.unmodifiableSet(EnumSet.copyOf(currMetricSet.keySet()));
return Collections.unmodifiableSet(
currMetricSet.isEmpty() ? EnumSet.noneOf(CoverageMetric.class) : EnumSet.copyOf(currMetricSet.keySet()));
}

private List<CoverageMetric> findEmptyMetrics(Map<CoverageMetric, Ratio> currMetricSet){
Expand Down

0 comments on commit 1196149

Please sign in to comment.