public static boolean matchesWildcardQuery(String str,
String query) throws IllegalArgumentException {
int idx = query.indexOf("*");
if (idx > -1) {
// We have a wildcard search
if ((idx > 0) && (idx < (query.length() - 1))) {
throw new IllegalArgumentException(
"Wildcards not supported in middle of query string; use either 'searchtext*' or '*searchtext'");
}
if (idx == (query.length() - 1)) {
return str.startsWith(query.substring(0, idx));
} else {
return str.endsWith(query.substring(idx + 1));
}
} else {
if (str.equalsIgnoreCase(query)) {
return true;
}
}
return false;
}
|