commit 2db67d1fcdaba34dbe91b7f17d0a419c7f0283d4
Author: Simon Legner <Simon.Legner@gmail.com>
Date:   2020-03-21 15:21:39 +0100

    fix #18961 - ColorHelper: harmonize color functions

diff --git a/src/org/openstreetmap/josm/gui/SelectionManager.java b/src/org/openstreetmap/josm/gui/SelectionManager.java
index 8a82c1b85..a6022b1f7 100644
--- a/src/org/openstreetmap/josm/gui/SelectionManager.java
+++ b/src/org/openstreetmap/josm/gui/SelectionManager.java
@@ -25,7 +25,7 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
-import org.openstreetmap.josm.tools.Utils;
+import org.openstreetmap.josm.tools.ColorHelper;
 
 /**
  * Manages the selection of a rectangle or a lasso loop. Listening to left and right mouse button
@@ -82,7 +82,7 @@
         public void paint(Graphics2D g, MapView mv, Bounds bbox) {
             if (mousePos == null || mousePosStart == null || mousePos == mousePosStart)
                 return;
-            Color color = Utils.complement(PaintColors.getBackgroundColor());
+            Color color = ColorHelper.complement(PaintColors.getBackgroundColor());
             g.setColor(color);
             if (lassoMode) {
                 g.drawPolygon(lasso);
diff --git a/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java b/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
index 57591e752..e08739c92 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
@@ -74,6 +74,7 @@
 import org.openstreetmap.josm.gui.widgets.JosmTextArea;
 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
 import org.openstreetmap.josm.gui.widgets.ScrollableTable;
+import org.openstreetmap.josm.tools.ColorHelper;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.ImageOverlay;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -611,7 +612,7 @@ private JPanel buildInfoPanel(StyleSource s) {
                 text.append(tableRow(tr("Icon:"), s.icon));
             }
             if (s.getBackgroundColorOverride() != null) {
-                text.append(tableRow(tr("Background:"), Utils.toString(s.getBackgroundColorOverride())));
+                text.append(tableRow(tr("Background:"), ColorHelper.color2html(s.getBackgroundColorOverride())));
             }
             text.append(tableRow(tr("Style is currently active?"), s.active ? tr("Yes") : tr("No")))
                 .append("</table>");
diff --git a/src/org/openstreetmap/josm/gui/mappaint/Cascade.java b/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
index ea74f1a08..922f771b5 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
@@ -14,7 +14,6 @@
 import org.openstreetmap.josm.tools.ColorHelper;
 import org.openstreetmap.josm.tools.GenericParser;
 import org.openstreetmap.josm.tools.Logging;
-import org.openstreetmap.josm.tools.Utils;
 
 /**
  * Simple map of properties with dynamic typing.
@@ -250,7 +249,7 @@ public String toString() {
             if (val instanceof float[]) {
                 sb.append(Arrays.toString((float[]) val));
             } else if (val instanceof Color) {
-                sb.append(Utils.toString((Color) val));
+                sb.append(ColorHelper.color2html((Color) val));
             } else if (val != null) {
                 sb.append(val);
             }
diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
index 891f59d98..79cbcb539 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
@@ -270,7 +270,7 @@ public static String color2html(Color c) { // NO_UCD (unused code)
      * @see java.awt.Color#getRed()
      */
     public static float red(Color c) { // NO_UCD (unused code)
-        return Utils.colorInt2float(c.getRed());
+        return ColorHelper.int2float(c.getRed());
     }
 
     /**
@@ -280,7 +280,7 @@ public static float red(Color c) { // NO_UCD (unused code)
      * @see java.awt.Color#getGreen()
      */
     public static float green(Color c) { // NO_UCD (unused code)
-        return Utils.colorInt2float(c.getGreen());
+        return ColorHelper.int2float(c.getGreen());
     }
 
     /**
@@ -290,7 +290,7 @@ public static float green(Color c) { // NO_UCD (unused code)
      * @see java.awt.Color#getBlue()
      */
     public static float blue(Color c) { // NO_UCD (unused code)
-        return Utils.colorInt2float(c.getBlue());
+        return ColorHelper.int2float(c.getBlue());
     }
 
     /**
@@ -300,7 +300,7 @@ public static float blue(Color c) { // NO_UCD (unused code)
      * @see java.awt.Color#getAlpha()
      */
     public static float alpha(Color c) { // NO_UCD (unused code)
-        return Utils.colorInt2float(c.getAlpha());
+        return ColorHelper.int2float(c.getAlpha());
     }
 
     /**
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java
index 37ab21944..bf3dac9bf 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java
@@ -17,6 +17,7 @@
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
 import org.openstreetmap.josm.spi.preferences.Config;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.ColorHelper;
 import org.openstreetmap.josm.tools.HiDPISupport;
 import org.openstreetmap.josm.tools.Utils;
 import org.openstreetmap.josm.tools.bugreport.BugReport;
@@ -95,16 +96,16 @@ public static AreaElement create(final Environment env) {
             }
 
             fillImage.alpha = Utils.clamp(Config.getPref().getInt("mappaint.fill-image-alpha", 255), 0, 255);
-            Integer pAlpha = Utils.colorFloat2int(c.get(FILL_OPACITY, null, float.class));
+            Integer pAlpha = ColorHelper.float2int(c.get(FILL_OPACITY, null, float.class));
             if (pAlpha != null) {
                 fillImage.alpha = pAlpha;
             }
         } else {
             color = c.get(FILL_COLOR, null, Color.class);
             if (color != null) {
-                float defaultOpacity = Utils.colorInt2float(DEFAULT_FILL_ALPHA.get());
+                float defaultOpacity = ColorHelper.int2float(DEFAULT_FILL_ALPHA.get());
                 float opacity = c.get(FILL_OPACITY, defaultOpacity, Float.class);
-                color = Utils.alphaMultiply(color, opacity);
+                color = ColorHelper.alphaMultiply(color, opacity);
             }
         }
 
@@ -158,7 +159,7 @@ public int hashCode() {
 
     @Override
     public String toString() {
-        return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) +
+        return "AreaElemStyle{" + super.toString() + "color=" + ColorHelper.color2html(color) +
                 " fillImage=[" + fillImage + "] extent=[" + extent + "] extentThreshold=[" + extentThreshold + "]}";
     }
 }
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java
index 4afc24b0a..d035fc3f2 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java
@@ -19,8 +19,8 @@
 import org.openstreetmap.josm.gui.mappaint.Keyword;
 import org.openstreetmap.josm.gui.mappaint.MultiCascade;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat;
+import org.openstreetmap.josm.tools.ColorHelper;
 import org.openstreetmap.josm.tools.Logging;
-import org.openstreetmap.josm.tools.Utils;
 
 /**
  * This is the style definition for a simple line.
@@ -234,10 +234,10 @@ public int hashCode() {
     @Override
     public String toString() {
         return "LineElemStyle{" + super.toString() + "width=" + line.getLineWidth() +
-            " realWidth=" + realWidth + " color=" + Utils.toString(color) +
+            " realWidth=" + realWidth + " color=" + ColorHelper.color2html(color) +
             " dashed=" + Arrays.toString(line.getDashArray()) +
             (line.getDashPhase() == 0 ? "" : " dashesOffses=" + line.getDashPhase()) +
-            " dashedColor=" + Utils.toString(dashesBackground) +
+            " dashedColor=" + ColorHelper.color2html(dashesBackground) +
             " linejoin=" + linejoinToString(line.getLineJoin()) +
             " linecap=" + linecapToString(line.getEndCap()) +
             (offset == 0 ? "" : " offset=" + offset) +
@@ -333,7 +333,7 @@ private static LineElement createImpl(Environment env, LineType type) {
             color = PaintColors.UNTAGGED.get();
         }
 
-        Integer pAlpha = Utils.colorFloat2int(c.get(type.prefix + OPACITY, null, Float.class));
+        Integer pAlpha = ColorHelper.float2int(c.get(type.prefix + OPACITY, null, Float.class));
         if (pAlpha != null) {
             alpha = pAlpha;
         }
@@ -362,7 +362,7 @@ private static LineElement createImpl(Environment env, LineType type) {
         }
         Color dashesBackground = c.get(type.prefix + DASHES_BACKGROUND_COLOR, null, Color.class);
         if (dashesBackground != null) {
-            pAlpha = Utils.colorFloat2int(c.get(type.prefix + DASHES_BACKGROUND_OPACITY, null, Float.class));
+            pAlpha = ColorHelper.float2int(c.get(type.prefix + DASHES_BACKGROUND_OPACITY, null, Float.class));
             if (pAlpha != null) {
                 alpha = pAlpha;
             }
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
index 238254cb6..f447f0177 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
@@ -21,10 +21,10 @@
 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProvider;
 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProviderResult;
 import org.openstreetmap.josm.gui.util.GuiHelper;
+import org.openstreetmap.josm.tools.ColorHelper;
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.ImageResource;
 import org.openstreetmap.josm.tools.Logging;
-import org.openstreetmap.josm.tools.Utils;
 
 /**
  * An image that will be displayed on the map.
@@ -214,7 +214,7 @@ public int getHeight() {
      * @return The value in range 0..1
      */
     public float getAlphaFloat() {
-        return Utils.colorInt2float(alpha);
+        return ColorHelper.int2float(alpha);
     }
 
     /**
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
index a0a184537..8a3bbd897 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
@@ -23,6 +23,7 @@
 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.SimpleBoxProvider;
 import org.openstreetmap.josm.spi.preferences.Config;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.ColorHelper;
 import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.RotationAngle;
 import org.openstreetmap.josm.tools.Utils;
@@ -167,7 +168,7 @@ public static MapImage createIcon(final Environment env, final String... keys) {
         mapImage.offsetY = Math.round(offsetYF);
 
         mapImage.alpha = Utils.clamp(Config.getPref().getInt("mappaint.icon-image-alpha", 255), 0, 255);
-        Integer pAlpha = Utils.colorFloat2int(c.get(keys[ICON_OPACITY_IDX], null, float.class));
+        Integer pAlpha = ColorHelper.float2int(c.get(keys[ICON_OPACITY_IDX], null, float.class));
         if (pAlpha != null) {
             mapImage.alpha = pAlpha;
         }
@@ -212,7 +213,7 @@ private static Symbol createSymbol(Environment env) {
 
         Stroke stroke = null;
         if (strokeColor != null && strokeWidth != null) {
-            Integer strokeAlpha = Utils.colorFloat2int(c.get("symbol-stroke-opacity", null, Float.class));
+            Integer strokeAlpha = ColorHelper.float2int(c.get("symbol-stroke-opacity", null, Float.class));
             if (strokeAlpha != null) {
                 strokeColor = new Color(strokeColor.getRed(), strokeColor.getGreen(),
                         strokeColor.getBlue(), strokeAlpha);
@@ -226,7 +227,7 @@ private static Symbol createSymbol(Environment env) {
         }
 
         if (fillColor != null) {
-            Integer fillAlpha = Utils.colorFloat2int(c.get("symbol-fill-opacity", null, Float.class));
+            Integer fillAlpha = ColorHelper.float2int(c.get("symbol-fill-opacity", null, Float.class));
             if (fillAlpha != null) {
                 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(),
                         fillColor.getBlue(), fillAlpha);
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
index 829385f8a..befca5c33 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
@@ -17,7 +17,7 @@
 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy;
 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
-import org.openstreetmap.josm.tools.Utils;
+import org.openstreetmap.josm.tools.ColorHelper;
 
 /**
  * Represents the rendering style for a textual label placed somewhere on the map.
@@ -139,7 +139,7 @@ public static TextLabel create(Environment env, Color defaultTextColor, boolean
 
         Color color = c.get(TEXT_COLOR, defaultTextColor, Color.class);
         float alpha = c.get(TEXT_OPACITY, 1f, Float.class);
-        color = Utils.alphaMultiply(color, alpha);
+        color = ColorHelper.alphaMultiply(color, alpha);
 
         Float haloRadius = c.get(TEXT_HALO_RADIUS, null, Float.class);
         if (haloRadius != null && haloRadius <= 0) {
@@ -147,9 +147,9 @@ public static TextLabel create(Environment env, Color defaultTextColor, boolean
         }
         Color haloColor = null;
         if (haloRadius != null) {
-            haloColor = c.get(TEXT_HALO_COLOR, Utils.complement(color), Color.class);
+            haloColor = c.get(TEXT_HALO_COLOR, ColorHelper.complement(color), Color.class);
             float haloAlphaFactor = c.get(TEXT_HALO_OPACITY, 1f, Float.class);
-            haloColor = Utils.alphaMultiply(haloColor, haloAlphaFactor);
+            haloColor = ColorHelper.alphaMultiply(haloColor, haloAlphaFactor);
         }
 
         return new TextLabel(strategy, font, color, haloRadius, haloColor);
@@ -198,7 +198,7 @@ protected String toStringImpl() {
         StringBuilder sb = new StringBuilder(96);
         sb.append("labelCompositionStrategy=").append(labelCompositionStrategy)
           .append(" font=").append(font)
-          .append(" color=").append(Utils.toString(color));
+          .append(" color=").append(ColorHelper.color2html(color));
         if (haloRadius != null) {
             sb.append(" haloRadius=").append(haloRadius)
               .append(" haloColor=").append(haloColor);
diff --git a/src/org/openstreetmap/josm/tools/ColorHelper.java b/src/org/openstreetmap/josm/tools/ColorHelper.java
index ac824a41f..eb654238c 100644
--- a/src/org/openstreetmap/josm/tools/ColorHelper.java
+++ b/src/org/openstreetmap/josm/tools/ColorHelper.java
@@ -2,7 +2,6 @@
 package org.openstreetmap.josm.tools;
 
 import java.awt.Color;
-import java.util.Locale;
 
 /**
  * Helper to convert from color to HTML string and back.
@@ -38,11 +37,6 @@ public static Color html2color(String html) {
         }
     }
 
-    private static String int2hex(int i) {
-        String s = Integer.toHexString(i / 16) + Integer.toHexString(i % 16);
-        return s.toUpperCase(Locale.ENGLISH);
-    }
-
     /**
      * Returns the HTML color code (6 or 8 digit).
      * @param col The color to convert
@@ -54,22 +48,18 @@ public static String color2html(Color col) {
 
     /**
      * Returns the HTML color code (6 or 8 digit).
-     * @param col The color to convert
+     * @param color The color to convert
      * @param withAlpha if {@code true} and alpha value &lt; 255, return 8-digit color code, else always 6-digit
      * @return the HTML color code (6 or 8 digit)
      * @since 6655
      */
-    public static String color2html(Color col, boolean withAlpha) {
-        if (col == null)
+    public static String color2html(Color color, boolean withAlpha) {
+        if (color == null)
             return null;
-        String code = '#'+int2hex(col.getRed())+int2hex(col.getGreen())+int2hex(col.getBlue());
-        if (withAlpha) {
-            int alpha = col.getAlpha();
-            if (alpha < 255) {
-                code += int2hex(alpha);
-            }
-        }
-        return code;
+        int alpha = color.getAlpha();
+        return withAlpha && alpha != 255
+                ? String.format("#%06X%02X", color.getRGB() & 0x00ffffff, alpha)
+                : String.format("#%06X", color.getRGB() & 0x00ffffff);
     }
 
     /**
@@ -85,4 +75,55 @@ public static Color getForegroundColor(Color bg) {
               (bg.getRed()*0.299 + bg.getGreen()*0.587 + bg.getBlue()*0.114) > 186 ?
                   Color.BLACK : Color.WHITE;
     }
+
+    /**
+     * convert float range 0 &lt;= x &lt;= 1 to integer range 0..255
+     * when dealing with colors and color alpha value
+     * @param val float value between 0 and 1
+     * @return null if val is null, the corresponding int if val is in the
+     *         range 0...1. If val is outside that range, return 255
+     */
+    public static Integer float2int(Float val) {
+        if (val == null)
+            return null;
+        if (val < 0 || val > 1)
+            return 255;
+        return (int) (255f * val + 0.5f);
+    }
+
+    /**
+     * convert integer range 0..255 to float range 0 &lt;= x &lt;= 1
+     * when dealing with colors and color alpha value
+     * @param val integer value
+     * @return corresponding float value in range 0 &lt;= x &lt;= 1
+     */
+    public static Float int2float(Integer val) {
+        if (val == null)
+            return null;
+        if (val < 0 || val > 255)
+            return 1f;
+        return ((float) val) / 255f;
+    }
+
+    /**
+     * Multiply the alpha value of the given color with the factor. The alpha value is clamped to 0..255
+     * @param color The color
+     * @param alphaFactor The factor to multiply alpha with.
+     * @return The new color.
+     * @since 11692
+     */
+    public static Color alphaMultiply(Color color, float alphaFactor) {
+        int alpha = float2int(int2float(color.getAlpha()) * alphaFactor);
+        alpha = Utils.clamp(alpha, 0, 255);
+        return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
+    }
+
+    /**
+     * Returns the complementary color of {@code clr}.
+     * @param clr the color to complement
+     * @return the complementary color of {@code clr}
+     */
+    public static Color complement(Color clr) {
+        return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
+    }
 }
diff --git a/src/org/openstreetmap/josm/tools/Utils.java b/src/org/openstreetmap/josm/tools/Utils.java
index aa15d7214..84fbef5cd 100644
--- a/src/org/openstreetmap/josm/tools/Utils.java
+++ b/src/org/openstreetmap/josm/tools/Utils.java
@@ -5,7 +5,6 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 import static org.openstreetmap.josm.tools.I18n.trn;
 
-import java.awt.Color;
 import java.awt.Font;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
@@ -256,72 +255,6 @@ public static String joinAsHtmlUnorderedList(Iterable<?> values) {
         return StreamUtils.toStream(values).map(Object::toString).collect(StreamUtils.toHtmlList());
     }
 
-    /**
-     * convert Color to String
-     * (Color.toString() omits alpha value)
-     * @param c the color
-     * @return the String representation, including alpha
-     */
-    public static String toString(Color c) {
-        if (c == null)
-            return "null";
-        if (c.getAlpha() == 255)
-            return String.format("#%06x", c.getRGB() & 0x00ffffff);
-        else
-            return String.format("#%06x(alpha=%d)", c.getRGB() & 0x00ffffff, c.getAlpha());
-    }
-
-    /**
-     * convert float range 0 &lt;= x &lt;= 1 to integer range 0..255
-     * when dealing with colors and color alpha value
-     * @param val float value between 0 and 1
-     * @return null if val is null, the corresponding int if val is in the
-     *         range 0...1. If val is outside that range, return 255
-     */
-    public static Integer colorFloat2int(Float val) {
-        if (val == null)
-            return null;
-        if (val < 0 || val > 1)
-            return 255;
-        return (int) (255f * val + 0.5f);
-    }
-
-    /**
-     * convert integer range 0..255 to float range 0 &lt;= x &lt;= 1
-     * when dealing with colors and color alpha value
-     * @param val integer value
-     * @return corresponding float value in range 0 &lt;= x &lt;= 1
-     */
-    public static Float colorInt2float(Integer val) {
-        if (val == null)
-            return null;
-        if (val < 0 || val > 255)
-            return 1f;
-        return ((float) val) / 255f;
-    }
-
-    /**
-     * Multiply the alpha value of the given color with the factor. The alpha value is clamped to 0..255
-     * @param color The color
-     * @param alphaFactor The factor to multiply alpha with.
-     * @return The new color.
-     * @since 11692
-     */
-    public static Color alphaMultiply(Color color, float alphaFactor) {
-        int alpha = Utils.colorFloat2int(Utils.colorInt2float(color.getAlpha()) * alphaFactor);
-        alpha = clamp(alpha, 0, 255);
-        return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
-    }
-
-    /**
-     * Returns the complementary color of {@code clr}.
-     * @param clr the color to complement
-     * @return the complementary color of {@code clr}
-     */
-    public static Color complement(Color clr) {
-        return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
-    }
-
     /**
      * Copies the given array. Unlike {@link Arrays#copyOf}, this method is null-safe.
      * @param <T> type of items
diff --git a/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java b/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java
index 1921bb7aa..5020add46 100644
--- a/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java
+++ b/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java
@@ -13,6 +13,34 @@
  */
 public class ColorHelperTest {
 
+    /**
+     * Unit test of method {@link ColorHelper#html2color}.
+     */
+    @Test
+    public void testHtml2color() {
+        assertNull(ColorHelper.html2color(""));
+        assertNull(ColorHelper.html2color("xyz"));
+        assertEquals(Color.CYAN, ColorHelper.html2color("0ff"));
+        assertEquals(Color.CYAN, ColorHelper.html2color("#0ff"));
+        assertEquals(Color.CYAN, ColorHelper.html2color("00ffff"));
+        assertEquals(Color.CYAN, ColorHelper.html2color("#00ffff"));
+        assertEquals(Color.CYAN, ColorHelper.html2color("#00FFFF"));
+        assertEquals(new Color(0x12345678, true), ColorHelper.html2color("#34567812"));
+    }
+
+    /**
+     * Unit test of method {@link ColorHelper#color2html}.
+     */
+    @Test
+    public void testColor2html() {
+        assertNull(ColorHelper.color2html(null));
+        assertEquals("#FF0000", ColorHelper.color2html(Color.RED));
+        assertEquals("#00FFFF", ColorHelper.color2html(Color.CYAN));
+        assertEquals("#34567812", ColorHelper.color2html(new Color(0x12345678, true)));
+        assertEquals("#34567812", ColorHelper.color2html(new Color(0x12345678, true), true));
+        assertEquals("#345678", ColorHelper.color2html(new Color(0x12345678, true), false));
+    }
+
     /**
      * Unit test of method {@link ColorHelper#getForegroundColor}.
      */
@@ -25,4 +53,57 @@ public void testGetForegroundColor() {
         assertEquals(Color.BLACK, ColorHelper.getForegroundColor(Color.YELLOW));
         assertEquals(Color.BLACK, ColorHelper.getForegroundColor(Color.WHITE));
     }
+
+    /**
+     * Test of {@link ColorHelper#float2int}
+     */
+    @Test
+    public void testColorFloat2int() {
+        assertNull(ColorHelper.float2int(null));
+        assertEquals(255, (int) ColorHelper.float2int(-1.0f));
+        assertEquals(0, (int) ColorHelper.float2int(-0.0f));
+        assertEquals(0, (int) ColorHelper.float2int(0.0f));
+        assertEquals(64, (int) ColorHelper.float2int(0.25f));
+        assertEquals(128, (int) ColorHelper.float2int(0.5f));
+        assertEquals(255, (int) ColorHelper.float2int(1.0f));
+        assertEquals(255, (int) ColorHelper.float2int(2.0f));
+    }
+
+    /**
+     * Test of {@link ColorHelper#int2float}
+     */
+    @Test
+    public void testColorInt2float() {
+        assertNull(ColorHelper.int2float(null));
+        assertEquals(1.0f, ColorHelper.int2float(-1), 1e-3);
+        assertEquals(0.0f, ColorHelper.int2float(0), 1e-3);
+        assertEquals(0.25f, ColorHelper.int2float(64), 1e-3);
+        assertEquals(0.502f, ColorHelper.int2float(128), 1e-3);
+        assertEquals(0.753f, ColorHelper.int2float(192), 1e-3);
+        assertEquals(1.0f, ColorHelper.int2float(255), 1e-3);
+        assertEquals(1.0f, ColorHelper.int2float(1024), 1e-3);
+    }
+
+    /**
+     * Test of {@link ColorHelper#alphaMultiply}
+     */
+    @Test
+    public void testAlphaMultiply() {
+        final Color color = new Color(0x12345678, true);
+        assertEquals(new Color(0x12345678, true), ColorHelper.alphaMultiply(color, 1f));
+        assertEquals(new Color(0x24345678, true), ColorHelper.alphaMultiply(color, 2f));
+    }
+
+    /**
+     * Test of {@link ColorHelper#complement}
+     */
+    @Test
+    public void testComplement() {
+        assertEquals(Color.cyan, ColorHelper.complement(Color.red));
+        assertEquals(Color.red, ColorHelper.complement(Color.cyan));
+        assertEquals(Color.magenta, ColorHelper.complement(Color.green));
+        assertEquals(Color.green, ColorHelper.complement(Color.magenta));
+        assertEquals(Color.yellow, ColorHelper.complement(Color.blue));
+        assertEquals(Color.blue, ColorHelper.complement(Color.yellow));
+    }
 }
diff --git a/test/unit/org/openstreetmap/josm/tools/UtilsTest.java b/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
index 0e5f69589..9dc4ca4fd 100644
--- a/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
+++ b/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
@@ -7,7 +7,6 @@
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
-import java.awt.Color;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -413,69 +412,6 @@ public void testFirstNonNull() {
         assertEquals("foo", Utils.firstNonNull(null, "foo", null));
     }
 
-    /**
-     * Test of {@link Utils#toString}
-     */
-    @Test
-    public void testToString() {
-        assertEquals("null", Utils.toString(null));
-        assertEquals("#ff0000", Utils.toString(Color.red));
-        assertEquals("#345678(alpha=18)", Utils.toString(new Color(0x12345678, true)));
-    }
-
-    /**
-     * Test of {@link Utils#colorFloat2int}
-     */
-    @Test
-    public void testColorFloat2int() {
-        assertNull(Utils.colorFloat2int(null));
-        assertEquals(255, (int) Utils.colorFloat2int(-1.0f));
-        assertEquals(0, (int) Utils.colorFloat2int(-0.0f));
-        assertEquals(0, (int) Utils.colorFloat2int(0.0f));
-        assertEquals(64, (int) Utils.colorFloat2int(0.25f));
-        assertEquals(128, (int) Utils.colorFloat2int(0.5f));
-        assertEquals(255, (int) Utils.colorFloat2int(1.0f));
-        assertEquals(255, (int) Utils.colorFloat2int(2.0f));
-    }
-
-    /**
-     * Test of {@link Utils#colorInt2float}
-     */
-    @Test
-    public void testColorInt2float() {
-        assertNull(Utils.colorInt2float(null));
-        assertEquals(1.0f, Utils.colorInt2float(-1), 1e-3);
-        assertEquals(0.0f, Utils.colorInt2float(0), 1e-3);
-        assertEquals(0.25f, Utils.colorInt2float(64), 1e-3);
-        assertEquals(0.502f, Utils.colorInt2float(128), 1e-3);
-        assertEquals(0.753f, Utils.colorInt2float(192), 1e-3);
-        assertEquals(1.0f, Utils.colorInt2float(255), 1e-3);
-        assertEquals(1.0f, Utils.colorInt2float(1024), 1e-3);
-    }
-
-    /**
-     * Test of {@link Utils#alphaMultiply}
-     */
-    @Test
-    public void testAlphaMultiply() {
-        final Color color = new Color(0x12345678, true);
-        assertEquals(new Color(0x12345678, true), Utils.alphaMultiply(color, 1f));
-        assertEquals(new Color(0x24345678, true), Utils.alphaMultiply(color, 2f));
-    }
-
-    /**
-     * Test of {@link Utils#complement}
-     */
-    @Test
-    public void testComplement() {
-        assertEquals(Color.cyan, Utils.complement(Color.red));
-        assertEquals(Color.red, Utils.complement(Color.cyan));
-        assertEquals(Color.magenta, Utils.complement(Color.green));
-        assertEquals(Color.green, Utils.complement(Color.magenta));
-        assertEquals(Color.yellow, Utils.complement(Color.blue));
-        assertEquals(Color.blue, Utils.complement(Color.yellow));
-    }
-
     /**
      * Test of {@link Utils#getMatches}
      */
