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;
}
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);
}
}
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();
}
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;
}
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);
}
}
Aggregations