activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r365882 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/filter/DestinationMapEntry.java main/java/org/apache/activemq/filter/DestinationMapNode.java test/java/org/apache/activemq/filter/DestinationMapTest.java
Date Wed, 04 Jan 2006 10:30:48 GMT
Author: jstrachan
Date: Wed Jan  4 02:30:40 2006
New Revision: 365882

URL: http://svn.apache.org/viewcvs?rev=365882&view=rev
Log:
fixed edge cases in DestinationMap

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java?rev=365882&r1=365881&r2=365882&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java
Wed Jan  4 02:30:40 2006
@@ -27,9 +27,23 @@
  * 
  * @version $Revision: 1.1 $
  */
-public abstract class DestinationMapEntry implements InitializingBean {
+public abstract class DestinationMapEntry implements InitializingBean, Comparable {
 
     private ActiveMQDestination destination;
+
+    
+    public int compareTo(Object that) {
+        if (that instanceof DestinationMapEntry) {
+            DestinationMapEntry thatEntry = (DestinationMapEntry) that;
+            return ActiveMQDestination.compare(destination, thatEntry.destination);
+        }
+        else if (that == null) {
+            return 1;
+        }
+        else {
+            return getClass().getName().compareTo(that.getClass().getName());
+        }
+    }
 
     /**
      * A helper method to set the destination from a configuration file

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java?rev=365882&r1=365881&r2=365882&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
Wed Jan  4 02:30:40 2006
@@ -25,7 +25,7 @@
 
 /**
  * An implementation class used to implement {@link DestinationMap}
- *
+ * 
  * @version $Revision: 1.2 $
  */
 public class DestinationMapNode {
@@ -38,14 +38,13 @@
     protected static final String ANY_CHILD = DestinationMap.ANY_CHILD;
     protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
 
-
     public DestinationMapNode(DestinationMapNode parent) {
         this.parent = parent;
     }
-    
 
     /**
-     * Returns the child node for the given named path or null if it does not exist
+     * Returns the child node for the given named path or null if it does not
+     * exist
      */
     public DestinationMapNode getChild(String path) {
         return (DestinationMapNode) childNodes.get(path);
@@ -54,10 +53,10 @@
     public int getChildCount() {
         return childNodes.size();
     }
-    
+
     /**
-     * Returns the child node for the given named path, lazily creating one if it does
-     * not yet exist
+     * Returns the child node for the given named path, lazily creating one if
+     * it does not yet exist
      */
     public DestinationMapNode getChildOrCreate(String path) {
         DestinationMapNode answer = (DestinationMapNode) childNodes.get(path);
@@ -169,10 +168,12 @@
 
     public void appendMatchingValues(Set answer, String[] paths, int startIndex) {
         DestinationMapNode node = this;
+        boolean couldMatchAny = true;
         for (int i = startIndex, size = paths.length; i < size && node != null;
i++) {
             String path = paths[i];
             if (path.equals(ANY_DESCENDENT)) {
                 answer.addAll(node.getDesendentValues());
+                couldMatchAny = false;
                 break;
             }
 
@@ -186,10 +187,16 @@
         }
         if (node != null) {
             answer.addAll(node.getValues());
+            if (couldMatchAny) {
+                // lets allow FOO.BAR to match the FOO.BAR.> entry in the map
+                DestinationMapNode child = node.getChild(ANY_DESCENDENT);
+                if (child != null) {
+                    answer.addAll(child.getValues());
+                }
+            }
         }
     }
 
-
     public String getPath() {
         return path;
     }
@@ -199,7 +206,6 @@
             parent.removeChild(this);
         }
     }
-
 
     protected void removeChild(DestinationMapNode node) {
         childNodes.remove(node.getPath());

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java?rev=365882&r1=365881&r2=365882&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
Wed Jan  4 02:30:40 2006
@@ -165,20 +165,34 @@
         put("TEST.XYZ.D4", v4);
         put("TEST.BAR.D3", v5);
         put("TEST.*.D2", v6);
-
-
+        
+        
         assertMapValue("TEST.*.D3", v2, v3, v5);
         assertMapValue("TEST.*.D4", v2, v4);
-
+        
         assertMapValue("TEST.*", v1, v2);
         assertMapValue("TEST.*.*", v2, v3, v4, v5, v6);
         assertMapValue("*.*.D3", v2, v3, v5);
         assertMapValue("TEST.BAR.*", v2, v5, v6);
-
+        
         assertMapValue("TEST.BAR.D2", v2, v6);
         assertMapValue("TEST.*.D2", v2, v6);
         assertMapValue("TEST.BAR.*", v2, v5, v6);
     }
+    
+    public void testAnyPathWildcardInMap() throws Exception {
+        put("TEST.FOO.>", v1);
+
+
+        assertMapValue("TEST.FOO.BAR.WHANOT.A.B.C", v1);
+        assertMapValue("TEST.FOO.BAR.WHANOT", v1);
+        assertMapValue("TEST.FOO.BAR", v1);
+        
+        assertMapValue("TEST.*.*", v1);
+        assertMapValue("TEST.BAR", null);
+        
+        assertMapValue("TEST.FOO", v1);
+     }
 
     public void testSimpleAddRemove() throws Exception {
         put("TEST.D1", v2);



Mime
View raw message