Skip to content

Commit 8cb790a

Browse files
committed
Sort members
1 parent bda9a3b commit 8cb790a

2 files changed

Lines changed: 45 additions & 45 deletions

File tree

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

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,45 @@ public String[] getArgs() {
221221
return args.toArray(Util.EMPTY_STRING_ARRAY);
222222
}
223223

224+
/**
225+
* Gets the number of times this option appears in the command line
226+
*
227+
* @param optionChar the character name of the option.
228+
* @return Number of times the option is present
229+
* @since 1.11.0
230+
*/
231+
public int getOptionCount(final char optionChar) {
232+
return getOptionCount(String.valueOf(optionChar));
233+
}
234+
235+
/**
236+
* Gets the number of times this option appears in the command line.
237+
*
238+
* @param option the option.
239+
* @return Number of times the option is present
240+
* @since 1.11.0
241+
*/
242+
public int getOptionCount(final Option option) {
243+
int result = 0;
244+
for (Option opt : options) {
245+
if (Objects.equals(opt, option)) {
246+
++result;
247+
}
248+
}
249+
return result;
250+
}
251+
252+
/**
253+
* Gets the number of times this option appears in the command line
254+
*
255+
* @param optionName the name of the option.
256+
* @return Number of times the option is present
257+
* @since 1.11.0
258+
*/
259+
public int getOptionCount(final String optionName) {
260+
return getOptionCount(resolveOption(optionName));
261+
}
262+
224263
/**
225264
* Gets the {@code Object} type of this {@code Option}.
226265
*
@@ -300,45 +339,6 @@ public Option[] getOptions() {
300339
return options.toArray(Option.EMPTY_ARRAY);
301340
}
302341

303-
/**
304-
* Gets the number of times this option appears in the command line.
305-
*
306-
* @param option the option.
307-
* @return Number of times the option is present
308-
* @since 1.11.0
309-
*/
310-
public int getOptionCount(final Option option) {
311-
int result = 0;
312-
for (Option opt : options) {
313-
if (Objects.equals(opt, option)) {
314-
++result;
315-
}
316-
}
317-
return result;
318-
}
319-
320-
/**
321-
* Gets the number of times this option appears in the command line
322-
*
323-
* @param optionChar the character name of the option.
324-
* @return Number of times the option is present
325-
* @since 1.11.0
326-
*/
327-
public int getOptionCount(final char optionChar) {
328-
return getOptionCount(String.valueOf(optionChar));
329-
}
330-
331-
/**
332-
* Gets the number of times this option appears in the command line
333-
*
334-
* @param optionName the name of the option.
335-
* @return Number of times the option is present
336-
* @since 1.11.0
337-
*/
338-
public int getOptionCount(final String optionName) {
339-
return getOptionCount(resolveOption(optionName));
340-
}
341-
342342
/**
343343
* Gets the first argument, if any, of this option.
344344
*

src/test/java/org/apache/commons/cli/OptionCountTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class OptionCountTest {
2525
private static final Option VERBOSITY = new Option("v", "verbosity: use multiple times for more");
2626
private static final Options OPTIONS = new Options().addOption(VERBOSITY);
2727

28+
@Test
29+
void testFiveSwitchesMixed() throws ParseException {
30+
final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{"-v", "-vvv", "-v"});
31+
assertEquals(5, cmdLine.getOptionCount(VERBOSITY));
32+
}
33+
2834
@Test
2935
void testNoSwitch() throws ParseException {
3036
final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{});
@@ -50,10 +56,4 @@ void testThreeSwitchesCompact() throws ParseException {
5056
final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{"-vvv"});
5157
assertEquals(3, cmdLine.getOptionCount(VERBOSITY));
5258
}
53-
54-
@Test
55-
void testFiveSwitchesMixed() throws ParseException {
56-
final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{"-v", "-vvv", "-v"});
57-
assertEquals(5, cmdLine.getOptionCount(VERBOSITY));
58-
}
5959
}

0 commit comments

Comments
 (0)