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-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new f51f015e3 [LANG-1682] Javadoc and test: Use Strings.CI.startsWithAny 
method instead (#1299)
f51f015e3 is described below

commit f51f015e3deb2d205b2962fbaa253f6ef457f2a3
Author: Capt. Cutlass <5120290+paranoidu...@users.noreply.github.com>
AuthorDate: Wed Oct 16 13:34:39 2024 -0400

    [LANG-1682] Javadoc and test: Use Strings.CI.startsWithAny method instead 
(#1299)
    
    * test: add case-insensitive tests for startsWithAny method
    
    * docs: revise javadoc to describe case-sensitivity
---
 .../java/org/apache/commons/lang3/Strings.java     | 47 ++++++++++++++--------
 .../java/org/apache/commons/lang3/StringsTest.java | 21 ++++++++++
 2 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/Strings.java 
b/src/main/java/org/apache/commons/lang3/Strings.java
index 0817482d1..80e18c55c 100644
--- a/src/main/java/org/apache/commons/lang3/Strings.java
+++ b/src/main/java/org/apache/commons/lang3/Strings.java
@@ -607,7 +607,7 @@ public abstract class Strings {
     }
 
     /**
-     * Tests if a CharSequence ends with any of the provided case-sensitive 
suffixes.
+     * Tests if a CharSequence ends with any of the provided suffixes.
      *
      * <p>
      * Case-sensitive examples
@@ -625,10 +625,10 @@ public abstract class Strings {
      * </pre>
      *
      * @param sequence      the CharSequence to check, may be null
-     * @param searchStrings the case-sensitive CharSequences to find, may be 
empty or contain {@code null}
-     * @see StringUtils#endsWith(CharSequence, CharSequence)
+     * @param searchStrings the CharSequence suffixes to find, may be empty or 
contain {@code null}
+     * @see Strings#endsWith(CharSequence, CharSequence)
      * @return {@code true} if the input {@code sequence} is {@code null} AND 
no {@code searchStrings} are provided, or the input {@code sequence} ends in any
-     *         of the provided case-sensitive {@code searchStrings}.
+     *         of the provided {@code searchStrings}.
      */
     public boolean endsWithAny(final CharSequence sequence, final 
CharSequence... searchStrings) {
         if (StringUtils.isEmpty(sequence) || 
ArrayUtils.isEmpty(searchStrings)) {
@@ -1412,28 +1412,43 @@ public abstract class Strings {
     }
 
     /**
-     * Tests if a CharSequence starts with any of the provided case-sensitive 
prefixes.
+     * Tests if a CharSequence starts with any of the provided prefixes.
      *
      * <p>
      * Case-sensitive examples
      * </p>
      *
      * <pre>
-     * StringUtils.startsWithAny(null, null)      = false
-     * StringUtils.startsWithAny(null, new String[] {"abc"})  = false
-     * StringUtils.startsWithAny("abcxyz", null)     = false
-     * StringUtils.startsWithAny("abcxyz", new String[] {""}) = true
-     * StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true
-     * StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) 
= true
-     * StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX") = false
-     * StringUtils.startsWithAny("ABCXYZ", null, "xyz", "abc") = false
+     * Strings.CS.startsWithAny(null, null)      = false
+     * Strings.CS.startsWithAny(null, new String[] {"abc"})  = false
+     * Strings.CS.startsWithAny("abcxyz", null)     = false
+     * Strings.CS.startsWithAny("abcxyz", new String[] {""}) = true
+     * Strings.CS.startsWithAny("abcxyz", new String[] {"abc"}) = true
+     * Strings.CS.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = 
true
+     * Strings.CS.startsWithAny("abcxyz", null, "xyz", "ABCX") = false
+     * Strings.CS.startsWithAny("ABCXYZ", null, "xyz", "abc") = false
+     * </pre>
+     *
+     * <p>
+     * Case-insensitive examples
+     * </p>
+     *
+     * <pre>
+     * Strings.CI.startsWithAny(null, null)      = false
+     * Strings.CI.startsWithAny(null, new String[] {"aBc"})  = false
+     * Strings.CI.startsWithAny("AbCxYz", null)     = false
+     * Strings.CI.startsWithAny("AbCxYz", new String[] {""}) = true
+     * Strings.CI.startsWithAny("AbCxYz", new String[] {"aBc"}) = true
+     * Strings.CI.startsWithAny("AbCxYz", new String[] {null, "XyZ", "aBc"}) = 
true
+     * Strings.CI.startsWithAny("abcxyz", null, "xyz", "ABCX") = true
+     * Strings.CI.startsWithAny("ABCXYZ", null, "xyz", "abc") = true
      * </pre>
      *
      * @param sequence      the CharSequence to check, may be null
-     * @param searchStrings the case-sensitive CharSequence prefixes, may be 
empty or contain {@code null}
-     * @see StringUtils#startsWith(CharSequence, CharSequence)
+     * @param searchStrings the CharSequence prefixes, may be empty or contain 
{@code null}
+     * @see Strings#startsWith(CharSequence, CharSequence)
      * @return {@code true} if the input {@code sequence} is {@code null} AND 
no {@code searchStrings} are provided, or the input {@code sequence} begins with
-     *         any of the provided case-sensitive {@code searchStrings}.
+     *         any of the provided {@code searchStrings}.
      */
     public boolean startsWithAny(final CharSequence sequence, final 
CharSequence... searchStrings) {
         if (StringUtils.isEmpty(sequence) || 
ArrayUtils.isEmpty(searchStrings)) {
diff --git a/src/test/java/org/apache/commons/lang3/StringsTest.java 
b/src/test/java/org/apache/commons/lang3/StringsTest.java
index b8cef63c4..de0013d29 100644
--- a/src/test/java/org/apache/commons/lang3/StringsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringsTest.java
@@ -63,6 +63,27 @@ public class StringsTest {
         assertTrue(Strings.CS.isCaseSensitive());
     }
 
+    /**
+     * Expanding the existing test group {@link 
StringUtilsStartsEndsWithTest#testStartsWithAny()} to include case-insensitive 
cases
+     */
+    @Test
+    public void testCaseInsensitiveStartsWithAny() {
+        // LANG-1682
+        assertFalse(Strings.CI.startsWithAny(null, (String[]) null));
+        assertFalse(Strings.CI.startsWithAny(null, "aBc"));
+        assertFalse(Strings.CI.startsWithAny("AbCxYz", (String[]) null));
+        assertFalse(Strings.CI.startsWithAny("AbCxYz"));
+        assertTrue(Strings.CI.startsWithAny("AbCxYz", "aBc"));
+        assertTrue(Strings.CI.startsWithAny("AbCxYz", null, "XyZ", "aBc"));
+        assertFalse(Strings.CI.startsWithAny("AbCxYz", null, "XyZ", "aBcD"));
+        assertTrue(Strings.CI.startsWithAny("AbCxYz", ""));
+        assertTrue(Strings.CI.startsWithAny("abcxyz", null, "XyZ", "ABCX"));
+        assertTrue(Strings.CI.startsWithAny("ABCXYZ", null, "XyZ", "abc"));
+
+        assertTrue(Strings.CI.startsWithAny("AbCxYz", new 
StringBuilder("XyZ"), new StringBuffer("aBc")));
+        assertTrue(Strings.CI.startsWithAny(new StringBuffer("AbCxYz"), new 
StringBuilder("XyZ"), new StringBuffer("abc")));
+    }
+
     @ParameterizedTest
     @MethodSource("stringsFactory")
     public void testEqualsStrings(final Strings strings) {

Reply via email to