@@ -170,23 +170,6 @@ public Object getOptionObject(final String opt) {
170170 }
171171 }
172172
173- /**
174- * Parses a list of values as properties. All odd numbered values are property keys
175- * and even numbered values are property values. If there are an odd number of values
176- * the last value is assumed to be a boolean with a value of "true".
177- * @param props the properties to update.
178- * @param values the list of values to parse.
179- */
180- private void processPropertiesFromValues (final Properties props , final List <String > values ) {
181- for (int i = 0 ; i < values .size (); i += 2 ) {
182- if (i + 1 < values .size ()) {
183- props .put (values .get (i ), values .get (i + 1 ));
184- } else {
185- props .put (values .get (i ), "true" );
186- }
187- }
188- }
189-
190173 /**
191174 * Gets the map of values associated to the option. This is convenient for options specifying Java properties like
192175 * <code>-Dparam1=value1
@@ -345,7 +328,6 @@ public String getOptionValue(final String opt, final Supplier<String> defaultVal
345328 return getOptionValue (resolveOption (opt ), defaultValue );
346329 }
347330
348-
349331 /**
350332 * Gets the array of values, if any, of an option.
351333 *
@@ -356,6 +338,7 @@ public String[] getOptionValues(final char opt) {
356338 return getOptionValues (String .valueOf (opt ));
357339 }
358340
341+
359342 /**
360343 * Gets the array of values, if any, of an option.
361344 *
@@ -410,7 +393,7 @@ public <T> T getParsedOptionValue(final char opt) throws ParseException {
410393 * @see PatternOptionBuilder
411394 * @since 1.7.0
412395 */
413- public <T > T getParsedOptionValue (final char opt , final T defaultValue ) throws ParseException {
396+ public <T > T getParsedOptionValue (final char opt , final Supplier < T > defaultValue ) throws ParseException {
414397 return getParsedOptionValue (String .valueOf (opt ), defaultValue );
415398 }
416399
@@ -425,7 +408,7 @@ public <T> T getParsedOptionValue(final char opt, final T defaultValue) throws P
425408 * @see PatternOptionBuilder
426409 * @since 1.7.0
427410 */
428- public <T > T getParsedOptionValue (final char opt , final Supplier < T > defaultValue ) throws ParseException {
411+ public <T > T getParsedOptionValue (final char opt , final T defaultValue ) throws ParseException {
429412 return getParsedOptionValue (String .valueOf (opt ), defaultValue );
430413 }
431414
@@ -454,8 +437,18 @@ public <T> T getParsedOptionValue(final Option option) throws ParseException {
454437 * @see PatternOptionBuilder
455438 * @since 1.7.0
456439 */
457- public <T > T getParsedOptionValue (final Option option , final T defaultValue ) throws ParseException {
458- return getParsedOptionValue (option , () -> defaultValue );
440+ @ SuppressWarnings ("unchecked" )
441+ public <T > T getParsedOptionValue (final Option option , final Supplier <T > defaultValue ) throws ParseException {
442+ final String res = option == null ? null : getOptionValue (option );
443+
444+ try {
445+ if (res == null ) {
446+ return defaultValue == null ? null : defaultValue .get ();
447+ }
448+ return (T ) option .getConverter ().apply (res );
449+ } catch (final Throwable e ) {
450+ throw ParseException .wrap (e );
451+ }
459452 }
460453
461454 /**
@@ -469,18 +462,8 @@ public <T> T getParsedOptionValue(final Option option, final T defaultValue) thr
469462 * @see PatternOptionBuilder
470463 * @since 1.7.0
471464 */
472- @ SuppressWarnings ("unchecked" )
473- public <T > T getParsedOptionValue (final Option option , final Supplier <T > defaultValue ) throws ParseException {
474- final String res = option == null ? null : getOptionValue (option );
475-
476- try {
477- if (res == null ) {
478- return defaultValue == null ? null : defaultValue .get ();
479- }
480- return (T ) option .getConverter ().apply (res );
481- } catch (final Throwable e ) {
482- throw ParseException .wrap (e );
483- }
465+ public <T > T getParsedOptionValue (final Option option , final T defaultValue ) throws ParseException {
466+ return getParsedOptionValue (option , () -> defaultValue );
484467 }
485468
486469 /**
@@ -508,7 +491,7 @@ public <T> T getParsedOptionValue(final String opt) throws ParseException {
508491 * @see PatternOptionBuilder
509492 * @since 1.7.0
510493 */
511- public <T > T getParsedOptionValue (final String opt , final T defaultValue ) throws ParseException {
494+ public <T > T getParsedOptionValue (final String opt , final Supplier < T > defaultValue ) throws ParseException {
512495 return getParsedOptionValue (resolveOption (opt ), defaultValue );
513496 }
514497
@@ -523,10 +506,20 @@ public <T> T getParsedOptionValue(final String opt, final T defaultValue) throws
523506 * @see PatternOptionBuilder
524507 * @since 1.7.0
525508 */
526- public <T > T getParsedOptionValue (final String opt , final Supplier < T > defaultValue ) throws ParseException {
509+ public <T > T getParsedOptionValue (final String opt , final T defaultValue ) throws ParseException {
527510 return getParsedOptionValue (resolveOption (opt ), defaultValue );
528511 }
529512
513+ /**
514+ * Tests to see if an option has been set.
515+ *
516+ * @param opt character name of the option.
517+ * @return true if set, false if not.
518+ */
519+ public boolean hasOption (final char opt ) {
520+ return hasOption (String .valueOf (opt ));
521+ }
522+
530523 /**
531524 * jkeyes - commented out until it is implemented properly
532525 * <p>
@@ -545,16 +538,6 @@ public <T> T getParsedOptionValue(final String opt, final Supplier<T> defaultVal
545538 * return buf.toString(); }
546539 */
547540
548- /**
549- * Tests to see if an option has been set.
550- *
551- * @param opt character name of the option.
552- * @return true if set, false if not.
553- */
554- public boolean hasOption (final char opt ) {
555- return hasOption (String .valueOf (opt ));
556- }
557-
558541 /**
559542 * Tests to see if an option has been set.
560543 *
@@ -585,6 +568,23 @@ public Iterator<Option> iterator() {
585568 return options .iterator ();
586569 }
587570
571+ /**
572+ * Parses a list of values as properties. All odd numbered values are property keys
573+ * and even numbered values are property values. If there are an odd number of values
574+ * the last value is assumed to be a boolean with a value of "true".
575+ * @param props the properties to update.
576+ * @param values the list of values to parse.
577+ */
578+ private void processPropertiesFromValues (final Properties props , final List <String > values ) {
579+ for (int i = 0 ; i < values .size (); i += 2 ) {
580+ if (i + 1 < values .size ()) {
581+ props .put (values .get (i ), values .get (i + 1 ));
582+ } else {
583+ props .put (values .get (i ), "true" );
584+ }
585+ }
586+ }
587+
588588 /**
589589 * Retrieves the option object given the long or short option as a String
590590 *
0 commit comments