Skip to content

Commit a9baf80

Browse files
committed
No need to create an intermediary array
1 parent 4c46459 commit a9baf80

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ private void handleProperties(final Properties properties) throws ParseException
516516
final String value = properties.getProperty(option);
517517

518518
if (opt.hasArg()) {
519-
if (Util.isEmpty(opt.getValues())) {
519+
if (opt.isValuesEmpty()) {
520520
opt.processValue(stripLeadingAndTrailingQuotesDefaultOff(value));
521521
}
522522
} else if (!("yes".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value))) {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ public Object getType() {
694694
* @return the value/first value of this Option or {@code null} if there is no value.
695695
*/
696696
public String getValue() {
697-
return hasNoValues() ? null : values.get(0);
697+
return isValuesEmpty() ? null : values.get(0);
698698
}
699699

700700
/**
@@ -705,7 +705,7 @@ public String getValue() {
705705
* @throws IndexOutOfBoundsException if index is less than 1 or greater than the number of the values for this Option.
706706
*/
707707
public String getValue(final int index) throws IndexOutOfBoundsException {
708-
return hasNoValues() ? null : values.get(index);
708+
return isValuesEmpty() ? null : values.get(index);
709709
}
710710

711711
/**
@@ -725,7 +725,7 @@ public String getValue(final String defaultValue) {
725725
* @return the values of this Option as a String array or an empty array if there are no values.
726726
*/
727727
public String[] getValues() {
728-
return hasNoValues() ? null : values.toArray(EMPTY_STRING_ARRAY);
728+
return isValuesEmpty() ? null : values.toArray(EMPTY_STRING_ARRAY);
729729
}
730730

731731
/**
@@ -787,15 +787,6 @@ public boolean hasLongOpt() {
787787
return longOption != null;
788788
}
789789

790-
/**
791-
* Tests whether this Option has any values.
792-
*
793-
* @return whether this Option has any values.
794-
*/
795-
private boolean hasNoValues() {
796-
return values.isEmpty();
797-
}
798-
799790
/**
800791
* Tests whether this Option can have an optional argument.
801792
*
@@ -834,6 +825,15 @@ public boolean isRequired() {
834825
return required;
835826
}
836827

828+
/**
829+
* Tests whether this Option has any values.
830+
*
831+
* @return whether this Option has any values.
832+
*/
833+
boolean isValuesEmpty() {
834+
return values.isEmpty();
835+
}
836+
837837
/**
838838
* Processes the value. If this Option has a value separator the value will have to be parsed into individual tokens. When n-1 tokens have been processed
839839
* and there are more value separators in the value, parsing is ceased and the remaining characters are added as a single token.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void processArgs(final Option opt, final ListIterator<String> iter) throw
231231
break;
232232
}
233233
}
234-
if (opt.getValues() == null && !opt.hasOptionalArg()) {
234+
if (opt.isValuesEmpty() && !opt.hasOptionalArg()) {
235235
throw new MissingArgumentException(opt);
236236
}
237237
}
@@ -285,7 +285,7 @@ protected void processProperties(final Properties properties) throws ParseExcept
285285
// get the value from the properties instance
286286
final String value = properties.getProperty(option);
287287
if (opt.hasArg()) {
288-
if (Util.isEmpty(opt.getValues())) {
288+
if (opt.isValuesEmpty()) {
289289
try {
290290
opt.processValue(value);
291291
} catch (final RuntimeException exp) { // NOPMD

0 commit comments

Comments
 (0)