Repository: activemq Updated Branches: refs/heads/master 5eeb62a6b -> 33dded13d
https://issues.apache.org/jira/browse/AMQ-6036 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. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/33dded13 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/33dded13 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/33dded13 Branch: refs/heads/master Commit: 33dded13dfa17eca1911fde46464edab60756ee2 Parents: 5eeb62a Author: Christopher L. Shannon (cshannon) <[email protected]> Authored: Thu Feb 4 16:53:02 2016 +0000 Committer: Christopher L. Shannon (cshannon) <[email protected]> Committed: Thu Feb 4 16:53:02 2016 +0000 ---------------------------------------------------------------------- .../plugin/SubQueueSelectorCacheBroker.java | 33 +++++++++----------- 1 file changed, 15 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/33dded13/activemq-broker/src/main/java/org/apache/activemq/plugin/SubQueueSelectorCacheBroker.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/plugin/SubQueueSelectorCacheBroker.java b/activemq-broker/src/main/java/org/apache/activemq/plugin/SubQueueSelectorCacheBroker.java index 30c8784..f6403eb 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/plugin/SubQueueSelectorCacheBroker.java +++ b/activemq-broker/src/main/java/org/apache/activemq/plugin/SubQueueSelectorCacheBroker.java @@ -169,7 +169,7 @@ public class SubQueueSelectorCacheBroker extends BrokerFilter implements Runnabl static boolean hasWildcards(String selector) { - return new WildcardFinder(selector).hasWildcards(); + return WildcardFinder.hasWildcards(selector); } @Override @@ -317,17 +317,16 @@ public class SubQueueSelectorCacheBroker extends BrokerFilter implements Runnabl Pattern.CASE_INSENSITIVE); private static final String REGEX_SPECIAL = ".+?*(){}[]\\-"; - private final Matcher matcher; - WildcardFinder(String selector) { - this.matcher = LIKE_PATTERN.matcher(selector); + private static String getLike(final Matcher matcher) { + return matcher.group("like"); } - private String getLike() { - return matcher.group("like"); + private static boolean hasLikeOperator(final Matcher matcher) { + return matcher.find(); } - private String getEscape() { + private static String getEscape(final Matcher matcher) { String escapeChar = matcher.group("escape"); if (escapeChar == null) { return null; @@ -337,21 +336,19 @@ public class SubQueueSelectorCacheBroker extends BrokerFilter implements Runnabl return escapeChar; } - private boolean hasLikeOperator() { - return matcher.find(); - } - - boolean hasWildcardInCurrentMatch() { + private static boolean hasWildcardInCurrentMatch(final Matcher matcher) { String wildcards = "[_%]"; - if (getEscape() != null) { - wildcards = "(^|[^" + getEscape() + "])" + wildcards; + if (getEscape(matcher) != null) { + wildcards = "(^|[^" + getEscape(matcher) + "])" + wildcards; } - return Pattern.compile(wildcards).matcher(getLike()).find(); + return Pattern.compile(wildcards).matcher(getLike(matcher)).find(); } - public boolean hasWildcards() { - while(hasLikeOperator()) { - if (hasWildcardInCurrentMatch()) + public static boolean hasWildcards(String selector) { + Matcher matcher = LIKE_PATTERN.matcher(selector); + + while(hasLikeOperator(matcher)) { + if (hasWildcardInCurrentMatch(matcher)) return true; } return false;
