use of org.onebusaway.exceptions.InvalidSelectionServiceException in project onebusaway-application-modules by camsys.
the class StopSelectionServiceImpl method visitTree.
private void visitTree(StopSelectionTreeBean tree, StopSelectionBean selection, List<Integer> selectionIndices, int index) throws InvalidSelectionServiceException {
// If we have a stop, we have no choice but to return
if (tree.hasStop()) {
selection.setStop(tree.getStop());
return;
}
Set<NameBean> names = tree.getNames();
// If we've only got one name, short circuit
if (names.size() == 1) {
NameBean next = names.iterator().next();
selection.addSelected(next);
StopSelectionTreeBean subtree = tree.getSubTree(next);
visitTree(subtree, selection, selectionIndices, index);
return;
}
if (index >= selectionIndices.size()) {
for (NameBean name : names) {
StopBean stop = getStop(tree.getSubTree(name));
if (stop != null) {
selection.addNameWithStop(name, stop);
} else {
selection.addName(name);
}
}
List<StopBean> stops = tree.getAllStops();
for (StopBean stop : stops) selection.addStop(stop);
return;
} else {
int i = 0;
int selectionIndex = selectionIndices.get(index);
for (NameBean name : names) {
if (selectionIndex == i) {
selection.addSelected(name);
tree = tree.getSubTree(name);
visitTree(tree, selection, selectionIndices, index + 1);
return;
}
i++;
}
}
// If we made it here...
throw new InvalidSelectionServiceException();
}
Aggregations