ColorNames { @Pure public static String getColorNameFromValue(int colorValue) { for (final Entry<String, Integer> entry : COLOR_MATCHES.entrySet()) { final int knownValue = entry.getValue().intValue(); if (colorValue == knownValue) { return entry.getKey(); } } return null; } private  ColorNames(); @Pure static Set<String> getColorNames(); @Pure static Map<String, Integer> getColorDefinitions(); @Pure static int getColorFromName(String colorName, int defaultValue); @Pure static Integer getColorFromName(String colorName); @Pure static String getColorNameFromValue(int colorValue); static final String TRANSPARENT; static final String WHITE; static final String LIGHT_GRAY; static final String GRAY; static final String DARK_GRAY; static final String BLACK; static final String RED; static final String PINK; static final String ORANGE; static final String YELLOW; static final String GREEN; static final String MAGENTA; static final String CYAN; static final String BLUE; }
@Test public void getColorNameFromValue() { assertEquals("red", ColorNames.getColorNameFromValue(0xFFFF0000)); assertNull(ColorNames.getColorNameFromValue(0xFF0000)); assertEquals("lime", ColorNames.getColorNameFromValue(0xFF00FF00)); assertNull(ColorNames.getColorNameFromValue(0x00FF00)); assertEquals("blue", ColorNames.getColorNameFromValue(0xFF0000FF)); assertNull(ColorNames.getColorNameFromValue(0x0000FF)); }