Flex extends AbstractCssProperty<Flex> implements StateChangeInformer<CssProperty> { public Flex setFlexGrow(final FlexGrow flexGrow) { if (flexGrow == null) { throw new InvalidValueException("flexGrow cannot be null"); } if (this.flexGrow == flexGrow) { return this; } final StringBuilder cssValueBuilder = new StringBuilder(); if (this.flexGrow != null) { this.flexGrow.setCssValue(flexGrow.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "copied the cssValue from the given flexGrow to the existing flexGrow object."); } } else { if (flexGrow.isAlreadyInUse()) { this.flexGrow = new FlexGrow(flexGrow); this.flexGrow.setAlreadyInUse(true); this.flexGrow.setStateChangeInformer(this); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "created a new object of FlexGrow as the given flexGrow object is already used by another object"); } } else { this.flexGrow = flexGrow; this.flexGrow.setAlreadyInUse(true); this.flexGrow.setStateChangeInformer(this); } } cssValueBuilder.append(flexGrow.getCssValue()).append(' '); if (flexShrink == null) { flexShrink = new FlexShrink(1); flexShrink.setStateChangeInformer(this); flexShrink.setAlreadyInUse(true); } cssValueBuilder.append(flexShrink.getCssValue()).append(' '); if (flexBasis == null) { flexBasis = new FlexBasis(0); flexBasis.setStateChangeInformer(this); flexBasis.setAlreadyInUse(true); } cssValueBuilder.append(flexBasis.getCssValue()); cssValue = cssValueBuilder.toString(); if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } return this; } Flex();  Flex(final String cssValue);  Flex(final Flex flex); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); @Override Flex setCssValue(final String cssValue); static boolean isValid(final String cssValue); void setAsInitial(); void setAsInherit(); void setAsAuto(); FlexBasis getFlexBasis(); FlexShrink getFlexShrink(); FlexGrow getFlexGrow(); Flex setFlexGrow(final FlexGrow flexGrow); Flex setFlexShrink(final FlexShrink flexShrink); Flex setFlexBasis(final FlexBasis flexBasis); @Override void stateChanged(final CssProperty stateChangedObject); static final String INITIAL; static final String INHERIT; static final String AUTO; }
@Test public void testSetFlexGrow() { final Flex flex = new Flex("6 5 25px"); final FlexGrow flexGrow1 = flex.getFlexGrow(); final FlexGrow flexGrow2 = new FlexGrow(2); flex.setFlexGrow(flexGrow2); assertEquals("2.0 5.0 25px", flex.getCssValue()); assertNotNull(flex.getFlexGrow()); assertEquals("2.0", flex.getFlexGrow().getCssValue()); assertNotNull(flex.getFlexShrink()); assertEquals("5.0", flex.getFlexShrink().getCssValue()); assertNotNull(flex.getFlexBasis()); assertEquals("25px", flex.getFlexBasis().getCssValue()); assertNotEquals(flexGrow1, flexGrow2); assertNotEquals(flexGrow2, flex.getFlexGrow()); assertEquals(flexGrow1, flex.getFlexGrow()); flex.setFlexGrow(flexGrow1); }