private static SubscriptionNode locate(String[] subjectPathTokens, SubscriptionNode current, List<SubscriptionNode> chainFromTop, boolean createPath) {
assert (current != null);
assert (subjectPathTokens != null);
assert (subjectPathTokens.length > 0);
if (chainFromTop != null)
chainFromTop.add(current);
SubscriptionNode next = current.getChild(subjectPathTokens[0]);
if (next == null) {
if (createPath) {
next = new SubscriptionNode(current, subjectPathTokens[0], null);
current.addChild(subjectPathTokens[0], next);
} else {
return null;
}
}
if (subjectPathTokens.length > 1) {
return locate(Arrays.copyOfRange(subjectPathTokens, 1, subjectPathTokens.length), next, chainFromTop, createPath);
} else {
return next;
}
}