org.opentripplanner.api.mapping.FeedScopedIdMapper 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.model.FeedScopedId;
import org.opentripplanner.model.TransitEntity;
import javax.ws.rs.BadRequestException;
public class FeedScopedIdMapper {
private static final String SEPARATOR = ":";
/** @throws BadRequestException if id is not parsable. */
public static FeedScopedId mapToDomain(String name, String api) {
try {
if (api == null) { return null; }
String[] parts = api.split(SEPARATOR, 2);
return new FeedScopedId(parts[0], parts[1]);
}
catch (IndexOutOfBoundsException e) {
throw new BadRequestException(
"'" + name + "' is not a valid id on the form: FEED_ID" + SEPARATOR
+ "ENTITY_ID"
);
}
}
public static String mapToApi(FeedScopedId arg) {
if (arg == null) {
return null;
}
return arg.getFeedId() + SEPARATOR + arg.getId();
}
public static String mapIdToApi(TransitEntity entity) {
return entity == null ? null : mapToApi(entity.getId());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy