visited.add(node);
List<TransferParent> results = new ArrayList<TransferParent>();
if (node.isExitAllowed()) {
TransferNode extended = root.extendTree(node.getToStop(),
node.getFromStop(), exitAllowed);
results.add(extended);
}
for (TransferNode subNode : node.getTransfers()) {
/**
* There can be circular paths in the transfer tree. If we've already
* visited the sub-node, we don't visit it again.
*/
if (visited.contains(subNode))
continue;
List<TransferParent> parents = reverseTree(subNode, root, false, visited);
for (TransferParent parent : parents) {
TransferNode extended = parent.extendTree(node.getToStop(),
node.getFromStop(), exitAllowed);
results.add(extended);
}
}