Skip to content

Commit bbc7001

Browse files
committed
Internal refactoring
1 parent a7849ae commit bbc7001

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ protected void addOption(final Option option) {
199199
}
200200
}
201201

202+
/**
203+
* Gets the first element or null if values is null.
204+
*
205+
* @param values the array to query.
206+
* @return the first element or null if values is null.
207+
*/
208+
private String first(final String[] values) {
209+
return values == null ? null : values[0];
210+
}
211+
202212
private <T> T get(final Supplier<T> supplier) {
203213
return supplier == null ? null : supplier.get();
204214
}
@@ -374,8 +384,7 @@ public String getOptionValue(final char optionChar, final Supplier<String> defau
374384
* @since 1.5.0
375385
*/
376386
public String getOptionValue(final Option option) {
377-
final String[] values = getOptionValues(option);
378-
return values == null ? null : values[0];
387+
return first(getOptionValues(option));
379388
}
380389

381390
/**
@@ -411,8 +420,7 @@ public String getOptionValue(final Option option, final Supplier<String> default
411420
* @since 1.9.0
412421
*/
413422
public String getOptionValue(final OptionGroup optionGroup) {
414-
final String[] values = getOptionValues(optionGroup);
415-
return values == null ? null : values[0];
423+
return first(getOptionValues(optionGroup));
416424
}
417425

418426
/**

0 commit comments

Comments
 (0)