You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/07/11 06:21:42 UTC

svn commit: r420708 - in /incubator/activemq/trunk/activemq-core: ./ src/main/java/org/apache/activemq/filter/ src/test/java/org/apache/activemq/filter/

Author: chirino
Date: Mon Jul 10 21:21:40 2006
New Revision: 420708

URL: http://svn.apache.org/viewvc?rev=420708&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQ-808

Modified:
    incubator/activemq/trunk/activemq-core/pom.xml
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.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/pom.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/pom.xml?rev=420708&r1=420707&r2=420708&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/pom.xml (original)
+++ incubator/activemq/trunk/activemq-core/pom.xml Mon Jul 10 21:21:40 2006
@@ -293,6 +293,7 @@
       </plugin>
 
       <!-- Use Gram to Gernerate the OpenWire Marshallers -->
+      <!--
       <plugin>
         <groupId>incubator-activemq</groupId>
         <artifactId>maven-gram-plugin</artifactId>
@@ -321,6 +322,7 @@
           </dependency>
         </dependencies>
       </plugin>
+      -->
 
       <plugin>
         <artifactId>maven-antrun-plugin</artifactId>

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java?rev=420708&r1=420707&r2=420708&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java Mon Jul 10 21:21:40 2006
@@ -162,17 +162,20 @@
 
     /**
      * @param dest
+     * @return 
      */
-    public void removeAll(ActiveMQDestination key) {
+    public Set removeAll(ActiveMQDestination key) {
+        Set rc = new HashSet();
         if (key.isComposite()) {
             ActiveMQDestination[] destinations = key.getCompositeDestinations();
             for (int i = 0; i < destinations.length; i++) {
-                removeAll(destinations[i]);
+                rc.add( removeAll(destinations[i]) );
             }
-            return;
+            return rc;
         }
         String[] paths = key.getDestinationPaths();
-        getRootNode(key).removeAll(paths, 0);
+        getRootNode(key).removeAll(rc, paths, 0);
+        return rc;
     }
 
     /**

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java?rev=420708&r1=420707&r2=420708&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 Mon Jul 10 21:21:40 2006
@@ -94,6 +94,31 @@
     }
 
     /**
+     * Returns a mutable List of the values available at this node in the tree
+     */
+    public List removeValues() {
+    	ArrayList v = new ArrayList(values);
+    	parent.getAnyChildNode().getValues().removeAll(v);
+    	values.clear();
+    	pruneIfEmpty();
+        return v;
+    }
+    
+    
+    public Set removeDesendentValues() {
+        Set answer = new HashSet();
+        removeDesendentValues(answer);
+        return answer;
+    }
+    
+    protected void removeDesendentValues(Set answer) {
+        if (anyChild != null) {
+            anyChild.removeDesendentValues(answer);
+        }
+        answer.addAll(removeValues());
+    }
+
+    /**
      * Returns a list of all the values from this node down the tree
      */
     public Set getDesendentValues() {
@@ -133,20 +158,45 @@
         }
     }
 
-    public void removeAll(String[] paths, int idx) {
-        if (idx >= paths.length) {
-            values.clear();
-            pruneIfEmpty();
-        }
-        else {
-            if (idx == paths.length - 1) {
-                getAnyChildNode().getValues().clear();
+    public void removeAll(Set answer, String[] paths, int startIndex) {
+//        if (idx >= paths.length) {
+//            values.clear();
+//            pruneIfEmpty();
+//        }
+//        else {
+//            if (idx == paths.length - 1) {
+//                getAnyChildNode().getValues().clear();
+//            }
+//            else {
+//                getAnyChildNode().removeAll(paths, idx + 1);
+//            }
+//            getChildOrCreate(paths[idx]).removeAll(paths, ++idx);
+//        }
+//        
+        
+        DestinationMapNode node = this;
+        for (int i = startIndex, size = paths.length; i < size && node != null; i++) {
+
+        	String path = paths[i];
+            if (path.equals(ANY_DESCENDENT)) {
+                answer.addAll(node.removeDesendentValues());
+                break;
+            }
+
+            node.appendMatchingWildcards(answer, paths, i);
+            if (path.equals(ANY_CHILD)) {
+                node = node.getAnyChildNode();
             }
             else {
-                getAnyChildNode().removeAll(paths, idx + 1);
+                node = node.getChild(path);
             }
-            getChildOrCreate(paths[idx]).removeAll(paths, ++idx);
         }
+        
+        if (node != null) {
+            answer.addAll(node.removeValues());
+        }
+
+        
     }
 
     protected void appendDescendantValues(Set answer) {

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java?rev=420708&r1=420707&r2=420708&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 Mon Jul 10 21:21:40 2006
@@ -285,6 +285,21 @@
         assertMapValue("TEST.*.*", v3, v5);
         assertMapValue("TEST.BAR.*", v3);
     }
+    
+    public void testAddAndRemove() throws Exception {
+    	
+        put("FOO.A", v1);
+        assertMapValue("FOO.>", v1);
+        
+        put("FOO.B", v2);        
+        assertMapValue("FOO.>", v1, v2);
+        
+        Set set = map.removeAll(createDestination("FOO.A"));
+        
+        assertMapValue("FOO.>", v2);
+        
+    }
+
 
     protected void loadSample2() {
         put("TEST.FOO", v1);