Search in sources :

Example 1 with InvalidSelectionServiceException

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();
}
Also used : StopSelectionTreeBean(org.onebusaway.presentation.model.StopSelectionTreeBean) InvalidSelectionServiceException(org.onebusaway.exceptions.InvalidSelectionServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean)

Aggregations

InvalidSelectionServiceException (org.onebusaway.exceptions.InvalidSelectionServiceException)1 StopSelectionTreeBean (org.onebusaway.presentation.model.StopSelectionTreeBean)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1