Search in sources :

Example 1 with AlphanumComparator

use of org.onebusaway.util.comparators.AlphanumComparator in project onebusaway-application-modules by camsys.

the class RouteConfigAction method getModel.

@Override
public Body<Route> getModel() {
    Body<Route> body = new Body<Route>();
    if (isValid(body)) {
        List<String> agencyIds = processAgencyIds(agencyId);
        List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
        List<RouteBean> routeBeans = new ArrayList<RouteBean>();
        int routes_count = 1;
        if (processRouteIds(routeId, routeIds, agencyIds, body)) {
            for (AgencyAndId routeId : routeIds) {
                routeBeans.add(_transitDataService.getRouteForId(routeId.toString()));
            }
        } else if (routeId == null) {
            routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
        }
        Collections.sort(routeBeans, new Comparator<RouteBean>() {

            AlphanumComparator alphaComparator = new AlphanumComparator();

            public int compare(RouteBean arg0, RouteBean arg1) {
                return alphaComparator.compare(arg0.getId(), arg1.getId());
            }
        });
        for (RouteBean routeBean : routeBeans) {
            // Limit Number of Routes Returned
            if (routes_count > MAX_ROUTES)
                break;
            Route route = new Route();
            route.setTag(getIdNoAgency(routeBean.getId()));
            route.setTitle(route.getTag() + " " + routeBean.getLongName());
            route.setShortTitle(routeBean.getShortName());
            route.setColor(routeBean.getColor());
            route.setOppositeColor(routeBean.getTextColor());
            StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
            // Stops
            for (StopBean stopBean : stopsForRoute.getStops()) {
                Stop stop = new Stop();
                stop.setTag(getIdNoAgency(stopBean.getId()));
                stop.setTitle(stopBean.getName());
                stop.setLat(stopBean.getLat());
                stop.setLon(stopBean.getLon());
                stop.setStopId(stopBean.getCode());
                route.getStops().add(stop);
            }
            // Directions
            for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
                for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                    Direction direction = new Direction();
                    direction.setTag(stopGroupBean.getId());
                    direction.setTitle(stopGroupBean.getName().getName());
                    for (String stopId : stopGroupBean.getStopIds()) {
                        direction.getStops().add(new DisplayStop(getIdNoAgency(stopId)));
                    }
                    route.getDirections().add(direction);
                }
            }
            // PolyLines
            for (EncodedPolylineBean polyline : stopsForRoute.getPolylines()) {
                Path path = new Path();
                List<CoordinatePoint> coordinatePoints = PolylineEncoder.decode(polyline);
                for (CoordinatePoint coordinatePoint : coordinatePoints) {
                    path.getPoints().add(new Point(coordinatePoint.getLat(), coordinatePoint.getLon()));
                }
                route.getPaths().add(path);
            }
            body.getResponse().add(route);
            routes_count++;
        }
    }
    return body;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) Stop(org.onebusaway.nextbus.model.nextbus.Stop) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Direction(org.onebusaway.nextbus.model.nextbus.Direction) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Body(org.onebusaway.nextbus.model.nextbus.Body) Route(org.onebusaway.nextbus.model.nextbus.Route) DisplayRoute(org.onebusaway.nextbus.model.nextbus.DisplayRoute) Path(org.onebusaway.nextbus.model.nextbus.Path) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) AlphanumComparator(org.onebusaway.util.comparators.AlphanumComparator) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 2 with AlphanumComparator

use of org.onebusaway.util.comparators.AlphanumComparator in project onebusaway-application-modules by camsys.

the class RouteListAction method getModel.

@Override
public Body<DisplayRoute> getModel() {
    Body<DisplayRoute> body = new Body<DisplayRoute>();
    if (isValid(body)) {
        List<RouteBean> routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
        Collections.sort(routeBeans, new Comparator<RouteBean>() {

            AlphanumComparator alphaComparator = new AlphanumComparator();

            public int compare(RouteBean arg0, RouteBean arg1) {
                return alphaComparator.compare(arg0.getId(), arg1.getId());
            }
        });
        for (RouteBean routeBean : routeBeans) {
            DisplayRoute route = new DisplayRoute();
            route.setTag(getIdNoAgency(routeBean.getId()));
            route.setTitle(routeBean.getShortName() + " " + routeBean.getLongName());
            body.getResponse().add(route);
        }
    }
    return body;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AlphanumComparator(org.onebusaway.util.comparators.AlphanumComparator) Body(org.onebusaway.nextbus.model.nextbus.Body) DisplayRoute(org.onebusaway.nextbus.model.nextbus.DisplayRoute)

Aggregations

Body (org.onebusaway.nextbus.model.nextbus.Body)2 DisplayRoute (org.onebusaway.nextbus.model.nextbus.DisplayRoute)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 AlphanumComparator (org.onebusaway.util.comparators.AlphanumComparator)2 ArrayList (java.util.ArrayList)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Direction (org.onebusaway.nextbus.model.nextbus.Direction)1 DisplayStop (org.onebusaway.nextbus.model.nextbus.DisplayStop)1 Path (org.onebusaway.nextbus.model.nextbus.Path)1 Point (org.onebusaway.nextbus.model.nextbus.Point)1 Route (org.onebusaway.nextbus.model.nextbus.Route)1 Stop (org.onebusaway.nextbus.model.nextbus.Stop)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1