MsFlex extends AbstractCssProperty<MsFlex> implements StateChangeInformer<CssProperty> { public MsFlex setFlexBasis(final FlexBasis flexBasis) { if (flexBasis == null) { throw new InvalidValueException("flexBasis cannot be null"); } if (Objects.equals(this.flexBasis, flexBasis)) { 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 (flexShrink == null) { flexShrink = new FlexShrink(1); flexShrink.setStateChangeInformer(this); flexShrink.setAlreadyInUse(true); } cssValueBuilder.append(flexShrink.getCssValue()).append(' '); if (this.flexBasis != null) { this.flexBasis.setCssValue(flexBasis.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "copied the cssValue from the given flexBasis to the existing flexBasis object."); } } else { if (flexBasis.isAlreadyInUse()) { this.flexBasis = new FlexBasis(flexBasis); this.flexBasis.setAlreadyInUse(true); this.flexBasis.setStateChangeInformer(this); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "created a new object of FlexBasis as the given flexBasis object is already used by another object"); } } else { this.flexBasis = flexBasis; this.flexBasis.setAlreadyInUse(true); this.flexBasis.setStateChangeInformer(this); } } cssValue = cssValueBuilder.append(flexBasis.getCssValue()).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 testSetFlexBasis() { final MsFlex flex = new MsFlex("6 5 25px"); final FlexBasis flexBasis1 = flex.getFlexBasis(); final FlexBasis flexBasis2 = new FlexBasis(2, CssLengthUnit.PX); flex.setFlexBasis(flexBasis2); assertEquals("6.0 5.0 2.0px", flex.getCssValue()); assertNotNull(flex.getFlexGrow()); assertEquals("6.0", flex.getFlexGrow().getCssValue()); assertNotNull(flex.getFlexShrink()); assertEquals("5.0", flex.getFlexShrink().getCssValue()); assertNotNull(flex.getFlexBasis()); assertEquals("2.0px", flex.getFlexBasis().getCssValue()); assertNotEquals(flexBasis1, flexBasis2); assertNotEquals(flexBasis2, flex.getFlexBasis()); assertEquals(flexBasis1, flex.getFlexBasis()); flex.setFlexBasis(flexBasis1); }