ColorConverter { @Nonnull public static ColorRGB8 toColorRGB(@Nonnull final String colorCSS) throws IllegalArgumentException { assert colorCSS != null; final String value = colorCSS.trim().toUpperCase(); if (value.length() < COLOR_MIN_LENGTH) { throw new IllegalArgumentException("Expected format: #RRGGBB"); } if (value.charAt(0) != '#') { throw new IllegalArgumentException("Should start with '#'"); } if (value.length() > COLOR_MAX_LENGTH) { throw new IllegalArgumentException( "Length should be [" + COLOR_MIN_LENGTH + "src/main" + COLOR_MAX_LENGTH + ']'); } int total = 0; int factor = 1; int i = value.length() - 1; while (i >= 1) { final char ch = value.charAt(i); final int val = Character.digit(ch, 16); if (val < 0) { throw new IllegalArgumentException("Unrecognized hex digit: " + ch); } total = total + (val * factor); factor = factor * 16; --i; } return new ColorRGB8(total); } private  ColorConverter(); @Nonnull static ColorRGB8 toColorRGB(@Nonnull final String colorCSS); @Nonnull static String toColorCSS(@Nonnull final ColorRGB8 colorRGB8); static final int COLOR_MIN_LENGTH; static final int COLOR_MAX_LENGTH; }
@Test public void testToColorRGB() { LOG.info("testToColorRGB"); final ColorRGB8 c1 = new ColorRGB8(1, 2, 3); Assert.assertEquals(c1, ColorConverter.toColorRGB("#010203")); }