@@ -53,39 +53,52 @@ public class Option implements Cloneable, Serializable {
5353 */
5454 public static final class Builder {
5555
56- /** The name of the option . */
57- private String option ;
56+ /** The default type . */
57+ private static final Class < String > DEFAULT_TYPE = String . class ;
5858
59- /** Description of the option. */
60- private String description ;
59+ /**
60+ * Returns the input Class or the default type (String) if null.
61+ *
62+ * @param type the candidate Class.
63+ * @return the input Class or the default type (String) if null.
64+ */
65+ private static Class <?> toType (final Class <?> type ) {
66+ return type != null ? type : DEFAULT_TYPE ;
67+ }
6168
62- /** The long representation of the option. */
63- private String longOption ;
69+ /** The number of argument values this option can have . */
70+ private int argCount = UNINITIALIZED ;
6471
6572 /** The name of the argument for this option. */
6673 private String argName ;
6774
75+ /** The converter to convert to type. **/
76+ private Converter <?, ?> converter ;
77+
6878 /** Specifies whether this option is deprecated. */
6979 private DeprecatedAttributes deprecated ;
7080
71- /** Specifies whether this option is required to be present. */
72- private boolean required ;
81+ /** Description of the option. */
82+ private String description ;
83+
84+ /** The long representation of the option. */
85+ private String longOption ;
86+
87+ /** The name of the option. */
88+ private String option ;
7389
7490 /** Specifies whether the argument value of this Option is optional. */
7591 private boolean optionalArg ;
7692
77- /** The number of argument values this option can have . */
78- private int argCount = UNINITIALIZED ;
93+ /** Specifies whether this option is required to be present . */
94+ private boolean required ;
7995
8096 /** The type of this Option. */
81- private Class <?> type = String . class ;
97+ private Class <?> type = DEFAULT_TYPE ;
8298
8399 /** The character that is the value separator. */
84100 private char valueSeparator ;
85101
86- /** The converter to convert to type. **/
87- private Converter <?, ?> converter ;
88-
89102 /**
90103 * Constructs a new {@code Builder} with the minimum required parameters for an {@code Option} instance.
91104 *
@@ -276,7 +289,7 @@ public Builder required(final boolean required) {
276289 * @return this builder.
277290 */
278291 public Builder type (final Class <?> type ) {
279- this .type = type ;
292+ this .type = toType ( type ) ;
280293 return this ;
281294 }
282295
@@ -316,18 +329,18 @@ public Builder valueSeparator(final char valueSeparator) {
316329
317330 }
318331
332+ /** Empty array. */
333+ static final Option [] EMPTY_ARRAY = {};
334+
335+ /** The serial version UID. */
336+ private static final long serialVersionUID = 1L ;
337+
319338 /** Specifies the number of argument values has not been specified. */
320339 public static final int UNINITIALIZED = -1 ;
321340
322341 /** Specifies the number of argument values is infinite. */
323342 public static final int UNLIMITED_VALUES = -2 ;
324343
325- /** The serial version UID. */
326- private static final long serialVersionUID = 1L ;
327-
328- /** Empty array. */
329- static final Option [] EMPTY_ARRAY = {};
330-
331344 /**
332345 * Returns a {@link Builder} to create an {@link Option} using descriptive methods.
333346 *
@@ -350,17 +363,14 @@ public static Builder builder(final String option) {
350363 return new Builder (option );
351364 }
352365
353- /** The name of the option. */
354- private final String option ;
355-
356- /** The long representation of the option. */
357- private String longOption ;
366+ /** The number of argument values this option can have. */
367+ private int argCount = UNINITIALIZED ;
358368
359369 /** The name of the argument for this option. */
360370 private String argName ;
361371
362- /** Description of the option. */
363- private String description ;
372+ /** The explicit converter for this option. May be null . */
373+ private transient Converter <?, ?> converter ;
364374
365375 /**
366376 * Specifies whether this option is deprecated, may be null.
@@ -370,14 +380,20 @@ public static Builder builder(final String option) {
370380 */
371381 private final transient DeprecatedAttributes deprecated ;
372382
373- /** Specifies whether this option is required to be present. */
374- private boolean required ;
383+ /** Description of the option. */
384+ private String description ;
385+
386+ /** The long representation of the option. */
387+ private String longOption ;
388+
389+ /** The name of the option. */
390+ private final String option ;
375391
376392 /** Specifies whether the argument value of this Option is optional. */
377393 private boolean optionalArg ;
378394
379- /** The number of argument values this option can have . */
380- private int argCount = UNINITIALIZED ;
395+ /** Specifies whether this option is required to be present . */
396+ private boolean required ;
381397
382398 /** The type of this Option. */
383399 private Class <?> type = String .class ;
@@ -388,9 +404,6 @@ public static Builder builder(final String option) {
388404 /** The character that is the value separator. */
389405 private char valuesep ;
390406
391- /** The explicit converter for this option. May be null. */
392- private transient Converter <?, ?> converter ;
393-
394407 /**
395408 * Private constructor used by the nested Builder class.
396409 *
@@ -932,7 +945,7 @@ public void setRequired(final boolean required) {
932945 * @since 1.3
933946 */
934947 public void setType (final Class <?> type ) {
935- this .type = type ;
948+ this .type = Builder . toType ( type ) ;
936949 }
937950
938951 /**
@@ -997,11 +1010,13 @@ public String toString() {
9971010 } else if (hasArg ()) {
9981011 buf .append (" [ARG]" );
9991012 }
1000- buf .append (" :: " ).append (description );
1001- if (type != null ) {
1002- buf .append (" :: " ).append (type );
1003- }
1004- buf .append (" ]" );
1005- return buf .toString ();
1013+ // @formatter:off
1014+ return buf .append (" :: " )
1015+ .append (description )
1016+ .append (" :: " )
1017+ .append (type )
1018+ .append (" ]" )
1019+ .toString ();
1020+ // @formatter:on
10061021 }
10071022}
0 commit comments