@Test public void canDetectInvalidHtmlColor() { LabelToColorMapping mapping = new LabelToColorMapping(); Color c = mapping.parseStandardHtmlColor("foo"); Assert.assertNull("Should have received null, since 'foo' is not a standard html color", c); }
public Color parseStandardHtmlColor(String someKindOfColorDescription) { Color c = standardHtmlColorNames.get( someKindOfColorDescription.toLowerCase() ); if (c==null) { if (someKindOfColorDescription.trim().startsWith("#") && someKindOfColorDescription.length() >= 2) { String hexColor = someKindOfColorDescription.substring(1); int intColor = Integer.parseInt(hexColor,16); if (intColor >0 && intColor < 0x1010000) { c = new Color(intColor); } } } return c; }
LabelToColorMapping { public Color parseStandardHtmlColor(String someKindOfColorDescription) { Color c = standardHtmlColorNames.get( someKindOfColorDescription.toLowerCase() ); if (c==null) { if (someKindOfColorDescription.trim().startsWith("#") && someKindOfColorDescription.length() >= 2) { String hexColor = someKindOfColorDescription.substring(1); int intColor = Integer.parseInt(hexColor,16); if (intColor >0 && intColor < 0x1010000) { c = new Color(intColor); } } } return c; } }
LabelToColorMapping { public Color parseStandardHtmlColor(String someKindOfColorDescription) { Color c = standardHtmlColorNames.get( someKindOfColorDescription.toLowerCase() ); if (c==null) { if (someKindOfColorDescription.trim().startsWith("#") && someKindOfColorDescription.length() >= 2) { String hexColor = someKindOfColorDescription.substring(1); int intColor = Integer.parseInt(hexColor,16); if (intColor >0 && intColor < 0x1010000) { c = new Color(intColor); } } } return c; } LabelToColorMapping(); }
LabelToColorMapping { public Color parseStandardHtmlColor(String someKindOfColorDescription) { Color c = standardHtmlColorNames.get( someKindOfColorDescription.toLowerCase() ); if (c==null) { if (someKindOfColorDescription.trim().startsWith("#") && someKindOfColorDescription.length() >= 2) { String hexColor = someKindOfColorDescription.substring(1); int intColor = Integer.parseInt(hexColor,16); if (intColor >0 && intColor < 0x1010000) { c = new Color(intColor); } } } return c; } LabelToColorMapping(); Color parseStandardHtmlColor(String someKindOfColorDescription); void addStandardHtmlColor(String colorName, Color c); Color getColorForLabel(String label); void addMapping(String label, Color c); static LabelToColorMapping load(String colorConfigString); }
LabelToColorMapping { public Color parseStandardHtmlColor(String someKindOfColorDescription) { Color c = standardHtmlColorNames.get( someKindOfColorDescription.toLowerCase() ); if (c==null) { if (someKindOfColorDescription.trim().startsWith("#") && someKindOfColorDescription.length() >= 2) { String hexColor = someKindOfColorDescription.substring(1); int intColor = Integer.parseInt(hexColor,16); if (intColor >0 && intColor < 0x1010000) { c = new Color(intColor); } } } return c; } LabelToColorMapping(); Color parseStandardHtmlColor(String someKindOfColorDescription); void addStandardHtmlColor(String colorName, Color c); Color getColorForLabel(String label); void addMapping(String label, Color c); static LabelToColorMapping load(String colorConfigString);  }