org.opentripplanner.gtfs.mapping.FrequencyMapper Maven / Gradle / Ivy
package org.opentripplanner.gtfs.mapping;
import org.opentripplanner.model.Frequency;
import org.opentripplanner.util.MapUtils;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/** Responsible for mapping GTFS Frequency into the OTP model. */
class FrequencyMapper {
private final TripMapper tripMapper;
private Map mappedFrequencys = new HashMap<>();
FrequencyMapper(TripMapper tripMapper) {
this.tripMapper = tripMapper;
}
Collection map(Collection allFrequencys) {
return MapUtils.mapToList(allFrequencys, this::map);
}
/** Map from GTFS to OTP model, {@code null} safe. */
Frequency map(org.onebusaway.gtfs.model.Frequency orginal) {
return orginal == null ? null : mappedFrequencys.computeIfAbsent(orginal, this::doMap);
}
private Frequency doMap(org.onebusaway.gtfs.model.Frequency rhs) {
Frequency lhs = new Frequency();
lhs.setTrip(tripMapper.map(rhs.getTrip()));
lhs.setStartTime(rhs.getStartTime());
lhs.setEndTime(rhs.getEndTime());
lhs.setHeadwaySecs(rhs.getHeadwaySecs());
lhs.setExactTimes(rhs.getExactTimes());
lhs.setLabelOnly(rhs.getLabelOnly());
return lhs;
}
}