https://issues.apache.org/jira/browse/AMQ-6109
The chooseValue method in DestinationMap will now always return the
exact match, if there is one, else it will then sort as before.
(cherry picked from commit 8e2176d93c95d847c813f54d54aaf9bafba4d5c4)
diff --git a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
index fd07b7a..b361203 100755
--- a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
+++ b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
@@ -16,6 +16,7 @@
*/
package org.apache.activemq.filter;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -201,12 +202,18 @@
* @return the largest matching value or null if no value matches
*/
@SuppressWarnings({"rawtypes", "unchecked"})
- public Object chooseValue(ActiveMQDestination destination) {
+ public Object chooseValue(final ActiveMQDestination destination) {
Set set = get(destination);
if (set == null || set.isEmpty()) {
return null;
}
- SortedSet sortedSet = new TreeSet(set);
+ SortedSet sortedSet = new TreeSet(new Comparator<DestinationMapEntry>() {
+ @Override
+ public int compare(DestinationMapEntry entry1, DestinationMapEntry entry2) {
+ return destination.equals(entry1.destination) ? -1 : (destination.equals(entry2.destination) ? 1 : entry1.compareTo(entry2));
+ }
+ });
+ sortedSet.addAll(set);
return sortedSet.first();
}