[New] Added array as AND searching in contains*()

This commit is contained in:
Robert von Burg 2018-04-19 12:21:48 +02:00
parent 1729460784
commit 164fc0ac80
2 changed files with 32 additions and 6 deletions

View File

@ -365,7 +365,9 @@ public class StrolchSearchTest {
.and(param(BAG_ID, PARAM_STRING_ID, isNotEqualTo("dfgdfg")))
.and(param(BAG_ID, PARAM_STRING_ID, isNotEqualToIgnoreCase("dfgdfg")))
.and(param(BAG_ID, PARAM_STRING_ID, contains("rol")))
.and(param(BAG_ID, PARAM_STRING_ID, contains(new String[] { "Str", "rol" })))
.and(param(BAG_ID, PARAM_STRING_ID, containsIgnoreCase("ROL")))
.and(param(BAG_ID, PARAM_STRING_ID, containsIgnoreCase(new String[] { "STR", "ROL" })))
.and(param(BAG_ID, PARAM_STRING_ID, startsWith("Str")))
.and(param(BAG_ID, PARAM_STRING_ID, startsWithIgnoreCase("str")))
.and(param(BAG_ID, PARAM_STRING_ID, endsWith("lch")))

View File

@ -60,14 +60,38 @@ public class ObjectHelper {
return collection.contains(right);
}
if (left instanceof String && right instanceof String) {
if (left instanceof String) {
String str = (String) left;
String subStr = (String) right;
if (ignoreCase)
return str.toLowerCase().contains(subStr.toLowerCase());
else
return str.contains(subStr);
if (right instanceof String[]) {
String[] arr = (String[]) right;
if (ignoreCase) {
str = str.toLowerCase();
for (String s : arr) {
if (!str.contains(s.toLowerCase()))
return false;
}
return true;
} else {
for (String s : arr) {
if (!str.contains(s))
return false;
}
return true;
}
} else if (right instanceof String) {
String subStr = (String) right;
if (ignoreCase)
return str.toLowerCase().contains(subStr.toLowerCase());
else
return str.contains(subStr);
}
}
throw new IllegalArgumentException("Unhandled type combination " + left.getClass() + " / " + right.getClass());