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:20:05 UTC
svn commit: r420707 - in
/incubator/activemq/branches/activemq-4.0/activemq-core/src:
main/java/org/apache/activemq/filter/ test/java/org/apache/activemq/filter/
Author: chirino
Date: Mon Jul 10 21:20:03 2006
New Revision: 420707
URL: http://svn.apache.org/viewvc?rev=420707&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQ-808
Modified:
incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java
incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
Modified: incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java?rev=420707&r1=420706&r2=420707&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java (original)
+++ incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMap.java Mon Jul 10 21:20:03 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/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java?rev=420707&r1=420706&r2=420707&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java (original)
+++ incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java Mon Jul 10 21:20:03 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/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java?rev=420707&r1=420706&r2=420707&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java (original)
+++ incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java Mon Jul 10 21:20:03 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);