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

org.onebusaway.gtfs_transformer.updates.UpdateStopNameFromParentStationIfInvalidStrategy Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2020 Kyyti Group Oy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onebusaway.gtfs_transformer.updates;

import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.gtfs.model.Stop;
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy;
import org.onebusaway.gtfs_transformer.services.TransformContext;

/**
 * Some providers use platform numbers for stop names inside stations. As this is not wanted,
 * replace the stop name with the parent station name instead, leaving the platform number as is.
 */
public class UpdateStopNameFromParentStationIfInvalidStrategy implements GtfsTransformStrategy {

  @Override
  public String getName() {
    return this.getClass().getSimpleName();
  }

  @Override
  public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    for (Stop stop : dao.getAllStops()) {
      if (stop.getName().equals(stop.getPlatformCode()) && stop.getParentStation() != null) {
        String agency = stop.getId().getAgencyId();
        AgencyAndId parentId = new AgencyAndId(agency, stop.getParentStation());
        Stop parentStation = dao.getStopForId(parentId);
        if (parentStation != null) {
          stop.setName(parentStation.getName());
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy