Always return false to contains a null word
This commit is contained in:
parent
54facb4fd9
commit
633ce60496
|
@ -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;
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue