From cf5ee40d6397ad5e6106e74612620c797561cbd9 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Tue, 11 Jul 2006 04:21:40 +0000 Subject: [PATCH] http://issues.apache.org/activemq/browse/AMQ-808 git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@420708 13f79535-47bb-0310-9956-ffa450edef68 --- activemq-core/pom.xml | 2 + .../activemq/filter/DestinationMap.java | 11 +-- .../activemq/filter/DestinationMapNode.java | 70 ++++++++++++++++--- .../activemq/filter/DestinationMapTest.java | 15 ++++ 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/activemq-core/pom.xml b/activemq-core/pom.xml index 882071ede7..252fffaac5 100755 --- a/activemq-core/pom.xml +++ b/activemq-core/pom.xml @@ -293,6 +293,7 @@ + maven-antrun-plugin diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java index 84f3ba1b63..2cc0ed57df 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java @@ -162,17 +162,20 @@ public class DestinationMap { /** * @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; } /** diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java index 45fdaf3363..7a5272d6ee 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java @@ -93,6 +93,31 @@ public class DestinationMapNode { return values; } + /** + * 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 */ @@ -133,20 +158,45 @@ public class DestinationMapNode { } } - 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) { diff --git a/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java b/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java index 15815e9c90..b6c00cd5d7 100755 --- a/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java @@ -285,6 +285,21 @@ public class DestinationMapTest extends TestCase { 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);