All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.routing.impl.DelegatingTransitAlertServiceImpl Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.routing.impl;

import org.opentripplanner.ext.siri.updater.SiriSXUpdater;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.calendar.ServiceDate;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.services.TransitAlertService;
import org.opentripplanner.updater.alerts.GtfsRealtimeAlertsUpdater;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Collectors;

public class DelegatingTransitAlertServiceImpl implements TransitAlertService {

  private ArrayList transitAlertServices = new ArrayList<>();

  public DelegatingTransitAlertServiceImpl(Graph graph) {
    if (graph.updaterManager != null) {
      graph.updaterManager.getUpdaterList().stream()
          .filter(SiriSXUpdater.class::isInstance)
          .map(SiriSXUpdater.class::cast)
          .map(SiriSXUpdater::getTransitAlertService)
          .forEach(transitAlertServices::add);

      graph.updaterManager.getUpdaterList().stream()
          .filter(GtfsRealtimeAlertsUpdater.class::isInstance)
          .map(GtfsRealtimeAlertsUpdater.class::cast)
          .map(GtfsRealtimeAlertsUpdater::getTransitAlertService)
          .forEach(transitAlertServices::add);
    }
  }

  @Override
  public void setAlerts(
      Collection alerts
  ) {
    throw new UnsupportedOperationException("Not supported");
  }

  @Override
  public Collection getAllAlerts() {
    return transitAlertServices
        .stream()
        .map(TransitAlertService::getAllAlerts)
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public TransitAlert getAlertById(String id) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getAlertById(id))
        .filter(Objects::nonNull)
        .findAny()
        .orElse(null);
  }

  @Override
  public Collection getStopAlerts(FeedScopedId stop) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getStopAlerts(stop))
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public Collection getRouteAlerts(FeedScopedId route) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getRouteAlerts(route))
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public Collection getTripAlerts(FeedScopedId trip, ServiceDate serviceDate) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getTripAlerts(trip, serviceDate))
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public Collection getAgencyAlerts(FeedScopedId agency) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getAgencyAlerts(agency))
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public Collection getStopAndRouteAlerts(
      FeedScopedId stop, FeedScopedId route
  ) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getStopAndRouteAlerts(stop, route))
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public Collection getStopAndTripAlerts(
      FeedScopedId stop, FeedScopedId trip, ServiceDate serviceDate
  ) {
    return transitAlertServices
        .stream()
        .map(transitAlertService -> transitAlertService.getStopAndTripAlerts(stop, trip, serviceDate))
        .flatMap(Collection::stream)
        .collect(Collectors.toList());
  }

  @Override
  public Collection getRouteTypeAndAgencyAlerts(
      int routeType, FeedScopedId agency
  ) {
    return transitAlertServices
            .stream()
            .map(transitAlertService -> transitAlertService.getRouteTypeAndAgencyAlerts(
                    routeType, agency))
            .flatMap(Collection::stream)
            .collect(Collectors.toList());
  }

  @Override
  public Collection getRouteTypeAlerts(int routeType, String feedId) {
    return transitAlertServices
            .stream()
            .map(transitAlertService -> transitAlertService.getRouteTypeAlerts(routeType, feedId))
            .flatMap(Collection::stream)
            .collect(Collectors.toList());
  }

  @Override
  public Collection getDirectionAndRouteAlerts(int directionId, FeedScopedId route) {
    return transitAlertServices
            .stream()
            .map(transitAlertService -> transitAlertService.getDirectionAndRouteAlerts(directionId, route))
            .flatMap(Collection::stream)
            .collect(Collectors.toList());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy