diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index a879acb58..46702b87f 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -98,7 +98,7 @@ import org.apache.commons.lang.math.NumberUtils; * @author Arun Mammen Thomas * @author Gary Gregory * @since 1.0 - * @version $Id: StringUtils.java,v 1.66 2003/07/19 21:55:05 scolebourne Exp $ + * @version $Id: StringUtils.java,v 1.67 2003/07/19 23:29:06 scolebourne Exp $ */ public class StringUtils { // Performance testing notes (JDK 1.4, Jul03, scolebourne) @@ -464,6 +464,310 @@ public class StringUtils { // IndexOf //----------------------------------------------------------------------- + /** + *
Finds the first index within a String, handling null
.
+ * This method uses {@link String#indexOf(int)}
A null
String will return -1
.
+ * StringUtils.indexOf(null, ' ') = -1 + * StringUtils.indexOf("", ' ') = -1 + * StringUtils.indexOf("aabaabaa", 'a') = 0 + * StringUtils.indexOf("aabaabaa", 'b') = 2 + *+ * + * @param str the String to check, may be null + * @param searchChar the character to find + * @return the first index of the search character, + * -1 if no match or
null
string input
+ */
+ public static int indexOf(String str, char searchChar) {
+ if (str == null || str.length() == 0) {
+ return -1;
+ }
+ return str.indexOf(searchChar);
+ }
+
+ /**
+ * Finds the first index within a String from a start position,
+ * handling null
.
+ * This method uses {@link String#indexOf(int, int)}
A null
String will return -1
.
+ * A negative start position is treated as zero.
+ * A start position greater than the string length returns -1
.
+ * StringUtils.indexOf(null, ' ', 0) = -1 + * StringUtils.indexOf(null, ' ', -1) = -1 + * StringUtils.indexOf("", ' ', 0) = -1 + * StringUtils.indexOf("", ' ', -1) = -1 + * StringUtils.indexOf("aabaabaa", 'b', 0) = 2 + * StringUtils.indexOf("aabaabaa", 'b', 3) = 5 + * StringUtils.indexOf("aabaabaa", 'b', 9) = -1 + * StringUtils.indexOf("aabaabaa", 'b', -1) = 2 + *+ * + * @param str the String to check, may be null + * @param searchChar the character to find + * @param startPos the start position, negative treated as zero + * @return the first index of the search character, + * -1 if no match or
null
string input
+ */
+ public static int indexOf(String str, char searchChar, int startPos) {
+ if (str == null || str.length() == 0) {
+ return -1;
+ }
+ return str.indexOf(searchChar, startPos);
+ }
+
+ /**
+ * Finds the first index within a String, handling null
.
+ * This method uses {@link String#indexOf(String)}
A null
String will return -1
.
+ * StringUtils.indexOf(null, null) = -1 + * StringUtils.indexOf("", null) = -1 + * StringUtils.indexOf("", "") = 0 + * StringUtils.indexOf("aabaabaa", "a") = 0 + * StringUtils.indexOf("aabaabaa", "b") = 2 + * StringUtils.indexOf("aabaabaa", "ab") = 1 + *+ * + * @param str the String to check, may be null + * @param searchStr the String to find, may be null + * @return the first index of the search String, + * -1 if no match or
null
string input
+ */
+ public static int indexOf(String str, String searchStr) {
+ if (str == null || searchStr == null) {
+ return -1;
+ }
+ return str.indexOf(searchStr);
+ }
+
+ /**
+ * Finds the first index within a String, handling null
.
+ * This method uses {@link String#indexOf(String, int)}
A null
String will return -1
.
+ * A negative start position is treated as zero.
+ * An empty ("") search String always matches.
+ * A start position greater than the string length only matches
+ * an empty search String.
+ * StringUtils.indexOf(null, null, 0) = -1 + * StringUtils.indexOf(null, null, -1) = -1 + * StringUtils.indexOf("", null, 0) = -1 + * StringUtils.indexOf("", null, -1) = -1 + * StringUtils.indexOf("", "", 0) = 0 + * StringUtils.indexOf("aabaabaa", "a", 0) = 0 + * StringUtils.indexOf("aabaabaa", "b", 0) = 2 + * StringUtils.indexOf("aabaabaa", "ab", 0) = 1 + * StringUtils.indexOf("aabaabaa", "b", 3) = 5 + * StringUtils.indexOf("aabaabaa", "b", 9) = -1 + * StringUtils.indexOf("aabaabaa", "b", -1) = 2 + *+ * + * @param str the String to check, may be null + * @param searchStr the String to find, may be null + * @param startPos the start position, negative treated as zero + * @return the first index of the search String, + * -1 if no match or
null
string input
+ */
+ public static int indexOf(String str, String searchStr, int startPos) {
+ if (str == null || searchStr == null) {
+ return -1;
+ }
+ return str.indexOf(searchStr, startPos);
+ }
+
+ // LastIndexOf
+ //-----------------------------------------------------------------------
+
+ /**
+ * Finds the last index within a String, handling null
.
+ * This method uses {@link String#indexOf(int)}
A null
String will return -1
.
+ * StringUtils.lastIndexOf(null, ' ') = -1 + * StringUtils.lastIndexOf("", ' ') = -1 + * StringUtils.lastIndexOf("aabaabaa", 'a') = 7 + * StringUtils.lastIndexOf("aabaabaa", 'b') = 5 + *+ * + * @param str the String to check, may be null + * @param searchChar the character to find + * @return the last index of the search character, + * -1 if no match or
null
string input
+ */
+ public static int lastIndexOf(String str, char searchChar) {
+ if (str == null || str.length() == 0) {
+ return -1;
+ }
+ return str.lastIndexOf(searchChar);
+ }
+
+ /**
+ * Finds the last index within a String from a start position,
+ * handling null
.
+ * This method uses {@link String#indexOf(int, int)}
A null
String will return -1
.
+ * A negative or zero start position returns -1
.
+ * A start position greater than the string length searches the whole string.
+ * StringUtils.lastIndexOf(null, ' ', 0) = -1 + * StringUtils.lastIndexOf(null, ' ', -1) = -1 + * StringUtils.lastIndexOf("", ' ', 0) = -1 + * StringUtils.lastIndexOf("", ' ', -1) = -1 + * StringUtils.lastIndexOf("aabaabaa", 'b', 8) = 5 + * StringUtils.lastIndexOf("aabaabaa", 'b', 4) = 2 + * StringUtils.lastIndexOf("aabaabaa", 'b', 0) = -1 + * StringUtils.lastIndexOf("aabaabaa", 'b', 9) = 5 + * StringUtils.lastIndexOf("aabaabaa", 'b', -1) = -1 + *+ * + * @param str the String to check, may be null + * @param searchChar the character to find + * @param startPos the start position + * @return the last index of the search character, + * -1 if no match or
null
string input
+ */
+ public static int lastIndexOf(String str, char searchChar, int startPos) {
+ if (str == null || str.length() == 0) {
+ return -1;
+ }
+ return str.lastIndexOf(searchChar, startPos);
+ }
+
+ /**
+ * Finds the last index within a String, handling null
.
+ * This method uses {@link String#indexOf(String)}
A null
String will return -1
.
+ * StringUtils.lastIndexOf(null, null) = -1 + * StringUtils.lastIndexOf("", null) = -1 + * StringUtils.lastIndexOf("", "") = 0 + * StringUtils.lastIndexOf("aabaabaa", "a") = 0 + * StringUtils.lastIndexOf("aabaabaa", "b") = 2 + * StringUtils.lastIndexOf("aabaabaa", "ab") = 1 + *+ * + * @param str the String to check, may be null + * @param searchStr the String to find, may be null + * @return the last index of the search String, + * -1 if no match or
null
string input
+ */
+ public static int lastIndexOf(String str, String searchStr) {
+ if (str == null || searchStr == null) {
+ return -1;
+ }
+ return str.lastIndexOf(searchStr);
+ }
+
+ /**
+ * Finds the first index within a String, handling null
.
+ * This method uses {@link String#indexOf(String, int)}
A null
String will return -1
.
+ * A negative start position returns -1
.
+ * A zero start position only matches an empty String ("").
+ * An empty ("") search String always matches unless start position negative.
+ * A start position greater than the string length searches the whole string.
+ * StringUtils.lastIndexOf(null, null, 0) = -1 + * StringUtils.lastIndexOf(null, null, -1) = -1 + * StringUtils.lastIndexOf("", null, 0) = -1 + * StringUtils.lastIndexOf("", null, -1) = -1 + * StringUtils.lastIndexOf("aabaabaa", "a", 8) = 7 + * StringUtils.lastIndexOf("aabaabaa", "b", 8) = 5 + * StringUtils.lastIndexOf("aabaabaa", "ab", 8) = 4 + * StringUtils.lastIndexOf("aabaabaa", "b", 9) = 5 + * StringUtils.lastIndexOf("aabaabaa", "b", -1) = -1 + *+ * + * @param str the String to check, may be null + * @param searchStr the String to find, may be null + * @param startPos the start position, negative treated as zero + * @return the first index of the search String, + * -1 if no match or
null
string input
+ */
+ public static int lastIndexOf(String str, String searchStr, int startPos) {
+ if (str == null || searchStr == null) {
+ return -1;
+ }
+ return str.lastIndexOf(searchStr, startPos);
+ }
+
+ // Contains
+ //-----------------------------------------------------------------------
+
+ /**
+ * Checks if String contains a search character, handling null
.
+ * This method uses {@link String#indexOf(int)}
A null
String will return -1
.
+ * StringUtils.contains(null, ' ') = false + * StringUtils.contains("", ' ') = false + * StringUtils.contains("abc", 'a') = true + * StringUtils.contains("abc", 'z') = false + *+ * + * @param str the String to check, may be null + * @param searchChar the character to find + * @return true if the String contains the search character, + * false if not or
null
string input
+ */
+ public static boolean contains(String str, char searchChar) {
+ if (str == null || str.length() == 0) {
+ return false;
+ }
+ return (str.indexOf(searchChar) >= 0);
+ }
+
+ /**
+ * Find the first index within a String, handling null
.
+ * This method uses {@link String#indexOf(String)}
A null
String will return -1
.
+ * StringUtils.contains(null, null) = false + * StringUtils.contains("", null) = false + * StringUtils.contains("", "") = true + * StringUtils.contains("abc", "") = true + * StringUtils.contains("abc", "a") = true + * StringUtils.contains("abc", "z") = false + *+ * + * @param str the String to check, may be null + * @param searchStr the String to find, may be null + * @return true if the String contains the search character, + * false if not or
null
string input
+ */
+ public static boolean contains(String str, String searchStr) {
+ if (str == null || searchStr == null) {
+ return false;
+ }
+ return (str.indexOf(searchStr) >= 0);
+ }
+
+ // IndexOfAny
+ //-----------------------------------------------------------------------
+
/**
* Find the first index of any of a set of potential substrings.
* @@ -554,6 +858,9 @@ public class StringUtils { return ret; } + // IndexOfAnyBut + //----------------------------------------------------------------------- + /** *Search a String to find the first index of any * character not in the given set of characters.
@@ -591,7 +898,7 @@ public class StringUtils { return -1; } - // Contains + // ContainsOnly //----------------------------------------------------------------------- /** @@ -651,6 +958,9 @@ public class StringUtils { return containsOnly(str, validChars.toCharArray()); } + // ContainsNone + //----------------------------------------------------------------------- + /** *Checks that the String does not contain certain characters.
* diff --git a/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java b/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java index 3dc4574c4..42b1dda4d 100644 --- a/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java @@ -63,7 +63,7 @@ import junit.textui.TestRunner; * * @author Stephen Colebourne * @author Ringo De Smet - * @version $Id: StringUtilsEqualsIndexOfTest.java,v 1.2 2003/03/23 21:50:58 scolebourne Exp $ + * @version $Id: StringUtilsEqualsIndexOfTest.java,v 1.3 2003/07/19 23:29:06 scolebourne Exp $ */ public class StringUtilsEqualsIndexOfTest extends TestCase { private static final String FOO = "foo"; @@ -115,6 +115,131 @@ public class StringUtilsEqualsIndexOfTest extends TestCase { assertEquals(false, StringUtils.equalsIgnoreCase(null, FOO)); } + //----------------------------------------------------------------------- + public void testIndexOf_char() { + assertEquals(-1, StringUtils.indexOf(null, ' ')); + assertEquals(-1, StringUtils.indexOf("", ' ')); + assertEquals(0, StringUtils.indexOf("aabaabaa", 'a')); + assertEquals(2, StringUtils.indexOf("aabaabaa", 'b')); + } + + public void testIndexOf_charInt() { + assertEquals(-1, StringUtils.indexOf(null, ' ', 0)); + assertEquals(-1, StringUtils.indexOf(null, ' ', -1)); + assertEquals(-1, StringUtils.indexOf("", ' ', 0)); + assertEquals(-1, StringUtils.indexOf("", ' ', -1)); + assertEquals(0, StringUtils.indexOf("aabaabaa", 'a', 0)); + assertEquals(2, StringUtils.indexOf("aabaabaa", 'b', 0)); + assertEquals(5, StringUtils.indexOf("aabaabaa", 'b', 3)); + assertEquals(-1, StringUtils.indexOf("aabaabaa", 'b', 9)); + assertEquals(2, StringUtils.indexOf("aabaabaa", 'b', -1)); + } + + public void testIndexOf_String() { + assertEquals(-1, StringUtils.indexOf(null, null)); + assertEquals(-1, StringUtils.indexOf("", null)); + assertEquals(0, StringUtils.indexOf("", "")); + assertEquals(0, StringUtils.indexOf("aabaabaa", "a")); + assertEquals(2, StringUtils.indexOf("aabaabaa", "b")); + assertEquals(1, StringUtils.indexOf("aabaabaa", "ab")); + } + + public void testIndexOf_StringInt() { + assertEquals(-1, StringUtils.indexOf(null, null, 0)); + assertEquals(-1, StringUtils.indexOf(null, null, -1)); + assertEquals(-1, StringUtils.indexOf(null, "", 0)); + assertEquals(-1, StringUtils.indexOf(null, "", -1)); + assertEquals(-1, StringUtils.indexOf("", null, 0)); + assertEquals(-1, StringUtils.indexOf("", null, -1)); + assertEquals(0, StringUtils.indexOf("", "", 0)); + assertEquals(0, StringUtils.indexOf("", "", -1)); + assertEquals(0, StringUtils.indexOf("", "", 9)); + assertEquals(0, StringUtils.indexOf("abc", "", 0)); + assertEquals(0, StringUtils.indexOf("abc", "", -1)); + assertEquals(3, StringUtils.indexOf("abc", "", 9)); + assertEquals(0, StringUtils.indexOf("aabaabaa", "a", 0)); + assertEquals(2, StringUtils.indexOf("aabaabaa", "b", 0)); + assertEquals(1, StringUtils.indexOf("aabaabaa", "ab", 0)); + assertEquals(5, StringUtils.indexOf("aabaabaa", "b", 3)); + assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9)); + assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1)); + } + + //----------------------------------------------------------------------- + public void testLastIndexOf_char() { + assertEquals(-1, StringUtils.lastIndexOf(null, ' ')); + assertEquals(-1, StringUtils.lastIndexOf("", ' ')); + assertEquals(7, StringUtils.lastIndexOf("aabaabaa", 'a')); + assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b')); + } + + public void testLastIndexOf_charInt() { + assertEquals(-1, StringUtils.lastIndexOf(null, ' ', 0)); + assertEquals(-1, StringUtils.lastIndexOf(null, ' ', -1)); + assertEquals(-1, StringUtils.lastIndexOf("", ' ', 0)); + assertEquals(-1, StringUtils.lastIndexOf("", ' ', -1)); + assertEquals(7, StringUtils.lastIndexOf("aabaabaa", 'a', 8)); + assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b', 8)); + assertEquals(2, StringUtils.lastIndexOf("aabaabaa", 'b', 3)); + assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b', 9)); + assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", 'b', -1)); + } + + public void testLastIndexOf_String() { + assertEquals(-1, StringUtils.lastIndexOf(null, null)); + assertEquals(-1, StringUtils.lastIndexOf("", null)); + assertEquals(0, StringUtils.lastIndexOf("", "")); + assertEquals(7, StringUtils.lastIndexOf("aabaabaa", "a")); + assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b")); + assertEquals(4, StringUtils.lastIndexOf("aabaabaa", "ab")); + } + + public void testLastIndexOf_StringInt() { + assertEquals(-1, StringUtils.lastIndexOf(null, null, 0)); + assertEquals(-1, StringUtils.lastIndexOf(null, null, -1)); + assertEquals(-1, StringUtils.lastIndexOf(null, "", 0)); + assertEquals(-1, StringUtils.lastIndexOf(null, "", -1)); + assertEquals(-1, StringUtils.lastIndexOf("", null, 0)); + assertEquals(-1, StringUtils.lastIndexOf("", null, -1)); + assertEquals(0, StringUtils.lastIndexOf("", "", 0)); + assertEquals(-1, StringUtils.lastIndexOf("", "", -1)); + assertEquals(0, StringUtils.lastIndexOf("", "", 9)); + assertEquals(0, StringUtils.lastIndexOf("abc", "", 0)); + assertEquals(-1, StringUtils.lastIndexOf("abc", "", -1)); + assertEquals(3, StringUtils.lastIndexOf("abc", "", 9)); + assertEquals(7, StringUtils.lastIndexOf("aabaabaa", "a", 8)); + assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b", 8)); + assertEquals(4, StringUtils.lastIndexOf("aabaabaa", "ab", 8)); + assertEquals(2, StringUtils.lastIndexOf("aabaabaa", "b", 3)); + assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b", 9)); + assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", -1)); + } + + //----------------------------------------------------------------------- + public void contains_char() { + assertEquals(false, StringUtils.contains(null, ' ')); + assertEquals(false, StringUtils.contains("", ' ')); + assertEquals(true, StringUtils.contains("abc", 'a')); + assertEquals(true, StringUtils.contains("abc", 'b')); + assertEquals(true, StringUtils.contains("abc", 'c')); + assertEquals(false, StringUtils.contains("abc", 'z')); + } + + public void contains_String() { + assertEquals(false, StringUtils.contains(null, null)); + assertEquals(false, StringUtils.contains(null, "")); + assertEquals(false, StringUtils.contains(null, "a")); + assertEquals(false, StringUtils.contains("", null)); + assertEquals(true, StringUtils.contains("", "")); + assertEquals(false, StringUtils.contains("", "a")); + assertEquals(true, StringUtils.contains("abc", "a")); + assertEquals(true, StringUtils.contains("abc", "b")); + assertEquals(true, StringUtils.contains("abc", "c")); + assertEquals(true, StringUtils.contains("abc", "abc")); + assertEquals(false, StringUtils.contains("abc", "z")); + } + + //----------------------------------------------------------------------- public void testIndexOfAny() { assertEquals(-1, StringUtils.indexOfAny(null, null)); assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY)); @@ -133,4 +258,128 @@ public class StringUtilsEqualsIndexOfTest extends TestCase { assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR, new String[] {"llll"})); } + //----------------------------------------------------------------------- + public void testIndexOfAnyBut() { + String str1 = "a"; + String str2 = "b"; + String str3 = "ab"; + String chars1= "b"; + String chars2= "a"; + String chars3= "ab"; + assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null)); + assertEquals(-1, StringUtils.indexOfAnyBut("", (String) null)); + assertEquals(-1, StringUtils.indexOfAnyBut(null, "")); + assertEquals(0, StringUtils.indexOfAnyBut(str1, "")); + assertEquals(-1, StringUtils.indexOfAnyBut("", "")); + assertEquals(-1, StringUtils.indexOfAnyBut("", chars1)); + assertEquals(0, StringUtils.indexOfAnyBut(str1, chars1)); + assertEquals(-1, StringUtils.indexOfAnyBut(str1, chars2)); + assertEquals(-1, StringUtils.indexOfAnyBut(str1, chars3)); + assertEquals(-1, StringUtils.indexOfAnyBut(str2, chars1)); + assertEquals(0, StringUtils.indexOfAnyBut(str2, chars2)); + assertEquals(-1, StringUtils.indexOfAnyBut(str2, chars3)); + assertEquals(0, StringUtils.indexOfAnyBut(str3, chars1)); + assertEquals(1, StringUtils.indexOfAnyBut(str3, chars2)); + assertEquals(-1, StringUtils.indexOfAnyBut(str3, chars3)); + } + + //----------------------------------------------------------------------- + public void testContainsOnly_String() { + String str1 = "a"; + String str2 = "b"; + String str3 = "ab"; + String chars1= "b"; + String chars2= "a"; + String chars3= "ab"; + assertEquals(false, StringUtils.containsOnly(null, (String) null)); + assertEquals(false, StringUtils.containsOnly("", (String) null)); + assertEquals(false, StringUtils.containsOnly(null, "")); + assertEquals(false, StringUtils.containsOnly(str1, "")); + assertEquals(true, StringUtils.containsOnly("", "")); + assertEquals(true, StringUtils.containsOnly("", chars1)); + assertEquals(false, StringUtils.containsOnly(str1, chars1)); + assertEquals(true, StringUtils.containsOnly(str1, chars2)); + assertEquals(true, StringUtils.containsOnly(str1, chars3)); + assertEquals(true, StringUtils.containsOnly(str2, chars1)); + assertEquals(false, StringUtils.containsOnly(str2, chars2)); + assertEquals(true, StringUtils.containsOnly(str2, chars3)); + assertEquals(false, StringUtils.containsOnly(str3, chars1)); + assertEquals(false, StringUtils.containsOnly(str3, chars2)); + assertEquals(true, StringUtils.containsOnly(str3, chars3)); + } + + public void testContainsOnly_CharArray() { + String str1 = "a"; + String str2 = "b"; + String str3 = "ab"; + char[] chars1= {'b'}; + char[] chars2= {'a'}; + char[] chars3= {'a', 'b'}; + char[] emptyChars = new char[0]; + assertEquals(false, StringUtils.containsOnly(null, (char[]) null)); + assertEquals(false, StringUtils.containsOnly("", (char[]) null)); + assertEquals(false, StringUtils.containsOnly(null, emptyChars)); + assertEquals(false, StringUtils.containsOnly(str1, emptyChars)); + assertEquals(true, StringUtils.containsOnly("", emptyChars)); + assertEquals(true, StringUtils.containsOnly("", chars1)); + assertEquals(false, StringUtils.containsOnly(str1, chars1)); + assertEquals(true, StringUtils.containsOnly(str1, chars2)); + assertEquals(true, StringUtils.containsOnly(str1, chars3)); + assertEquals(true, StringUtils.containsOnly(str2, chars1)); + assertEquals(false, StringUtils.containsOnly(str2, chars2)); + assertEquals(true, StringUtils.containsOnly(str2, chars3)); + assertEquals(false, StringUtils.containsOnly(str3, chars1)); + assertEquals(false, StringUtils.containsOnly(str3, chars2)); + assertEquals(true, StringUtils.containsOnly(str3, chars3)); + } + + public void testContainsNone_String() { + String str1 = "a"; + String str2 = "b"; + String str3 = "ab."; + String chars1= "b"; + String chars2= "."; + String chars3= "cd"; + assertEquals(true, StringUtils.containsNone(null, (String) null)); + assertEquals(true, StringUtils.containsNone("", (String) null)); + assertEquals(true, StringUtils.containsNone(null, "")); + assertEquals(true, StringUtils.containsNone(str1, "")); + assertEquals(true, StringUtils.containsNone("", "")); + assertEquals(true, StringUtils.containsNone("", chars1)); + assertEquals(true, StringUtils.containsNone(str1, chars1)); + assertEquals(true, StringUtils.containsNone(str1, chars2)); + assertEquals(true, StringUtils.containsNone(str1, chars3)); + assertEquals(false, StringUtils.containsNone(str2, chars1)); + assertEquals(true, StringUtils.containsNone(str2, chars2)); + assertEquals(true, StringUtils.containsNone(str2, chars3)); + assertEquals(false, StringUtils.containsNone(str3, chars1)); + assertEquals(false, StringUtils.containsNone(str3, chars2)); + assertEquals(true, StringUtils.containsNone(str3, chars3)); + } + + public void testContainsNone_CharArray() { + String str1 = "a"; + String str2 = "b"; + String str3 = "ab."; + char[] chars1= {'b'}; + char[] chars2= {'.'}; + char[] chars3= {'c', 'd'}; + char[] emptyChars = new char[0]; + assertEquals(true, StringUtils.containsNone(null, (char[]) null)); + assertEquals(true, StringUtils.containsNone("", (char[]) null)); + assertEquals(true, StringUtils.containsNone(null, emptyChars)); + assertEquals(true, StringUtils.containsNone(str1, emptyChars)); + assertEquals(true, StringUtils.containsNone("", emptyChars)); + assertEquals(true, StringUtils.containsNone("", chars1)); + assertEquals(true, StringUtils.containsNone(str1, chars1)); + assertEquals(true, StringUtils.containsNone(str1, chars2)); + assertEquals(true, StringUtils.containsNone(str1, chars3)); + assertEquals(false, StringUtils.containsNone(str2, chars1)); + assertEquals(true, StringUtils.containsNone(str2, chars2)); + assertEquals(true, StringUtils.containsNone(str2, chars3)); + assertEquals(false, StringUtils.containsNone(str3, chars1)); + assertEquals(false, StringUtils.containsNone(str3, chars2)); + assertEquals(true, StringUtils.containsNone(str3, chars3)); + } + }