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:37 UTC

(commons-cli) 03/07: Use Stream.count()

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();
     }
 
     /**