@@ -60,49 +60,54 @@ public GraphicBuilder configure(final Configuration config) {
6060 /** {@inheritDoc} */
6161 @ Override
6262 public final GraphicBuilder setSize (final PhysicalDimension size ) {
63- final double w , h ;
63+ GraphicBuilder ._checkSize (size );
64+ this .m_size = size ;
65+ return this ;
66+ }
67+
68+ /**
69+ * Check a size for a graphic.
70+ *
71+ * @param size
72+ * the physical size to check
73+ */
74+ static final void _checkSize (final PhysicalDimension size ) {
75+ final double width , height ;
6476 final ELength sizeUnit ;
65- double r ;
77+ double inMeters ;
78+
79+ if (size == null ) {
80+ throw new IllegalArgumentException (//
81+ "Size of graphic cannot be set to null." );//$NON-NLS-1$
82+ }
6683
67- if ((size == null ) || (( h = size .getHeight ()) <= 0d )
68- || ((w = size .getWidth ()) <= 0d )) {
84+ if ((( height = size .getHeight ()) <= 0d )
85+ || ((width = size .getWidth ()) <= 0d )) {
6986 throw new IllegalArgumentException (//
70- "Invalid graphic size: " + size );//$NON-NLS-1$
87+ "Invalid graphic size: " + size + //$NON-NLS-1$
88+ " - width or height cannot be zero or negative." );//$NON-NLS-1$
7189 }
7290
7391 sizeUnit = size .getUnit ();
74- r = sizeUnit .convertToAsDouble (w , ELength .M );
75- if ((r <= GraphicBuilder .MIN_SIZE_M )
76- || (r >= GraphicBuilder .MAX_SIZE_M )) {
92+ inMeters = sizeUnit .convertToAsDouble (width , ELength .M );
93+ if ((inMeters <= GraphicBuilder .MIN_SIZE_M )
94+ || (inMeters >= GraphicBuilder .MAX_SIZE_M )) {
7795 throw new IllegalArgumentException (//
7896 "A graphic width cannot be smaller than 0.1mm or larger than 10m, but " //$NON-NLS-1$
79- + w + " specified in " + sizeUnit + //$NON-NLS-1$
80- " equals " + r + //$NON-NLS-1$
97+ + width + " specified in " + sizeUnit + //$NON-NLS-1$
98+ " equals " + inMeters + //$NON-NLS-1$
8199 "m." );//$NON-NLS-1$
82100 }
83101
84- r = sizeUnit .convertToAsDouble (h , ELength .M );
85- if ((r <= GraphicBuilder .MIN_SIZE_M )
86- || (r >= GraphicBuilder .MAX_SIZE_M )) {
102+ inMeters = sizeUnit .convertToAsDouble (height , ELength .M );
103+ if ((inMeters <= GraphicBuilder .MIN_SIZE_M )
104+ || (inMeters >= GraphicBuilder .MAX_SIZE_M )) {
87105 throw new IllegalArgumentException (//
88106 "A graphic height cannot be smaller than 0.1mm or larger than 10m, but " //$NON-NLS-1$
89- + h + " specified in " + sizeUnit + //$NON-NLS-1$
90- " equals " + r + //$NON-NLS-1$
107+ + height + " specified in " + sizeUnit + //$NON-NLS-1$
108+ " equals " + inMeters + //$NON-NLS-1$
91109 "m." );//$NON-NLS-1$
92110 }
93-
94- this .m_size = size ;
95- return this ;
96- }
97-
98- /** {@inheritDoc} */
99- @ Override
100- protected void validate () {
101- super .validate ();
102- if (this .m_size == null ) {
103- throw new IllegalArgumentException (//
104- "The size of the graphic must be set." ); //$NON-NLS-1$
105- }
106111 }
107112
108113 /**
@@ -167,7 +172,7 @@ public final GraphicBuilder setQuality(final double quality) {
167172 /** {@inheritDoc} */
168173 @ Override
169174 public final Graphic create () {
170- this . validate ( );
175+ GraphicBuilder . _checkSize ( this . m_size );
171176 return ((AbstractGraphicDriver ) (this .m_config .getGraphicDriver ()))
172177 .createGraphic (this );
173178 }
0 commit comments