Opacity extends AbstractCssProperty<Opacity> { public static boolean isValid(final String cssValue) { final String trimmedCssValue = TagStringUtil .toLowerCase(StringUtil.strip(cssValue)); if (StringUtil.containsSpace(trimmedCssValue)) { return false; } try { final float parsedValue = Float.parseFloat(trimmedCssValue); if (parsedValue < 0 || parsedValue > 1) { return false; } return !(parsedValue == 0 && (StringUtil.containsMinus(trimmedCssValue) || StringUtil.containsPlus(trimmedCssValue))); } catch (final NumberFormatException e) { } return PREDEFINED_CONSTANTS.contains(trimmedCssValue); } Opacity();  Opacity(final String cssValue);  Opacity(final Opacity opacity);  Opacity(final float value); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); Float getValue(); void setValue(final float value); @Override Opacity setCssValue(final String cssValue); void setAsInitial(); void setAsInherit(); static boolean isValid(final String cssValue); static final String INITIAL; static final String INHERIT; }
@Test public void testIsValid() { assertTrue(Opacity.isValid(".5")); assertTrue(Opacity.isValid("0.5")); assertTrue(Opacity.isValid("0.1")); assertTrue(Opacity.isValid("1")); assertTrue(Opacity.isValid("0")); assertTrue(Opacity.isValid(Opacity.INITIAL)); assertTrue(Opacity.isValid(Opacity.INHERIT)); assertFalse(Opacity.isValid("dfd")); assertFalse(Opacity.isValid("1px")); assertFalse(Opacity.isValid("")); assertFalse(Opacity.isValid("1 1")); assertFalse(Opacity.isValid("1.1")); assertFalse(Opacity.isValid("-0.5")); assertFalse(Opacity.isValid("-0")); assertFalse(Opacity.isValid("-0.0")); assertFalse(Opacity.isValid("+0.0")); }