mirror of https://github.com/apache/activemq.git
Slight refactoring to make the WildcardFinder class use a static method so that we don't have to allocate throw away objects that will immediately be garbage collected.
This commit is contained in:
parent
5eeb62a6be
commit
33dded13df
|
@ -169,7 +169,7 @@ public class SubQueueSelectorCacheBroker extends BrokerFilter implements Runnabl
|
||||||
|
|
||||||
|
|
||||||
static boolean hasWildcards(String selector) {
|
static boolean hasWildcards(String selector) {
|
||||||
return new WildcardFinder(selector).hasWildcards();
|
return WildcardFinder.hasWildcards(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -317,17 +317,16 @@ public class SubQueueSelectorCacheBroker extends BrokerFilter implements Runnabl
|
||||||
Pattern.CASE_INSENSITIVE);
|
Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
private static final String REGEX_SPECIAL = ".+?*(){}[]\\-";
|
private static final String REGEX_SPECIAL = ".+?*(){}[]\\-";
|
||||||
private final Matcher matcher;
|
|
||||||
|
|
||||||
WildcardFinder(String selector) {
|
private static String getLike(final Matcher matcher) {
|
||||||
this.matcher = LIKE_PATTERN.matcher(selector);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getLike() {
|
|
||||||
return matcher.group("like");
|
return matcher.group("like");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getEscape() {
|
private static boolean hasLikeOperator(final Matcher matcher) {
|
||||||
|
return matcher.find();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getEscape(final Matcher matcher) {
|
||||||
String escapeChar = matcher.group("escape");
|
String escapeChar = matcher.group("escape");
|
||||||
if (escapeChar == null) {
|
if (escapeChar == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -337,21 +336,19 @@ public class SubQueueSelectorCacheBroker extends BrokerFilter implements Runnabl
|
||||||
return escapeChar;
|
return escapeChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasLikeOperator() {
|
private static boolean hasWildcardInCurrentMatch(final Matcher matcher) {
|
||||||
return matcher.find();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasWildcardInCurrentMatch() {
|
|
||||||
String wildcards = "[_%]";
|
String wildcards = "[_%]";
|
||||||
if (getEscape() != null) {
|
if (getEscape(matcher) != null) {
|
||||||
wildcards = "(^|[^" + getEscape() + "])" + wildcards;
|
wildcards = "(^|[^" + getEscape(matcher) + "])" + wildcards;
|
||||||
}
|
}
|
||||||
return Pattern.compile(wildcards).matcher(getLike()).find();
|
return Pattern.compile(wildcards).matcher(getLike(matcher)).find();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasWildcards() {
|
public static boolean hasWildcards(String selector) {
|
||||||
while(hasLikeOperator()) {
|
Matcher matcher = LIKE_PATTERN.matcher(selector);
|
||||||
if (hasWildcardInCurrentMatch())
|
|
||||||
|
while(hasLikeOperator(matcher)) {
|
||||||
|
if (hasWildcardInCurrentMatch(matcher))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue