Search in sources :

Example 11 with NameBean

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, "");
}
Also used : IOException(java.io.IOException) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 12 with NameBean

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

Example 13 with NameBean

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;
}
Also used : ArrayList(java.util.ArrayList) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 14 with NameBean

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

Example 15 with NameBean

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

NameBean (org.onebusaway.transit_data.model.NameBean)25 ArrayList (java.util.ArrayList)16 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)16 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)14 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)14 StopBean (org.onebusaway.transit_data.model.StopBean)10 RouteBean (org.onebusaway.transit_data.model.RouteBean)7 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)4 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 StopSelectionBean (org.onebusaway.presentation.model.StopSelectionBean)3 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2