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