Skip to content

Commit

Permalink
Merge pull request #66 from mbarrien/empty-enumset
Browse files Browse the repository at this point in the history
JENKINS-6425 Avoid EnumSet.copyOf of empty sets
  • Loading branch information
mbarrien committed Apr 25, 2017
2 parents 1cf41b4 + 1196149 commit 2c4f8d9
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 2c4f8d9

Please sign in to comment.