Search in sources :

Example 1 with StopSelectionTreeBean

use of org.onebusaway.presentation.model.StopSelectionTreeBean in project onebusaway-application-modules by camsys.

the class StopSelectionServiceImpl method getSelectedStops.

public StopSelectionBean getSelectedStops(StopsForRouteBean stopsForRoute, List<Integer> selectionIndices) throws InvalidSelectionServiceException {
    StopSelectionBean selection = new StopSelectionBean();
    StopSelectionTreeBean tree = getStopsForRouteAsStopSelectionTree(stopsForRoute);
    visitTree(tree, selection, selectionIndices, 0);
    return selection;
}
Also used : StopSelectionTreeBean(org.onebusaway.presentation.model.StopSelectionTreeBean) StopSelectionBean(org.onebusaway.presentation.model.StopSelectionBean)

Example 2 with StopSelectionTreeBean

use of org.onebusaway.presentation.model.StopSelectionTreeBean in project onebusaway-application-modules by camsys.

the class StopSelectionServiceImpl method groupByStop.

private void groupByStop(StopSelectionTreeBean tree, Iterable<StopBean> stops) {
    for (StopBean stop : stops) {
        StopSelectionTreeBean subTree = tree;
        if (_splitStopNames) {
            List<NameBean> names = _locationNameSplitStrategy.splitLocationNameIntoParts(stop.getName());
            for (NameBean name : names) subTree = subTree.getSubTree(name);
        } else {
            NameBean name = new NameBean(SelectionNameTypes.STOP_NAME, stop.getName());
            subTree = subTree.getSubTree(name);
        }
        // As a last resort, we extend the tree by the stop number (guaranteed to
        // be unique)
        String code = stop.getCode() != null ? stop.getCode() : stop.getId();
        NameBean name = new NameBean(SelectionNameTypes.STOP_DESCRIPTION, "Stop # " + code);
        subTree = subTree.getSubTree(name);
        subTree.setStop(stop);
    }
}
Also used : StopSelectionTreeBean(org.onebusaway.presentation.model.StopSelectionTreeBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 3 with StopSelectionTreeBean

use of org.onebusaway.presentation.model.StopSelectionTreeBean 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)

Example 4 with StopSelectionTreeBean

use of org.onebusaway.presentation.model.StopSelectionTreeBean in project onebusaway-application-modules by camsys.

the class StopSelectionServiceImpl method getStopsForRouteAsStopSelectionTree.

/**
 **
 * Private Methods
 ***
 */
private StopSelectionTreeBean getStopsForRouteAsStopSelectionTree(StopsForRouteBean stopsForRoute) {
    StopSelectionTreeBean tree = new StopSelectionTreeBean();
    StopGroupingBean byDirection = getGroupingByType(stopsForRoute, TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
    Map<String, StopBean> stopsById = getStopsById(stopsForRoute);
    if (byDirection != null) {
        groupByDirection(tree, stopsForRoute, byDirection, stopsById);
    } else {
        groupByStop(tree, stopsForRoute.getStops());
    }
    return tree;
}
Also used : StopSelectionTreeBean(org.onebusaway.presentation.model.StopSelectionTreeBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 5 with StopSelectionTreeBean

use of org.onebusaway.presentation.model.StopSelectionTreeBean in project onebusaway-application-modules by camsys.

the class StopSelectionServiceImpl method groupByDirection.

private void groupByDirection(StopSelectionTreeBean tree, StopsForRouteBean stopsForRoute, StopGroupingBean byDirection, Map<String, StopBean> stopsById) {
    List<StopGroupBean> groups = byDirection.getStopGroups();
    if (groups.isEmpty()) {
        groupByStop(tree, stopsForRoute.getStops());
        return;
    }
    for (StopGroupBean group : groups) {
        StopSelectionTreeBean subTree = tree.getSubTree(group.getName());
        List<StopBean> stops = new ArrayList<StopBean>();
        for (String stopId : group.getStopIds()) stops.add(stopsById.get(stopId));
        groupByStop(subTree, stops);
    }
}
Also used : StopSelectionTreeBean(org.onebusaway.presentation.model.StopSelectionTreeBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Aggregations

StopSelectionTreeBean (org.onebusaway.presentation.model.StopSelectionTreeBean)5 StopBean (org.onebusaway.transit_data.model.StopBean)4 NameBean (org.onebusaway.transit_data.model.NameBean)2 ArrayList (java.util.ArrayList)1 InvalidSelectionServiceException (org.onebusaway.exceptions.InvalidSelectionServiceException)1 StopSelectionBean (org.onebusaway.presentation.model.StopSelectionBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1