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 java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
import org.opentripplanner.api.model.ApiAlert;
import org.opentripplanner.routing.alertpatch.TransitAlert;
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 = ofNullableInstant(domain.getEffectiveStartDate());
api.effectiveEndDate = ofNullableInstant(domain.getEffectiveEndDate());
return api;
}
private static Date ofNullableInstant(Instant instant) {
return Optional.ofNullable(instant).map(Date::from).orElse(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy