MsFlex extends AbstractCssProperty<MsFlex> implements StateChangeInformer<CssProperty> { public MsFlex setFlexShrink(final FlexShrink flexShrink) { if (flexShrink == null) { throw new InvalidValueException("flexShrink cannot be null"); } if (Objects.equals(this.flexShrink, flexShrink)) { return this; } final StringBuilder cssValueBuilder = new StringBuilder(); if (flexGrow == null) { flexGrow = new FlexGrow(1); flexGrow.setStateChangeInformer(this); flexGrow.setAlreadyInUse(true); } cssValueBuilder.append(flexGrow.getCssValue()).append(' '); if (this.flexShrink != null) { this.flexShrink.setCssValue(flexShrink.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "copied the cssValue from the given flexShrink to the existing flexShrink object."); } } else { if (flexShrink.isAlreadyInUse()) { this.flexShrink = new FlexShrink(flexShrink); this.flexShrink.setAlreadyInUse(true); this.flexShrink.setStateChangeInformer(this); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "created a new object of FlexShrink as the given flexShrink object is already used by another object"); } } else { this.flexShrink = flexShrink; this.flexShrink.setAlreadyInUse(true); this.flexShrink.setStateChangeInformer(this); } } 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; } MsFlex();  MsFlex(final String cssValue);  MsFlex(final MsFlex msFlex); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); @Override MsFlex setCssValue(final String cssValue); static boolean isValid(final String cssValue); void setAsInitial(); void setAsInherit(); void setAsAuto(); FlexBasis getFlexBasis(); FlexShrink getFlexShrink(); FlexGrow getFlexGrow(); MsFlex setFlexGrow(final FlexGrow flexGrow); MsFlex setFlexShrink(final FlexShrink flexShrink); MsFlex 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 testSetFlexShrink() { final MsFlex flex = new MsFlex("6 5 25px"); final FlexShrink flexShrink1 = flex.getFlexShrink(); final FlexShrink flexShrink2 = new FlexShrink(2); flex.setFlexShrink(flexShrink2); assertEquals("6.0 2.0 25px", flex.getCssValue()); assertNotNull(flex.getFlexGrow()); assertEquals("6.0", flex.getFlexGrow().getCssValue()); assertNotNull(flex.getFlexShrink()); assertEquals("2.0", flex.getFlexShrink().getCssValue()); assertNotNull(flex.getFlexBasis()); assertEquals("25px", flex.getFlexBasis().getCssValue()); assertNotEquals(flexShrink1, flexShrink2); assertNotEquals(flexShrink2, flex.getFlexShrink()); assertEquals(flexShrink1, flex.getFlexShrink()); flex.setFlexShrink(flexShrink1); }