diff --git a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java index e16d80e521f..64368c2e07a 100644 --- a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java +++ b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java @@ -100,7 +100,7 @@ public void unsynchronizedPut(ActiveMQDestination key, Object value) { return; } String[] paths = key.getDestinationPaths(); - getRootNode(key).add(paths, 0, value); + getRootNode(key).add(paths, value); } @@ -123,7 +123,7 @@ public void unsynchronizedRemove(ActiveMQDestination key, Object value) { return; } String[] paths = key.getDestinationPaths(); - getRootNode(key).remove(paths, 0, value); + getRootNode(key).remove(paths, value); } diff --git a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMapNode.java b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMapNode.java index e7628a849ea..67fdab0fe01 100644 --- a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMapNode.java +++ b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMapNode.java @@ -17,6 +17,7 @@ package org.apache.activemq.filter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -73,14 +74,19 @@ public int getChildCount() { * 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); - if (answer == null) { - answer = createChildNode(); - answer.path = path; - childNodes.put(path, answer); + public DestinationMapNode getChildOrCreate(String[] paths) { + DestinationMapNode node = this; + for (String path : paths) { + DestinationMapNode child = (DestinationMapNode) node.childNodes.get(path); + if (child == null) { + child = node.createChildNode(); + child.path = path; + node.childNodes.put(path, child); + } + node = child; } - return answer; + + return node; } /** @@ -134,32 +140,44 @@ public Set getDesendentValues() { return answer; } - public void add(String[] paths, int idx, Object value) { - if (idx >= paths.length) { - values.add(value); + public void add(String[] paths, Object value) { + if (paths.length == 0) { + add(value); } else { - getChildOrCreate(paths[idx]).add(paths, idx + 1, value); + getChildOrCreate(paths).add(value); } } - public void set(String[] paths, int idx, Object value) { - if (idx >= paths.length) { - values.clear(); - values.add(value); + private void add(Object value) { + values.add(value); + } + + public void set(String[] paths, Object value) { + if (paths.length == 0) { + set(value); } else { - getChildOrCreate(paths[idx]).set(paths, idx + 1, value); + getChildOrCreate(paths).set(value); } } - public void remove(String[] paths, int idx, Object value) { - if (idx >= paths.length) { - values.remove(value); - pruneIfEmpty(); + private void set(Object value) { + values.clear(); + values.add(value); + } + + public void remove(String[] paths, Object value) { + if (paths.length == 0) { + remove(value); } else { - getChildOrCreate(paths[idx]).remove(paths, ++idx, value); + getChildOrCreate(paths).remove(value); } } + private void remove(Object value) { + values.remove(value); + pruneIfEmpty(); + } + public void removeAll(Set answer, String[] paths, int startIndex) { DestinationNode node = this; int size = paths.length;