Hiram R. Chirino 2006-07-11 04:21:40 +00:00
parent ff30070bea
commit cf5ee40d63
4 changed files with 84 additions and 14 deletions

View File

@ -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>

View File

@ -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;
}
/**

View File

@ -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) {

View File

@ -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);