You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/10/04 13:04:34 UTC
(commons-cli) branch master updated (f6c45f8f -> c7de56e9)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
from f6c45f8f feat: add option counting functions (#396)
new bda9a3bc Add CommandLine.getOptionCount() to measure option repetition #396
new 8cb790a3 Sort members
new d2442310 Use Stream.count()
new aede31ba Javadoc
new b2948a6a Use Stream.findFirst()
new 95bb098f Javadoc
new c7de56e9 The next release will be 1.11.0
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pom.xml | 6 +-
src/changes/changes.xml | 3 +-
.../java/org/apache/commons/cli/CommandLine.java | 135 ++++++++++-----------
.../org/apache/commons/cli/OptionCountTest.java | 12 +-
4 files changed, 75 insertions(+), 81 deletions(-)
(commons-cli) 04/07: Javadoc
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit aede31ba867613f3c898157d2705aa5fd6f2d0bc
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 08:57:36 2025 -0400
Javadoc
---
.../java/org/apache/commons/cli/CommandLine.java | 60 +++++++++++-----------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/main/java/org/apache/commons/cli/CommandLine.java b/src/main/java/org/apache/commons/cli/CommandLine.java
index b497bec6..1c14c1f4 100644
--- a/src/main/java/org/apache/commons/cli/CommandLine.java
+++ b/src/main/java/org/apache/commons/cli/CommandLine.java
@@ -204,7 +204,7 @@ public class CommandLine implements Serializable {
}
/**
- * Gets any left-over non-recognized options and arguments
+ * Gets any left-over non-recognized options and arguments.
*
* @return remaining items passed in but not parsed as a {@code List}.
*/
@@ -213,7 +213,7 @@ public class CommandLine implements Serializable {
}
/**
- * Gets any left-over non-recognized options and arguments
+ * Gets any left-over non-recognized options and arguments.
*
* @return remaining items passed in but not parsed as an array.
*/
@@ -225,7 +225,7 @@ public class CommandLine implements Serializable {
* Gets the number of times this option appears in the command line
*
* @param optionChar the character name of the option.
- * @return Number of times the option is present
+ * @return Number of times the option is present.
* @since 1.11.0
*/
public int getOptionCount(final char optionChar) {
@@ -236,7 +236,7 @@ public class CommandLine implements Serializable {
* Gets the number of times this option appears in the command line.
*
* @param option the option.
- * @return Number of times the option is present
+ * @return Number of times the option is present.
* @since 1.11.0
*/
public int getOptionCount(final Option option) {
@@ -247,7 +247,7 @@ public class CommandLine implements Serializable {
* Gets the number of times this option appears in the command line
*
* @param optionName the name of the option.
- * @return Number of times the option is present
+ * @return Number of times the option is present.
* @since 1.11.0
*/
public int getOptionCount(final String optionName) {
@@ -357,7 +357,7 @@ public class CommandLine implements Serializable {
/**
* Gets the argument, if any, of an option.
*
- * @param optionChar character name of the option
+ * @param optionChar character name of the option.
* @param defaultValue is a supplier for the default value to be returned if the option is not specified.
* @return Value of the argument if option is set, and has an argument, otherwise {@code defaultValue}.
* @since 1.7.0
@@ -536,7 +536,7 @@ public class CommandLine implements Serializable {
* @param optionChar the name of the option.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or null if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.5.0
*/
@@ -551,7 +551,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.7.0
*/
@@ -566,7 +566,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.7.0
*/
@@ -580,7 +580,7 @@ public class CommandLine implements Serializable {
* @param option the option.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or null if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.5.0
*/
@@ -595,7 +595,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.7.0
*/
@@ -622,7 +622,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.7.0
*/
@@ -636,7 +636,7 @@ public class CommandLine implements Serializable {
* @param optionGroup the option group.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or null if no option in the OptionGroup is set.
- * @throws ParseException if there are problems turning the selected option value into the desired type
+ * @throws ParseException if there are problems turning the selected option value into the desired type.
* @see PatternOptionBuilder
* @since 1.9.0
*/
@@ -651,7 +651,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if no option in the OptionGroup is set.
- * @throws ParseException if there are problems turning the selected option value into the desired type
+ * @throws ParseException if there are problems turning the selected option value into the desired type.
* @see PatternOptionBuilder
* @since 1.9.0
*/
@@ -669,7 +669,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if an option is not selected.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if no option in the OptionGroup is set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.9.0
*/
@@ -683,7 +683,7 @@ public class CommandLine implements Serializable {
* @param optionName the name of the option.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or null if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.2
*/
@@ -698,7 +698,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.7.0
*/
@@ -713,7 +713,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The return type for the method.
* @return the value parsed into a particular object or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.7.0
*/
@@ -727,7 +727,7 @@ public class CommandLine implements Serializable {
* @param optionChar the name of the option.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or null if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -742,7 +742,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -757,7 +757,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -771,7 +771,7 @@ public class CommandLine implements Serializable {
* @param option the option.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or null if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -786,7 +786,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -818,7 +818,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -832,7 +832,7 @@ public class CommandLine implements Serializable {
* @param optionGroup the option group.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or null if no option in the OptionGroup is set.
- * @throws ParseException if there are problems turning the selected option value into the desired type
+ * @throws ParseException if there are problems turning the selected option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -847,7 +847,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or null if no option in the OptionGroup is set.
- * @throws ParseException if there are problems turning the selected option value into the desired type
+ * @throws ParseException if there are problems turning the selected option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -865,7 +865,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if an option is not selected.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or null if no option in the OptionGroup is set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -879,7 +879,7 @@ public class CommandLine implements Serializable {
* @param optionName the name of the option.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or null if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -894,7 +894,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or defaultValues if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
@@ -909,7 +909,7 @@ public class CommandLine implements Serializable {
* @param defaultValue the default value to return if opt is not set.
* @param <T> The array type for the return value.
* @return the values parsed into an array of objects or defaultValues if the option is not set.
- * @throws ParseException if there are problems turning the option value into the desired type
+ * @throws ParseException if there are problems turning the option value into the desired type.
* @see PatternOptionBuilder
* @since 1.10.0
*/
(commons-cli) 07/07: The next release will be 1.11.0
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit c7de56e935ad396d16065b4ea0ad78b080985eb2
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 09:04:10 2025 -0400
The next release will be 1.11.0
---
pom.xml | 6 +++---
src/changes/changes.xml | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index a8a246d2..a7b684a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
- <version>1.10.1-SNAPSHOT</version>
+ <version>1.11.0-SNAPSHOT</version>
<name>Apache Commons CLI</name>
<inceptionYear>2002</inceptionYear>
<description>
@@ -92,8 +92,8 @@
<maven.compiler.target>1.8</maven.compiler.target>
<commons.componentid>cli</commons.componentid>
<commons.module.name>org.apache.commons.cli</commons.module.name>
- <commons.release.version>1.10.1</commons.release.version>
- <commons.release.next>1.10.2</commons.release.next>
+ <commons.release.version>1.11.0</commons.release.version>
+ <commons.release.next>1.11.1</commons.release.next>
<commons.release.name>commons-cli-${commons.release.version}</commons.release.name>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.rc.version>RC1</commons.rc.version>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 66a07888..71fb2a4c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,7 +22,7 @@
<title>Apache Commons CLI Release Notes</title>
</properties>
<body>
- <release version="1.10.1" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
+ <release version="1.11.0" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="fix" issue="CLI-351" dev="ggregory" due-to="Damien Carbonne, Claude Warren, Gary Gregory">Multiple trailing BREAK_CHAR_SET characters cause infinite loop in HelpFormatter.</action>
<!-- ADD -->
(commons-cli) 06/07: Javadoc
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit 95bb098f51f7e50cc39ee6c9e684056ec3f5adef
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 09:02:42 2025 -0400
Javadoc
---
src/main/java/org/apache/commons/cli/CommandLine.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/org/apache/commons/cli/CommandLine.java b/src/main/java/org/apache/commons/cli/CommandLine.java
index 01d5c8cc..b2f308df 100644
--- a/src/main/java/org/apache/commons/cli/CommandLine.java
+++ b/src/main/java/org/apache/commons/cli/CommandLine.java
@@ -1008,6 +1008,7 @@ public class CommandLine implements Serializable {
* Parses a list of values as properties. All odd numbered values are property keys
* and even numbered values are property values. If there are an odd number of values
* the last value is assumed to be a boolean with a value of "true".
+ *
* @param props the properties to update.
* @param values the list of values to parse.
*/
(commons-cli) 01/07: Add CommandLine.getOptionCount() to measure option repetition #396
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit bda9a3bc9d5177d9ee394dbf0a4ac21740b7fdb1
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 08:52:22 2025 -0400
Add CommandLine.getOptionCount() to measure option repetition #396
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f5ff79c1..66a07888 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -26,6 +26,7 @@
<!-- FIX -->
<action type="fix" issue="CLI-351" dev="ggregory" due-to="Damien Carbonne, Claude Warren, Gary Gregory">Multiple trailing BREAK_CHAR_SET characters cause infinite loop in HelpFormatter.</action>
<!-- ADD -->
+ <action type="add" dev="ggregory" due-to="David Larochette, Gary Gregory">Add CommandLine.getOptionCount() to measure option repetition #396.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 85 to 88 #393.</action>
</release>
(commons-cli) 02/07: Sort members
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit 8cb790a31578760f9f265b8beccc99eadb1d9888
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 08:52:37 2025 -0400
Sort members
---
.../java/org/apache/commons/cli/CommandLine.java | 78 +++++++++++-----------
.../org/apache/commons/cli/OptionCountTest.java | 12 ++--
2 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/src/main/java/org/apache/commons/cli/CommandLine.java b/src/main/java/org/apache/commons/cli/CommandLine.java
index 50313b61..aa136705 100644
--- a/src/main/java/org/apache/commons/cli/CommandLine.java
+++ b/src/main/java/org/apache/commons/cli/CommandLine.java
@@ -221,6 +221,45 @@ public class CommandLine implements Serializable {
return args.toArray(Util.EMPTY_STRING_ARRAY);
}
+ /**
+ * Gets the number of times this option appears in the command line
+ *
+ * @param optionChar the character name of the option.
+ * @return Number of times the option is present
+ * @since 1.11.0
+ */
+ public int getOptionCount(final char optionChar) {
+ return getOptionCount(String.valueOf(optionChar));
+ }
+
+ /**
+ * Gets the number of times this option appears in the command line.
+ *
+ * @param option the option.
+ * @return Number of times the option is present
+ * @since 1.11.0
+ */
+ public int getOptionCount(final Option option) {
+ int result = 0;
+ for (Option opt : options) {
+ if (Objects.equals(opt, option)) {
+ ++result;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Gets the number of times this option appears in the command line
+ *
+ * @param optionName the name of the option.
+ * @return Number of times the option is present
+ * @since 1.11.0
+ */
+ public int getOptionCount(final String optionName) {
+ return getOptionCount(resolveOption(optionName));
+ }
+
/**
* Gets the {@code Object} type of this {@code Option}.
*
@@ -300,45 +339,6 @@ public class CommandLine implements Serializable {
return options.toArray(Option.EMPTY_ARRAY);
}
- /**
- * Gets the number of times this option appears in the command line.
- *
- * @param option the option.
- * @return Number of times the option is present
- * @since 1.11.0
- */
- public int getOptionCount(final Option option) {
- int result = 0;
- for (Option opt : options) {
- if (Objects.equals(opt, option)) {
- ++result;
- }
- }
- return result;
- }
-
- /**
- * Gets the number of times this option appears in the command line
- *
- * @param optionChar the character name of the option.
- * @return Number of times the option is present
- * @since 1.11.0
- */
- public int getOptionCount(final char optionChar) {
- return getOptionCount(String.valueOf(optionChar));
- }
-
- /**
- * Gets the number of times this option appears in the command line
- *
- * @param optionName the name of the option.
- * @return Number of times the option is present
- * @since 1.11.0
- */
- public int getOptionCount(final String optionName) {
- return getOptionCount(resolveOption(optionName));
- }
-
/**
* Gets the first argument, if any, of this option.
*
diff --git a/src/test/java/org/apache/commons/cli/OptionCountTest.java b/src/test/java/org/apache/commons/cli/OptionCountTest.java
index a12f91ba..ca42d1d6 100644
--- a/src/test/java/org/apache/commons/cli/OptionCountTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionCountTest.java
@@ -25,6 +25,12 @@ class OptionCountTest {
private static final Option VERBOSITY = new Option("v", "verbosity: use multiple times for more");
private static final Options OPTIONS = new Options().addOption(VERBOSITY);
+ @Test
+ void testFiveSwitchesMixed() throws ParseException {
+ final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{"-v", "-vvv", "-v"});
+ assertEquals(5, cmdLine.getOptionCount(VERBOSITY));
+ }
+
@Test
void testNoSwitch() throws ParseException {
final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{});
@@ -50,10 +56,4 @@ class OptionCountTest {
final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{"-vvv"});
assertEquals(3, cmdLine.getOptionCount(VERBOSITY));
}
-
- @Test
- void testFiveSwitchesMixed() throws ParseException {
- final CommandLine cmdLine = new DefaultParser().parse(OPTIONS, new String[]{"-v", "-vvv", "-v"});
- assertEquals(5, cmdLine.getOptionCount(VERBOSITY));
- }
}
(commons-cli) 05/07: Use Stream.findFirst()
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit b2948a6af7a51a5c0da721c8b46044ae50606864
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 09:02:10 2025 -0400
Use Stream.findFirst()
---
src/main/java/org/apache/commons/cli/CommandLine.java | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/commons/cli/CommandLine.java b/src/main/java/org/apache/commons/cli/CommandLine.java
index 1c14c1f4..01d5c8cc 100644
--- a/src/main/java/org/apache/commons/cli/CommandLine.java
+++ b/src/main/java/org/apache/commons/cli/CommandLine.java
@@ -1030,11 +1030,9 @@ public class CommandLine implements Serializable {
private Option resolveOption(final String optionName) {
final String actual = Util.stripLeadingHyphens(optionName);
if (actual != null) {
- for (final Option option : options) {
- if (actual.equals(option.getOpt()) || actual.equals(option.getLongOpt())) {
- return option;
- }
- }
+ return options.stream()
+ .filter(opt -> actual.equals(opt.getOpt()) || actual.equals(opt.getLongOpt()))
+ .findFirst().orElse(null);
}
return null;
}
(commons-cli) 03/07: Use Stream.count()
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit d2442310cb4e8224722f1f288beda3e42fe8f0eb
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 4 08:55:17 2025 -0400
Use Stream.count()
---
src/main/java/org/apache/commons/cli/CommandLine.java | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/cli/CommandLine.java b/src/main/java/org/apache/commons/cli/CommandLine.java
index aa136705..b497bec6 100644
--- a/src/main/java/org/apache/commons/cli/CommandLine.java
+++ b/src/main/java/org/apache/commons/cli/CommandLine.java
@@ -240,13 +240,7 @@ public class CommandLine implements Serializable {
* @since 1.11.0
*/
public int getOptionCount(final Option option) {
- int result = 0;
- for (Option opt : options) {
- if (Objects.equals(opt, option)) {
- ++result;
- }
- }
- return result;
+ return (int) options.stream().filter(opt -> Objects.equals(opt, option)).count();
}
/**