Skip to content

Commit 4d0f3d5

Browse files
committed
Sort members
1 parent 19ead89 commit 4d0f3d5

9 files changed

Lines changed: 286 additions & 286 deletions

File tree

src/main/java/org/apache/commons/cli/CommandLine.java

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*

src/main/java/org/apache/commons/cli/OptionValidator.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ final class OptionValidator {
2929
/** The array of additional characters allowed in the rest of the option but not in the first position */
3030
static final char[] ADDITIONAL_LONG_CHARS = {'-'};
3131

32-
/**
33-
* Checks the char array for a matching char.
34-
* @param chars the char array to search
35-
* @param c the char to look for.
36-
* @return {@code true} if {@code c} was in {@code ary}, {@code false} otherwise.
37-
*/
38-
private static boolean search(final char[] chars, final char c) {
39-
for (char a : chars) {
40-
if (a == c) {
41-
return true;
42-
}
43-
}
44-
return false;
45-
}
46-
4732
/**
4833
* Returns whether the specified character is a valid character.
4934
* A character is valid if any of the following conditions are true:
@@ -86,6 +71,21 @@ private static boolean isValidOpt(final char c) {
8671
return Character.isJavaIdentifierPart(c) || search(ADDITIONAL_OPTION_CHARS, c);
8772
}
8873

74+
/**
75+
* Checks the char array for a matching char.
76+
* @param chars the char array to search
77+
* @param c the char to look for.
78+
* @return {@code true} if {@code c} was in {@code ary}, {@code false} otherwise.
79+
*/
80+
private static boolean search(final char[] chars, final char c) {
81+
for (char a : chars) {
82+
if (a == c) {
83+
return true;
84+
}
85+
}
86+
return false;
87+
}
88+
8989
/**
9090
* Validates whether {@code opt} is a permissible Option shortOpt. The rules that specify if the {@code opt}
9191
* is valid are:

src/main/java/org/apache/commons/cli/Options.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,6 @@ public class Options implements Serializable {
5454
/** A map of the option groups */
5555
private final Map<String, OptionGroup> optionGroups = new LinkedHashMap<>();
5656

57-
/**
58-
* Adds options to this option. If any Option in {@code options} already exists
59-
* in this Options an IllegalArgumentException is thrown
60-
*
61-
* @param options the options to add.
62-
* @return The resulting Options instance.
63-
* @since 1.7.0
64-
*/
65-
public Options addOptions(final Options options) {
66-
for (Option opt : options.getOptions()) {
67-
if (hasOption(opt.getKey())) {
68-
throw new IllegalArgumentException("Duplicate key: " + opt.getKey());
69-
}
70-
addOption(opt);
71-
}
72-
options.getOptionGroups().forEach(this::addOptionGroup);
73-
return this;
74-
}
75-
7657
/**
7758
* Adds an option instance
7859
*
@@ -169,6 +150,25 @@ public Options addOptionGroup(final OptionGroup group) {
169150
return this;
170151
}
171152

153+
/**
154+
* Adds options to this option. If any Option in {@code options} already exists
155+
* in this Options an IllegalArgumentException is thrown
156+
*
157+
* @param options the options to add.
158+
* @return The resulting Options instance.
159+
* @since 1.7.0
160+
*/
161+
public Options addOptions(final Options options) {
162+
for (Option opt : options.getOptions()) {
163+
if (hasOption(opt.getKey())) {
164+
throw new IllegalArgumentException("Duplicate key: " + opt.getKey());
165+
}
166+
addOption(opt);
167+
}
168+
options.getOptionGroups().forEach(this::addOptionGroup);
169+
return this;
170+
}
171+
172172
/**
173173
* Add an option that contains a short-name and a long-name.
174174
*

src/main/java/org/apache/commons/cli/ParseException.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ public static ParseException wrap(final Throwable e) throws UnsupportedOperation
4949
}
5050
return new ParseException(e);
5151
}
52-
/**
53-
* Constructs a new {@code ParseException} wrapping the specified exception.
54-
* @param e the Exception to wrap.
55-
*/
56-
public ParseException(final Throwable e) {
57-
super(e);
58-
}
59-
6052
/**
6153
* Constructs a new {@code ParseException} with the specified detail message.
6254
*
@@ -65,4 +57,12 @@ public ParseException(final Throwable e) {
6557
public ParseException(final String message) {
6658
super(message);
6759
}
60+
61+
/**
62+
* Constructs a new {@code ParseException} wrapping the specified exception.
63+
* @param e the Exception to wrap.
64+
*/
65+
public ParseException(final Throwable e) {
66+
super(e);
67+
}
6868
}

0 commit comments

Comments
 (0)