use of org.onebusaway.transit_data.model.NameBean in project onebusaway-application-modules by camsys.
the class NameComponent method end.
@Override
public boolean end(Writer writer, String body) {
if (_value == null)
_value = "top";
Object obj = findValue(_value);
if (obj instanceof NameBean) {
NameBean name = (NameBean) obj;
String value = name.getName();
try {
if (value != null)
writer.write(value);
} catch (IOException e) {
LOG.error("Could not write out Text tag", e);
}
}
return super.end(writer, "");
}
use of org.onebusaway.transit_data.model.NameBean in project onebusaway-application-modules by camsys.
the class StopSelectionTreeBean method toStringRecursive.
private String toStringRecursive(String prefix) {
if (hasStop())
return prefix + getStop().getName();
StringBuilder b = new StringBuilder();
for (NameBean name : getNames()) {
if (b.length() > 0)
b.append('\n');
b.append(prefix).append(name.getName()).append('\n');
b.append(getSubTree(name).toStringRecursive(prefix + " "));
}
return b.toString();
}
use of org.onebusaway.transit_data.model.NameBean in project onebusaway-application-modules by camsys.
the class DefaultLocationNameSplitStrategyImpl method splitLocationNameIntoParts.
public List<NameBean> splitLocationNameIntoParts(String name) {
if (name.contains("P&R"))
name = name.replaceAll("P&R", "ParkAndRide");
String[] tokens = name.split("\\s+&\\s+");
List<NameBean> names = new ArrayList<NameBean>();
if (tokens.length == 2) {
names.add(new NameBean(SelectionNameTypes.MAIN_STREET, tokens[0]));
names.add(new NameBean(SelectionNameTypes.CROSS_STREET, tokens[1]));
} else {
names.add(new NameBean(SelectionNameTypes.STOP_DESCRIPTION, name));
}
return names;
}
use of org.onebusaway.transit_data.model.NameBean 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.transit_data.model.NameBean 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