Always return false to contains a null word

This commit is contained in:
Eduardo Martins 2015-05-07 14:17:28 -03:00
parent 54facb4fd9
commit 633ce60496
2 changed files with 8 additions and 4 deletions

View File

@ -565,6 +565,7 @@ public class WordUtils {
return new String(buf, 0, count);
}
//-----------------------------------------------------------------------
/**
* <p>Checks if the String contains all words in the given array.</p>
*
@ -587,12 +588,14 @@ public class WordUtils {
* @param words The array of String words to search for, may be null
* @return {@code true} if all search words are found, {@code false} otherwise
*/
public static boolean containsAllWords(String word, String... words) {
if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words)
|| (words.length == 1 && StringUtils.isBlank(words[0]))) {
public static boolean containsAllWords(CharSequence word, CharSequence... words) {
if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words)) {
return false;
}
for (String w : words) {
for (CharSequence w : words) {
if (StringUtils.isBlank(w)) {
return false;
}
Pattern p = Pattern.compile(".*\\b" + w + "\\b.*");
if (!p.matcher(word).matches()) {
return false;

View File

@ -236,6 +236,7 @@ public class WordUtilsTest {
assertFalse(WordUtils.containsAllWords("zzabyycdxx", "by"));
assertTrue(WordUtils.containsAllWords("lorem ipsum dolor sit amet", "ipsum", "lorem", "dolor"));
assertFalse(WordUtils.containsAllWords("lorem ipsum dolor sit amet", "ipsum", null, "lorem", "dolor"));
assertFalse(WordUtils.containsAllWords("lorem ipsum null dolor sit amet", "ipsum", null, "lorem", "dolor"));
assertFalse(WordUtils.containsAllWords("ab", "b"));
assertFalse(WordUtils.containsAllWords("ab", "z"));
}