commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1648063 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/StringUtils.java test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
Date Sat, 27 Dec 2014 16:20:55 GMT
Author: britter
Date: Sat Dec 27 16:20:55 2014
New Revision: 1648063

URL: http://svn.apache.org/r1648063
Log:
LANG-883: Add StringUtils.containsAny(CharSequence, CharSequence...) method. Thanks to Daniel
Stewart.

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1648063&r1=1648062&r2=1648063&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Sat Dec 27 16:20:55 2014
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.4" date="tba" description="tba">
+    <action issue="LANG-883" type="add" dev="britter" due-to="Daniel Stewart">Add StringUtils.containsAny(CharSequence,
CharSequence...) method</action>
     <action issue="LANG-1073" type="fix" dev="kinow" due-to="haiyang li">Read wrong
component type of array in add in ArrayUtils</action>
     <action issue="LANG-1077" type="fix" dev="kinow" due-to="haiyang li">StringUtils.ordinalIndexOf("aaaaaa",
"aa", 2) != 3 in StringUtils</action>
     <action issue="LANG-1072" type="fix" dev="sebb" due-to="haiyang li">Duplicated
"0x" check in createBigInteger in NumberUtils</action>

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1648063&r1=1648062&r2=1648063&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Sat
Dec 27 16:20:55 2014
@@ -1670,6 +1670,31 @@ public class StringUtils {
         return containsAny(cs, CharSequenceUtils.toCharArray(searchChars));
     }
 
+    /**
+     * <p>Checks if the CharSequence contains any of the CharSequences in the given
array.</p>
+     *
+     * <p>
+     * A {@code null} CharSequence will return {@code false}. A {@code null} or zero
+     * length search array will return {@code false}.
+     * </p>
+     * 
+     * @param cs The CharSequence to check, may be null
+     * @param searchCharSequences The array of CharSequences to search for, may be null
+     * @return {@code true} if any of the search CharSequences are found, {@code false} otherwise
+     * @since 3.4
+     */
+    public static boolean containsAny(CharSequence cs, CharSequence... searchCharSequences)
{
+        if (isEmpty(cs) || ArrayUtils.isEmpty(searchCharSequences)) {
+            return false;
+        }
+        for (int i = 0; i < searchCharSequences.length; i++) {
+            if (contains(cs, searchCharSequences[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     // IndexOfAnyBut chars
     //-----------------------------------------------------------------------
     /**

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java?rev=1648063&r1=1648062&r2=1648063&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
Sat Dec 27 16:20:55 2014
@@ -213,6 +213,21 @@ public class StringUtilsEqualsIndexOfTes
         assertFalse(StringUtils.containsAny(CharU20000, CharU20001));
         assertFalse(StringUtils.containsAny(CharU20001, CharU20000));
     }
+    
+    @Test
+    public void testContainsAny_StringStringArray() {
+        assertFalse(StringUtils.containsAny(null, (String[]) null));
+        assertFalse(StringUtils.containsAny(null, new String[0]));
+        assertFalse(StringUtils.containsAny(null, new String[] { "hello" }));
+        assertFalse(StringUtils.containsAny("", (String[]) null));
+        assertFalse(StringUtils.containsAny("", new String[0]));
+        assertFalse(StringUtils.containsAny("", new String[] { "hello" }));
+        assertFalse(StringUtils.containsAny("hello, goodbye", (String[]) null));
+        assertFalse(StringUtils.containsAny("hello, goodbye", new String[0]));
+        assertTrue(StringUtils.containsAny("hello, goodbye", new String[] { "hello", "goodbye"
}));
+        assertTrue(StringUtils.containsAny("hello, goodbye", new String[] { "hello", "Goodbye"
}));
+        assertFalse(StringUtils.containsAny("hello, goodbye", new String[] { "Hello", "Goodbye"
}));
+    }
 
     @Test
     public void testContainsIgnoreCase_LocaleIndependence() {



Mime
View raw message