Margin extends AbstractCssProperty<Margin> implements StateChangeInformer<CssProperty> { public void setMargin(final MarginTop marginTop, final MarginRight marginRight, final MarginBottom marginBottom, final MarginLeft marginLeft) { if (marginTop != null && marginRight != null && marginBottom != null && marginLeft != null) { if (MarginTop.INITIAL.equals(marginTop.getCssValue()) || MarginTop.INHERIT.equals(marginTop.getCssValue()) || MarginRight.INITIAL.equals(marginRight.getCssValue()) || MarginRight.INHERIT.equals(marginRight.getCssValue()) || MarginBottom.INITIAL.equals(marginBottom.getCssValue()) || MarginBottom.INHERIT.equals(marginBottom.getCssValue()) || MarginLeft.INITIAL.equals(marginLeft.getCssValue()) || MarginLeft.INHERIT.equals(marginLeft.getCssValue())) { throw new InvalidValueException( "Any or all of the given arguments have initial/inherit constant value as its cssValue"); } try { final MarginTop marginTopTemp; final MarginRight marginRightTemp; final MarginBottom marginBottomTemp; final MarginLeft marginLeftTemp; if (this.marginTop != null) { this.marginTop.setAlreadyInUse(false); this.marginRight.setAlreadyInUse(false); this.marginBottom.setAlreadyInUse(false); this.marginLeft.setAlreadyInUse(false); } if (marginTop.isAlreadyInUse() && this.marginTop != marginTop) { if (this.marginTop != null) { marginTopTemp = this.marginTop .setCssValue(marginTop.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginTop is already used by another object so the existing object is used"); } } else { marginTopTemp = marginTop.clone(); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginTop is already used by another object so its clone is assigned"); } } } else { marginTopTemp = marginTop; } if (marginRight.isAlreadyInUse() && this.marginRight != marginRight) { if (this.marginRight != null) { marginRightTemp = this.marginRight .setCssValue(marginTop.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginRight is already used by another object so the existing object is used"); } } else { marginRightTemp = marginRight.clone(); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginRight is already used by another object so its clone is assigned"); } } } else { marginRightTemp = marginRight; } if (marginBottom.isAlreadyInUse() && this.marginBottom != marginBottom) { if (this.marginBottom != null) { marginBottomTemp = this.marginBottom .setCssValue(marginTop.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginBottom is already used by another object so the existing object is used"); } } else { marginBottomTemp = marginBottom.clone(); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginBottom is already used by another object so its clone is assigned"); } } } else { marginBottomTemp = marginBottom; } if (marginLeft.isAlreadyInUse() && this.marginLeft != marginLeft) { if (this.marginLeft != null) { marginLeftTemp = this.marginLeft .setCssValue(marginTop.getCssValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginLeft is already used by another object so the existing object is used"); } } else { marginLeftTemp = marginLeft.clone(); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given marginLeft is already used by another object so its clone is assigned"); } } } else { marginLeftTemp = marginLeft; } marginTopTemp.setAlreadyInUse(true); marginTopTemp.setStateChangeInformer(this); marginRightTemp.setAlreadyInUse(true); marginRightTemp.setStateChangeInformer(this); marginBottomTemp.setAlreadyInUse(true); marginBottomTemp.setStateChangeInformer(this); marginLeftTemp.setAlreadyInUse(true); marginLeftTemp.setStateChangeInformer(this); assignProducedCssValue(marginTop, marginRight, marginBottom, marginLeft); this.marginTop = marginTopTemp; this.marginRight = marginRightTemp; this.marginBottom = marginBottomTemp; this.marginLeft = marginLeftTemp; } catch (final CloneNotSupportedException e) { throw new InvalidValueException(e); } catch (final Exception e) { throw new InvalidValueException(e); } } else { throw new NullValueException("cannot accept null arguments"); } } Margin();  Margin(final String cssValue);  Margin(final Margin marginBottom); Margin setValue(final String value); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); String getValue(); @Override Margin setCssValue(final String cssValue); void setAsInitial(); void setAsInherit(); void setAsAuto(); MarginTop getMarginTop(); void setMargin(final MarginTop marginTop,
            final MarginRight marginRight, final MarginBottom marginBottom,
            final MarginLeft marginLeft); MarginRight getMarginRight(); MarginBottom getMarginBottom(); MarginLeft getMarginLeft(); @Override void stateChanged(final CssProperty stateChangedObject); boolean hasPredefinedConstantValue(); static boolean isValid(final String cssValue); static final String INITIAL; static final String INHERIT; }
@Test(expected = NullValueException.class) public void testSetMarginForNullValues() { Margin margin = new Margin(); MarginTop marginTop = new MarginTop("55px"); MarginRight marginRight = new MarginRight("65px"); MarginBottom marginBottom = new MarginBottom("75px"); MarginLeft marginLeft = new MarginLeft("85px"); try { margin.setMargin(null, null, null, null); } catch (NullValueException e) { try { margin.setMargin(null, marginRight, marginBottom, marginLeft); } catch (NullValueException e2) { try { margin.setMargin(marginTop, null, marginBottom, marginLeft); } catch (NullValueException e3) { try { margin.setMargin(marginTop, marginRight, null, marginLeft); } catch (NullValueException e4) { try { margin.setMargin(marginTop, marginRight, marginBottom, null); } catch (NullValueException e5) { throw e4; } } } } } }