Skip to content

Commit

Permalink
Use EnumMap where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 18, 2024
1 parent 91488be commit ec4d4db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.jenkins.plugins.coverage.metrics.color;

import java.awt.*;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -34,7 +34,12 @@ public class ColorProvider {
* The color mapping to be used
*/
ColorProvider(final Map<ColorId, DisplayColors> colorMapping) {
availableColors = new HashMap<>(colorMapping);
if (colorMapping.isEmpty()) {
availableColors = new EnumMap<>(ColorId.class);
}
else {
availableColors = new EnumMap<>(colorMapping);
}
}

/**
Expand All @@ -52,7 +57,7 @@ public static Color blendColors(final Color color1, final Color color2) {
}

/**
* Blends two colors using weights that have to be greater then zero.
* Blends two colors using weights that have to be greater than zero.
*
* @param color1
* The first color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.awt.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -45,7 +45,7 @@ public static ColorProvider createColorProvider(final Map<String, String> colors
if (!colors.keySet().equals(CoverageColorJenkinsId.getAll()) || !verifyHexCodes(colors.values())) {
return createDefaultColorProvider();
}
Map<ColorId, DisplayColors> colorMap = new HashMap<>();
Map<ColorId, DisplayColors> colorMap = new EnumMap<>(ColorId.class);
// TODO: use dynamic text color (not provided yet)
colorMap.put(ColorId.INSUFFICIENT,
createDisplayColor(colors.get(CoverageColorJenkinsId.RED.getJenkinsColorId()), "#ffffff"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -473,7 +473,7 @@ private static void failStage(final ResultHandler resultHandler, final LogHandle

private Map<Parser, List<ModuleNode>> recordCoverageResults(final Run<?, ?> run, final FilePath workspace,
final ResultHandler resultHandler, final FilteredLog log, final LogHandler logHandler) throws InterruptedException {
Map<Parser, List<ModuleNode>> results = new HashMap<>();
Map<Parser, List<ModuleNode>> results = new EnumMap<>(Parser.class);

for (CoverageTool tool : tools) {
Parser parser = tool.getParser();
Expand Down

0 comments on commit ec4d4db

Please sign in to comment.