org.opentripplanner.api.mapping.AlertMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.api.mapping;
import org.opentripplanner.api.model.ApiAlert;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class AlertMapper {
private final Locale locale;
public AlertMapper(Locale locale) {
this.locale = locale;
}
public List mapToApi(Collection alerts) {
// Using {@code null} and not an empty set will minimize the JSON removing the
// {@code alerts} from the result.
if (alerts == null || alerts.isEmpty()) {
return null;
}
return alerts.stream().map(this::mapToApi).collect(Collectors.toList());
}
ApiAlert mapToApi(TransitAlert domain) {
ApiAlert api = new ApiAlert();
if (domain.alertHeaderText != null) {
api.alertHeaderText = domain.alertHeaderText.toString(locale);
}
if (domain.alertDescriptionText != null) {
api.alertDescriptionText = domain.alertDescriptionText.toString(locale);
}
if (domain.alertUrl != null) {
api.alertUrl = domain.alertUrl.toString(locale);
}
api.effectiveStartDate = domain.getEffectiveStartDate();
api.effectiveEndDate = domain.getEffectiveEndDate();
return api;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy