mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 04:08:46 +00:00
Switch to modern code format. Organize imports. No functional changes.
Java sources use Eclipse 4.5 'Java Conventions' with indentation changed to 4 spaces only per level.
This commit is contained in:
parent
db59817a05
commit
931dafb628
191 changed files with 24827 additions and 27703 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -38,8 +38,7 @@ import de.schildbach.pte.util.HttpClient;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public abstract class AbstractNetworkProvider implements NetworkProvider
|
||||
{
|
||||
public abstract class AbstractNetworkProvider implements NetworkProvider {
|
||||
protected final NetworkId network;
|
||||
protected final HttpClient httpClient = new HttpClient();
|
||||
|
||||
|
@ -47,20 +46,18 @@ public abstract class AbstractNetworkProvider implements NetworkProvider
|
|||
protected int numTripsRequested = 6;
|
||||
private @Nullable Map<String, Style> styles = null;
|
||||
|
||||
protected static final Set<Product> ALL_EXCEPT_HIGHSPEED = EnumSet.complementOf(EnumSet.of(Product.HIGH_SPEED_TRAIN));
|
||||
protected static final Set<Product> ALL_EXCEPT_HIGHSPEED = EnumSet
|
||||
.complementOf(EnumSet.of(Product.HIGH_SPEED_TRAIN));
|
||||
|
||||
protected AbstractNetworkProvider(final NetworkId network)
|
||||
{
|
||||
protected AbstractNetworkProvider(final NetworkId network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public final NetworkId id()
|
||||
{
|
||||
public final NetworkId id() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public final boolean hasCapabilities(final Capability... capabilities)
|
||||
{
|
||||
public final boolean hasCapabilities(final Capability... capabilities) {
|
||||
for (final Capability capability : capabilities)
|
||||
if (!hasCapability(capability))
|
||||
return false;
|
||||
|
@ -70,45 +67,37 @@ public abstract class AbstractNetworkProvider implements NetworkProvider
|
|||
|
||||
protected abstract boolean hasCapability(Capability capability);
|
||||
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return ALL_EXCEPT_HIGHSPEED;
|
||||
}
|
||||
|
||||
public void setUserAgent(final String userAgent)
|
||||
{
|
||||
public void setUserAgent(final String userAgent) {
|
||||
httpClient.setUserAgent(userAgent);
|
||||
}
|
||||
|
||||
protected void setTimeZone(final String timeZoneId)
|
||||
{
|
||||
protected void setTimeZone(final String timeZoneId) {
|
||||
this.timeZone = TimeZone.getTimeZone(timeZoneId);
|
||||
}
|
||||
|
||||
protected void setNumTripsRequested(final int numTripsRequested)
|
||||
{
|
||||
protected void setNumTripsRequested(final int numTripsRequested) {
|
||||
this.numTripsRequested = numTripsRequested;
|
||||
}
|
||||
|
||||
protected void setStyles(final Map<String, Style> styles)
|
||||
{
|
||||
protected void setStyles(final Map<String, Style> styles) {
|
||||
this.styles = styles;
|
||||
}
|
||||
|
||||
protected void setSessionCookieName(final String sessionCookieName)
|
||||
{
|
||||
protected void setSessionCookieName(final String sessionCookieName) {
|
||||
httpClient.setSessionCookieName(sessionCookieName);
|
||||
}
|
||||
|
||||
private static final char STYLES_SEP = '|';
|
||||
|
||||
public Style lineStyle(final @Nullable String network, final @Nullable Product product, final @Nullable String label)
|
||||
{
|
||||
public Style lineStyle(final @Nullable String network, final @Nullable Product product,
|
||||
final @Nullable String label) {
|
||||
final Map<String, Style> styles = this.styles;
|
||||
if (styles != null && product != null)
|
||||
{
|
||||
if (network != null)
|
||||
{
|
||||
if (styles != null && product != null) {
|
||||
if (network != null) {
|
||||
// check for line match
|
||||
final Style lineStyle = styles.get(network + STYLES_SEP + product.code + Strings.nullToEmpty(label));
|
||||
if (lineStyle != null)
|
||||
|
@ -120,8 +109,7 @@ public abstract class AbstractNetworkProvider implements NetworkProvider
|
|||
return productStyle;
|
||||
|
||||
// check for night bus, as that's a common special case
|
||||
if (product == Product.BUS && label != null && label.startsWith("N"))
|
||||
{
|
||||
if (product == Product.BUS && label != null && label.startsWith("N")) {
|
||||
final Style nightStyle = styles.get(network + STYLES_SEP + "BN");
|
||||
if (nightStyle != null)
|
||||
return nightStyle;
|
||||
|
@ -140,8 +128,7 @@ public abstract class AbstractNetworkProvider implements NetworkProvider
|
|||
return productStyle;
|
||||
|
||||
// check for night bus, as that's a common special case
|
||||
if (product == Product.BUS && label != null && label.startsWith("N"))
|
||||
{
|
||||
if (product == Product.BUS && label != null && label.startsWith("N")) {
|
||||
final Style nightStyle = styles.get("BN");
|
||||
if (nightStyle != null)
|
||||
return nightStyle;
|
||||
|
@ -152,13 +139,11 @@ public abstract class AbstractNetworkProvider implements NetworkProvider
|
|||
return Standard.STYLES.get(product);
|
||||
}
|
||||
|
||||
public Point[] getArea() throws IOException
|
||||
{
|
||||
public Point[] getArea() throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String normalizeStationId(final String stationId)
|
||||
{
|
||||
protected static String normalizeStationId(final String stationId) {
|
||||
if (stationId == null || stationId.length() == 0)
|
||||
return null;
|
||||
|
||||
|
@ -178,14 +163,12 @@ public abstract class AbstractNetworkProvider implements NetworkProvider
|
|||
private static final Pattern P_NAME_NOSW = Pattern.compile("(\\d{1,5})\\s*" + //
|
||||
"(Nord|Süd|Ost|West)", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
protected Position parsePosition(final String position)
|
||||
{
|
||||
protected Position parsePosition(final String position) {
|
||||
if (position == null)
|
||||
return null;
|
||||
|
||||
final Matcher mSection = P_NAME_SECTION.matcher(position);
|
||||
if (mSection.matches())
|
||||
{
|
||||
if (mSection.matches()) {
|
||||
final String name = Integer.toString(Integer.parseInt(mSection.group(1)));
|
||||
if (mSection.group(2) != null)
|
||||
return new Position(name, mSection.group(2).replaceAll("\\s+", ""));
|
||||
|
|
|
@ -62,10 +62,8 @@ import de.schildbach.pte.util.ParserUtils;
|
|||
/**
|
||||
* @author Kjell Braden <afflux@pentabarf.de>
|
||||
*/
|
||||
public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
||||
{
|
||||
private static class Context implements QueryTripsContext
|
||||
{
|
||||
public abstract class AbstractTsiProvider extends AbstractNetworkProvider {
|
||||
private static class Context implements QueryTripsContext {
|
||||
private static final long serialVersionUID = -6847355540229473013L;
|
||||
|
||||
public final Location from;
|
||||
|
@ -77,9 +75,8 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
public Date earliestArrival;
|
||||
public Date latestDeparture;
|
||||
|
||||
public Context(final Location from, final Location via, final Location to, final Collection<Product> products, final WalkSpeed walkSpeed,
|
||||
final Accessibility accessibility, final Set<Option> options)
|
||||
{
|
||||
public Context(final Location from, final Location via, final Location to, final Collection<Product> products,
|
||||
final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options) {
|
||||
this.from = from;
|
||||
this.via = via;
|
||||
this.to = to;
|
||||
|
@ -87,18 +84,15 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
this.walkSpeed = walkSpeed;
|
||||
}
|
||||
|
||||
public boolean canQueryEarlier()
|
||||
{
|
||||
public boolean canQueryEarlier() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canQueryLater()
|
||||
{
|
||||
public boolean canQueryLater() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private QueryTripsResult queryMore(final AbstractTsiProvider provider, final boolean later) throws IOException
|
||||
{
|
||||
private QueryTripsResult queryMore(final AbstractTsiProvider provider, final boolean later) throws IOException {
|
||||
final Date date = later ? latestDeparture : earliestArrival;
|
||||
|
||||
// add/remove a little bit just to be on the safe side
|
||||
|
@ -109,16 +103,14 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return provider.queryTripsFromContext(this, c.getTime(), later);
|
||||
}
|
||||
|
||||
private void updateEarliestArrival(final Date newTime)
|
||||
{
|
||||
private void updateEarliestArrival(final Date newTime) {
|
||||
if (newTime == null)
|
||||
return;
|
||||
if (earliestArrival == null || newTime.before(earliestArrival))
|
||||
earliestArrival = newTime;
|
||||
}
|
||||
|
||||
private void updateLatestDeparture(final Date newTime)
|
||||
{
|
||||
private void updateLatestDeparture(final Date newTime) {
|
||||
if (newTime == null)
|
||||
return;
|
||||
if (latestDeparture == null || newTime.after(latestDeparture))
|
||||
|
@ -131,8 +123,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
private static final String SERVER_PRODUCT = "tsi";
|
||||
|
||||
private static Map<String, Product> TRANSPORT_MODES = new HashMap<String, Product>();
|
||||
static
|
||||
{
|
||||
static {
|
||||
// HIGH_SPEED_TRAIN
|
||||
TRANSPORT_MODES.put("TGV", Product.HIGH_SPEED_TRAIN);
|
||||
TRANSPORT_MODES.put("HST", Product.HIGH_SPEED_TRAIN);
|
||||
|
@ -160,8 +151,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
TRANSPORT_MODES.put("TROLLEY_BUS", Product.CABLECAR);
|
||||
}
|
||||
|
||||
protected static double latLonToDouble(final int value)
|
||||
{
|
||||
protected static double latLonToDouble(final int value) {
|
||||
return (double) value / 1000000;
|
||||
}
|
||||
|
||||
|
@ -169,13 +159,12 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
private final String stopFinderEndpoint;
|
||||
private final String tripEndpoint;
|
||||
|
||||
public AbstractTsiProvider(final NetworkId network, final String apiKey, final String apiBase)
|
||||
{
|
||||
public AbstractTsiProvider(final NetworkId network, final String apiKey, final String apiBase) {
|
||||
this(network, apiKey, apiBase, null, null);
|
||||
}
|
||||
|
||||
public AbstractTsiProvider(final NetworkId network, final String apiKey, final String tripEndpoint, final String stopFinderEndpoint)
|
||||
{
|
||||
public AbstractTsiProvider(final NetworkId network, final String apiKey, final String tripEndpoint,
|
||||
final String stopFinderEndpoint) {
|
||||
super(network);
|
||||
|
||||
this.apiKey = apiKey;
|
||||
|
@ -183,24 +172,21 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
this.stopFinderEndpoint = stopFinderEndpoint;
|
||||
}
|
||||
|
||||
public AbstractTsiProvider(final NetworkId network, final String apiKey, final String apiBase, final String tripEndpoint,
|
||||
final String stopFinderEndpoint)
|
||||
{
|
||||
public AbstractTsiProvider(final NetworkId network, final String apiKey, final String apiBase,
|
||||
final String tripEndpoint, final String stopFinderEndpoint) {
|
||||
this(network, apiKey, apiBase + (tripEndpoint != null ? tripEndpoint : DEFAULT_TRIP_ENDPOINT), //
|
||||
apiBase + (stopFinderEndpoint != null ? stopFinderEndpoint : DEFAULT_STOPFINDER_ENDPOINT));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCapability(final Capability capability)
|
||||
{
|
||||
protected boolean hasCapability(final Capability capability) {
|
||||
if (capability == Capability.DEPARTURES)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
final StringBuilder parameters = buildCommonRequestParams("SearchTripPoint", "json");
|
||||
parameters.append("&MaxItems=").append(50); // XXX good value?
|
||||
parameters.append("&Keywords=").append(ParserUtils.urlEncode(constraint.toString(), Charsets.UTF_8));
|
||||
|
@ -209,8 +195,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
uri.append(parameters);
|
||||
|
||||
final CharSequence page = httpClient.get(uri.toString(), Charsets.UTF_8);
|
||||
try
|
||||
{
|
||||
try {
|
||||
final List<SuggestedLocation> locations = new ArrayList<SuggestedLocation>();
|
||||
final JSONObject head = new JSONObject(page.toString());
|
||||
|
||||
|
@ -222,8 +207,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return new SuggestLocationsResult(header, SuggestLocationsResult.Status.SERVICE_DOWN);
|
||||
|
||||
JSONArray dataArray = head.getJSONArray("Data");
|
||||
for (int i = 0; i < dataArray.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
JSONObject data = dataArray.getJSONObject(i);
|
||||
final Location location = parseJsonTransportLocation(data);
|
||||
|
||||
|
@ -233,24 +217,20 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
}
|
||||
|
||||
return new SuggestLocationsResult(header, locations);
|
||||
}
|
||||
catch (final JSONException x)
|
||||
{
|
||||
} catch (final JSONException x) {
|
||||
throw new ParserException(x);
|
||||
}
|
||||
}
|
||||
|
||||
private final StringBuilder buildCommonRequestParams(final String method, final String outputFormat)
|
||||
{
|
||||
private final StringBuilder buildCommonRequestParams(final String method, final String outputFormat) {
|
||||
final StringBuilder uri = new StringBuilder(method);
|
||||
uri.append('/').append(outputFormat);
|
||||
uri.append("?Key=").append(apiKey);
|
||||
return uri;
|
||||
}
|
||||
|
||||
private Line createLine(final String id, final String mode, final String number, final String name, final String operatorCode,
|
||||
final String codeActivity)
|
||||
{
|
||||
private Line createLine(final String id, final String mode, final String number, final String name,
|
||||
final String operatorCode, final String codeActivity) {
|
||||
final Product product = TRANSPORT_MODES.get(mode);
|
||||
|
||||
if (product == null)
|
||||
|
@ -258,26 +238,20 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
|
||||
final StringBuilder label = new StringBuilder();
|
||||
|
||||
if (number != null)
|
||||
{
|
||||
if (number != null) {
|
||||
label.append(number);
|
||||
}
|
||||
else if (operatorCode != null)
|
||||
{
|
||||
} else if (operatorCode != null) {
|
||||
label.append(operatorCode);
|
||||
if (codeActivity != null)
|
||||
label.append(codeActivity);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
label.append(name);
|
||||
}
|
||||
|
||||
return new Line(id, operatorCode, product, label.toString());
|
||||
}
|
||||
|
||||
private List<Location> identifyLocation(final Location location) throws IOException
|
||||
{
|
||||
private List<Location> identifyLocation(final Location location) throws IOException {
|
||||
if (location.isIdentified())
|
||||
return Collections.singletonList(location);
|
||||
|
||||
|
@ -288,10 +262,11 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return locations;
|
||||
}
|
||||
|
||||
private NearbyLocationsResult jsonCoordRequest(final int lat, final int lon, final int maxDistance, final int maxStations) throws IOException
|
||||
{
|
||||
private NearbyLocationsResult jsonCoordRequest(final int lat, final int lon, final int maxDistance,
|
||||
final int maxStations) throws IOException {
|
||||
final StringBuilder parameters = buildCommonRequestParams("SearchTripPoint", "json");
|
||||
parameters.append(String.format(Locale.FRENCH, "&Latitude=%2.6f&Longitude=%2.6f", latLonToDouble(lat), latLonToDouble(lon)));
|
||||
parameters.append(String.format(Locale.FRENCH, "&Latitude=%2.6f&Longitude=%2.6f", latLonToDouble(lat),
|
||||
latLonToDouble(lon)));
|
||||
parameters.append("&MaxItems=").append(maxStations != 0 ? maxStations : 50);
|
||||
parameters.append("&Perimeter=").append(maxDistance != 0 ? maxDistance : 1320);
|
||||
parameters.append("&PointTypes=Stop_Place");
|
||||
|
@ -300,8 +275,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
uri.append(parameters);
|
||||
|
||||
final CharSequence page = httpClient.get(uri.toString(), Charsets.UTF_8);
|
||||
try
|
||||
{
|
||||
try {
|
||||
final List<Location> stations = new ArrayList<Location>();
|
||||
final JSONObject head = new JSONObject(page.toString());
|
||||
|
||||
|
@ -309,34 +283,28 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
|
||||
final int status = head.getInt("StatusCode");
|
||||
|
||||
if (status != 200)
|
||||
{
|
||||
if (status != 200) {
|
||||
return new NearbyLocationsResult(header, status == 300 ? NearbyLocationsResult.Status.INVALID_ID
|
||||
: NearbyLocationsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
|
||||
JSONArray dataArray = head.getJSONArray("Data");
|
||||
for (int i = 0; i < dataArray.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
JSONObject data = dataArray.getJSONObject(i);
|
||||
stations.add(parseJsonTransportLocation(data));
|
||||
}
|
||||
|
||||
return new NearbyLocationsResult(header, stations);
|
||||
}
|
||||
catch (final JSONException x)
|
||||
{
|
||||
} catch (final JSONException x) {
|
||||
throw new ParserException(x);
|
||||
}
|
||||
}
|
||||
|
||||
private String jsonOptString(final JSONObject json, final String key) throws JSONException
|
||||
{
|
||||
private String jsonOptString(final JSONObject json, final String key) throws JSONException {
|
||||
return json.isNull(key) ? null : json.getString(key);
|
||||
}
|
||||
|
||||
private Location jsonStationRequestCoord(final String id) throws IOException
|
||||
{
|
||||
private Location jsonStationRequestCoord(final String id) throws IOException {
|
||||
final StringBuilder parameters = buildCommonRequestParams("GetTripPoint", "json");
|
||||
parameters.append("&TripPointId=").append(id);
|
||||
parameters.append("&PointType=Stop_Place");
|
||||
|
@ -345,8 +313,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
uri.append(parameters);
|
||||
|
||||
final CharSequence page = httpClient.get(uri.toString(), Charsets.UTF_8);
|
||||
try
|
||||
{
|
||||
try {
|
||||
final JSONObject head = new JSONObject(page.toString());
|
||||
|
||||
int status = head.getInt("StatusCode");
|
||||
|
@ -356,23 +323,17 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
|
||||
JSONObject data = head.getJSONObject("Data");
|
||||
return parseJsonTransportLocation(data);
|
||||
}
|
||||
catch (final JSONException x)
|
||||
{
|
||||
} catch (final JSONException x) {
|
||||
throw new ParserException(x);
|
||||
}
|
||||
}
|
||||
|
||||
private Trip.Individual parseJsonJourneyplannerIndividualLeg(final JSONObject legInfo) throws JSONException
|
||||
{
|
||||
private Trip.Individual parseJsonJourneyplannerIndividualLeg(final JSONObject legInfo) throws JSONException {
|
||||
final String transportMode = legInfo.getString("TransportMode");
|
||||
final Trip.Individual.Type type;
|
||||
if ("WALK".equals(transportMode))
|
||||
{
|
||||
if ("WALK".equals(transportMode)) {
|
||||
type = Trip.Individual.Type.WALK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new JSONException("unknown transportMode=" + transportMode);
|
||||
}
|
||||
|
||||
|
@ -385,14 +346,11 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
final String arrTimeStr = arrInfo.getString("Time");
|
||||
final String depTimeStr = depInfo.getString("Time");
|
||||
final Date depTime, arrTime;
|
||||
try
|
||||
{
|
||||
try {
|
||||
final DateFormat fullDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.US);
|
||||
depTime = fullDateFormat.parse(depTimeStr);
|
||||
arrTime = fullDateFormat.parse(arrTimeStr);
|
||||
}
|
||||
catch (final ParseException e)
|
||||
{
|
||||
} catch (final ParseException e) {
|
||||
throw new JSONException("failed to parse trip times: " + depTimeStr + " or " + arrTimeStr);
|
||||
}
|
||||
|
||||
|
@ -401,71 +359,56 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
|
||||
int distance = 0;
|
||||
path.add(new Point(departure.lat, departure.lon));
|
||||
for (int i = 0; i < pathLinks.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < pathLinks.length(); i++) {
|
||||
final JSONObject pathLink = pathLinks.getJSONObject(i);
|
||||
distance += pathLink.getInt("Distance");
|
||||
|
||||
final Location toLoc = parseJsonJourneyplannerLocation(pathLink.getJSONObject("Arrival").getJSONObject("Site"));
|
||||
final Location toLoc = parseJsonJourneyplannerLocation(
|
||||
pathLink.getJSONObject("Arrival").getJSONObject("Site"));
|
||||
path.add(new Point(toLoc.lat, toLoc.lon));
|
||||
}
|
||||
return new Trip.Individual(type, departure, depTime, arrival, arrTime, path, distance);
|
||||
}
|
||||
|
||||
private Trip.Leg parseJsonJourneyplannerLeg(final JSONObject jsonObject) throws JSONException
|
||||
{
|
||||
private Trip.Leg parseJsonJourneyplannerLeg(final JSONObject jsonObject) throws JSONException {
|
||||
final JSONObject legInfo = jsonObject.getJSONObject("Leg");
|
||||
final JSONObject ptrInfo = jsonObject.getJSONObject("PTRide");
|
||||
|
||||
if (legInfo.isNull("TransportMode") && !ptrInfo.isNull("TransportMode"))
|
||||
{
|
||||
if (legInfo.isNull("TransportMode") && !ptrInfo.isNull("TransportMode")) {
|
||||
return parseJsonJourneyplannerPublicLeg(ptrInfo);
|
||||
}
|
||||
else if (!legInfo.isNull("TransportMode") && ptrInfo.isNull("TransportMode"))
|
||||
{
|
||||
} else if (!legInfo.isNull("TransportMode") && ptrInfo.isNull("TransportMode")) {
|
||||
return parseJsonJourneyplannerIndividualLeg(legInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new JSONException("unknown leg type");
|
||||
}
|
||||
}
|
||||
|
||||
private Location parseJsonJourneyplannerLocation(final JSONObject data) throws JSONException
|
||||
{
|
||||
private Location parseJsonJourneyplannerLocation(final JSONObject data) throws JSONException {
|
||||
final String locTypeStr = data.getString("Type");
|
||||
final LocationType locType;
|
||||
final String id;
|
||||
|
||||
if ("POI".equals(locTypeStr))
|
||||
{
|
||||
if ("POI".equals(locTypeStr)) {
|
||||
locType = LocationType.POI;
|
||||
id = data.getString("id");
|
||||
}
|
||||
else if ("BOARDING_POSITION".equals(locTypeStr))
|
||||
{
|
||||
} else if ("BOARDING_POSITION".equals(locTypeStr)) {
|
||||
locType = LocationType.STATION;
|
||||
if (!data.isNull("LogicalId"))
|
||||
id = data.getString("LogicalId");
|
||||
else
|
||||
id = data.getString("id");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
id = data.optString("id");
|
||||
locType = LocationType.ADDRESS;
|
||||
}
|
||||
|
||||
final Point coord;
|
||||
final JSONObject posObj = data.optJSONObject("Position");
|
||||
if (posObj != null)
|
||||
{
|
||||
if (posObj != null) {
|
||||
final double lat = posObj.getDouble("Lat");
|
||||
final double lon = posObj.getDouble("Long");
|
||||
coord = Point.fromDouble(lat, lon);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
coord = null;
|
||||
}
|
||||
|
||||
|
@ -474,8 +417,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return new Location(locType, id, coord, place, name);
|
||||
}
|
||||
|
||||
private Trip.Public parseJsonJourneyplannerPublicLeg(final JSONObject ptrInfo) throws JSONException
|
||||
{
|
||||
private Trip.Public parseJsonJourneyplannerPublicLeg(final JSONObject ptrInfo) throws JSONException {
|
||||
final DateFormat fullDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.US);
|
||||
final Line line = parseJsonLine(ptrInfo);
|
||||
|
||||
|
@ -491,36 +433,29 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
final JSONObject arrivalInfo = ptrInfo.getJSONObject("Arrival");
|
||||
final Location departureLocation = parseJsonJourneyplannerLocation(departureInfo.getJSONObject("StopPlace"));
|
||||
final Location arrivalLocation = parseJsonJourneyplannerLocation(arrivalInfo.getJSONObject("StopPlace"));
|
||||
try
|
||||
{
|
||||
try {
|
||||
final Date departureTime = fullDateFormat.parse(departureInfo.getString("Time"));
|
||||
final Date arrivalTime = fullDateFormat.parse(arrivalInfo.getString("Time"));
|
||||
departureStop = new Stop(departureLocation, true, departureTime, null, null, null);
|
||||
arrivalStop = new Stop(arrivalLocation, false, arrivalTime, null, null, null);
|
||||
}
|
||||
catch (final ParseException e)
|
||||
{
|
||||
} catch (final ParseException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
|
||||
final JSONArray stepArray = ptrInfo.getJSONObject("steps").getJSONArray("Step");
|
||||
List<Stop> intermediateStops = new ArrayList<Stop>(stepArray.length() - 1);
|
||||
for (int i = 0; i < stepArray.length() - 1; i++)
|
||||
{
|
||||
for (int i = 0; i < stepArray.length() - 1; i++) {
|
||||
final JSONObject enterStop = stepArray.getJSONObject(i).getJSONObject("Arrival");
|
||||
final JSONObject leaveStop = stepArray.getJSONObject(i + 1).getJSONObject("Departure");
|
||||
|
||||
final Location location = parseJsonJourneyplannerLocation(leaveStop.getJSONObject("StopPlace"));
|
||||
Date enterTime;
|
||||
Date leaveTime;
|
||||
try
|
||||
{
|
||||
try {
|
||||
enterTime = fullDateFormat.parse(enterStop.getString("Time"));
|
||||
leaveTime = fullDateFormat.parse(leaveStop.getString("Time"));
|
||||
intermediateStops.add(new Stop(location, enterTime, null, leaveTime, null));
|
||||
}
|
||||
catch (final ParseException e)
|
||||
{
|
||||
} catch (final ParseException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
}
|
||||
|
@ -530,8 +465,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return new Trip.Public(line, lineDestination, departureStop, arrivalStop, intermediateStops, null, message);
|
||||
}
|
||||
|
||||
private Trip parseJsonJourneyplannerTrip(final JSONObject tripObject) throws JSONException
|
||||
{
|
||||
private Trip parseJsonJourneyplannerTrip(final JSONObject tripObject) throws JSONException {
|
||||
final JSONObject departureInfo = tripObject.getJSONObject("Departure");
|
||||
final JSONObject arrivalInfo = tripObject.getJSONObject("Arrival");
|
||||
final Location from = parseJsonJourneyplannerLocation(departureInfo.getJSONObject("Site"));
|
||||
|
@ -540,16 +474,14 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
final JSONArray legArray = tripObject.getJSONObject("sections").getJSONArray("Section");
|
||||
final List<Trip.Leg> legs = new ArrayList<Trip.Leg>(legArray.length());
|
||||
|
||||
for (int i = 0; i < legArray.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < legArray.length(); i++) {
|
||||
legs.add(parseJsonJourneyplannerLeg(legArray.getJSONObject(i)));
|
||||
}
|
||||
|
||||
return new Trip(null, from, to, legs, null, null, null);
|
||||
}
|
||||
|
||||
private Line parseJsonLine(final JSONObject ptrInfo) throws JSONException
|
||||
{
|
||||
private Line parseJsonLine(final JSONObject ptrInfo) throws JSONException {
|
||||
final JSONObject networkInfo = ptrInfo.optJSONObject("PTNetwork");
|
||||
final String network;
|
||||
if (networkInfo != null)
|
||||
|
@ -576,17 +508,16 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
final String codeActivity = jsonOptString(ptrInfo, "CodeActivity");
|
||||
|
||||
final Line line = createLine(id, transportMode, lineNumber, lineName, operatorCode, codeActivity);
|
||||
final Line styledLine = new Line(line.id, line.network, line.product, line.label, lineStyle(network, line.product, line.label));
|
||||
final Line styledLine = new Line(line.id, line.network, line.product, line.label,
|
||||
lineStyle(network, line.product, line.label));
|
||||
return styledLine;
|
||||
}
|
||||
|
||||
private Location parseJsonTransportLocation(final JSONObject data) throws JSONException
|
||||
{
|
||||
private Location parseJsonTransportLocation(final JSONObject data) throws JSONException {
|
||||
final String id = data.getString("Id");
|
||||
final LocationType locType;
|
||||
|
||||
switch (data.getInt("PointType"))
|
||||
{
|
||||
switch (data.getInt("PointType")) {
|
||||
case 1:
|
||||
locType = LocationType.POI;
|
||||
break;
|
||||
|
@ -604,30 +535,25 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
final String name = data.getString("Name");
|
||||
String place = null;
|
||||
final JSONObject localityObj = data.optJSONObject("Locality");
|
||||
if (localityObj != null)
|
||||
{
|
||||
if (localityObj != null) {
|
||||
place = localityObj.getString("Name");
|
||||
}
|
||||
return new Location(locType, id, Point.fromDouble(lat, lon), place, name);
|
||||
}
|
||||
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
return ((Context) context).queryMore(this, later);
|
||||
}
|
||||
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
Location queryLocation = location;
|
||||
if (!queryLocation.hasLocation())
|
||||
{
|
||||
if (!queryLocation.hasLocation()) {
|
||||
if (location.type != LocationType.STATION)
|
||||
throw new IllegalArgumentException("cannot handle: " + location.type);
|
||||
queryLocation = jsonStationRequestCoord(location.id);
|
||||
|
@ -639,10 +565,10 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return jsonCoordRequest(location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
final List<Location> possibleFroms, possibleTos, possibleVias;
|
||||
|
||||
|
@ -662,31 +588,27 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_VIA);
|
||||
|
||||
if (possibleFroms.size() > 1 || possibleVias.size() > 1 || possibleTos.size() > 1)
|
||||
return new QueryTripsResult(header, possibleFroms.size() > 1 ? possibleFroms : null, possibleVias.size() > 1 ? possibleVias : null,
|
||||
possibleTos.size() > 1 ? possibleTos : null);
|
||||
return new QueryTripsResult(header, possibleFroms.size() > 1 ? possibleFroms : null,
|
||||
possibleVias.size() > 1 ? possibleVias : null, possibleTos.size() > 1 ? possibleTos : null);
|
||||
|
||||
final Context context = new Context(possibleFroms.get(0), possibleVias.get(0), possibleTos.get(0), products, walkSpeed, accessibility,
|
||||
options);
|
||||
final Context context = new Context(possibleFroms.get(0), possibleVias.get(0), possibleTos.get(0), products,
|
||||
walkSpeed, accessibility, options);
|
||||
|
||||
return queryTripsFromContext(context, date, dep);
|
||||
}
|
||||
|
||||
protected QueryTripsResult queryTripsFromContext(final Context context, final Date date, final boolean dep) throws IOException
|
||||
{
|
||||
protected QueryTripsResult queryTripsFromContext(final Context context, final Date date, final boolean dep)
|
||||
throws IOException {
|
||||
final String mode;
|
||||
if (context.products != null)
|
||||
{
|
||||
if (context.products != null) {
|
||||
final StringBuilder modeBuilder = new StringBuilder();
|
||||
for (Product p : context.products)
|
||||
{
|
||||
for (Product p : context.products) {
|
||||
final String productName = translateToLocalProduct(p);
|
||||
if (productName != null)
|
||||
modeBuilder.append(productName).append("|");
|
||||
}
|
||||
mode = modeBuilder.substring(0, modeBuilder.length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mode = null;
|
||||
}
|
||||
|
||||
|
@ -697,52 +619,36 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
parameters.append("&Algorithm=FASTEST");
|
||||
parameters.append("&MaxWalkDist=1000"); // XXX good value? (in meters)
|
||||
|
||||
if (context.from.type == LocationType.STATION)
|
||||
{
|
||||
if (context.from.type == LocationType.STATION) {
|
||||
parameters.append("&DepType=STOP_PLACE&DepId=").append(context.from.id);
|
||||
parameters.append("%240"); // "$0"
|
||||
}
|
||||
else if (context.from.type == LocationType.POI)
|
||||
{
|
||||
} else if (context.from.type == LocationType.POI) {
|
||||
parameters.append("&DepType=POI&DepId=").append(context.from.id);
|
||||
parameters.append("%240"); // "$0"
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
parameters.append("&DepLat=").append(latLonToDouble(context.from.lat));
|
||||
parameters.append("&DepLon=").append(latLonToDouble(context.from.lon));
|
||||
}
|
||||
|
||||
if (context.to.type == LocationType.STATION)
|
||||
{
|
||||
if (context.to.type == LocationType.STATION) {
|
||||
parameters.append("&ArrType=STOP_PLACE&ArrId=").append(context.to.id);
|
||||
parameters.append("%240"); // "$0"
|
||||
}
|
||||
else if (context.to.type == LocationType.POI)
|
||||
{
|
||||
} else if (context.to.type == LocationType.POI) {
|
||||
parameters.append("&ArrType=POI&ArrId=").append(context.to.id);
|
||||
parameters.append("%240"); // "$0"
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
parameters.append("&ArrLat=").append(latLonToDouble(context.to.lat));
|
||||
parameters.append("&ArrLon=").append(latLonToDouble(context.to.lon));
|
||||
}
|
||||
|
||||
if (context.via != null)
|
||||
{
|
||||
if (context.via.type == LocationType.STATION)
|
||||
{
|
||||
if (context.via != null) {
|
||||
if (context.via.type == LocationType.STATION) {
|
||||
parameters.append("&ViaType=STOP_PLACE&ViaId=").append(context.via.id);
|
||||
parameters.append("%240"); // "$0"
|
||||
}
|
||||
else if (context.via.type == LocationType.POI)
|
||||
{
|
||||
} else if (context.via.type == LocationType.POI) {
|
||||
parameters.append("&ViaType=POI&ViaId=").append(context.via.id);
|
||||
parameters.append("%240"); // "$0"
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
parameters.append("&ViaLat=").append(latLonToDouble(context.via.lat));
|
||||
parameters.append("&ViaLon=").append(latLonToDouble(context.via.lon));
|
||||
}
|
||||
|
@ -762,56 +668,47 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
final StringBuilder uri = new StringBuilder(tripEndpoint);
|
||||
uri.append(parameters);
|
||||
final CharSequence page = httpClient.get(uri.toString(), Charsets.UTF_8);
|
||||
try
|
||||
{
|
||||
try {
|
||||
final JSONObject head = new JSONObject(page.toString());
|
||||
|
||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
||||
final JSONObject statusObj = head.optJSONObject("Status");
|
||||
|
||||
if (statusObj == null)
|
||||
{
|
||||
if (statusObj == null) {
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
|
||||
final String statusStr = statusObj.optString("Code");
|
||||
|
||||
if ("NO_SOLUTION_FOR_REQUEST".equals(statusStr))
|
||||
{
|
||||
if ("NO_SOLUTION_FOR_REQUEST".equals(statusStr)) {
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS);
|
||||
}
|
||||
|
||||
if (!"OK".equals(statusStr))
|
||||
{
|
||||
if (!"OK".equals(statusStr)) {
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
|
||||
final JSONArray tripArray = head.getJSONObject("trips").getJSONArray("Trip");
|
||||
final List<Trip> trips = new ArrayList<Trip>(tripArray.length());
|
||||
|
||||
for (int i = 0; i < tripArray.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < tripArray.length(); i++) {
|
||||
final JSONObject tripObject = tripArray.getJSONObject(i);
|
||||
trips.add(parseJsonJourneyplannerTrip(tripObject));
|
||||
}
|
||||
|
||||
if (trips.size() > 0)
|
||||
{
|
||||
if (trips.size() > 0) {
|
||||
context.updateEarliestArrival(trips.get(0).getLastArrivalTime());
|
||||
context.updateLatestDeparture(trips.get(trips.size() - 1).getFirstDepartureTime());
|
||||
}
|
||||
|
||||
return new QueryTripsResult(header, uri.toString(), context.from, context.via, context.to, context, trips);
|
||||
}
|
||||
catch (final JSONException x)
|
||||
{
|
||||
} catch (final JSONException x) {
|
||||
throw new ParserException(x);
|
||||
}
|
||||
}
|
||||
|
||||
protected TimeZone timeZone()
|
||||
{
|
||||
protected TimeZone timeZone() {
|
||||
return TimeZone.getTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
|
@ -821,10 +718,8 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider
|
|||
* @param walkSpeed
|
||||
* @return walk speed in km/h
|
||||
*/
|
||||
protected String translateWalkSpeed(final WalkSpeed walkSpeed)
|
||||
{
|
||||
switch (walkSpeed)
|
||||
{
|
||||
protected String translateWalkSpeed(final WalkSpeed walkSpeed) {
|
||||
switch (walkSpeed) {
|
||||
case FAST:
|
||||
return "6";
|
||||
case SLOW:
|
||||
|
|
|
@ -20,14 +20,12 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class AtcProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class AtcProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://82.187.83.50/TravelPlanner/";
|
||||
|
||||
// http://cisium.webhop.net/TravelPlanner/
|
||||
|
||||
public AtcProvider()
|
||||
{
|
||||
public AtcProvider() {
|
||||
super(NetworkId.ATC, API_BASE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,10 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class AvvProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class AvvProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "https://efa.avv-augsburg.de/avv2/";
|
||||
|
||||
public AvvProvider()
|
||||
{
|
||||
public AvvProvider() {
|
||||
super(NetworkId.AVV, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
@ -46,12 +44,12 @@ public class AvvProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
uri.append("&inclMOT_11=on"); // night bus
|
||||
uri.append("&inclMOT_13=on");
|
||||
|
@ -64,12 +62,10 @@ public class AvvProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("Regionalbahn".equals(trainName) && symbol != null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, symbol);
|
||||
if ("Staudenbahn SVG".equals(trainNum) && trainType == null && trainName == null)
|
||||
|
@ -93,8 +89,7 @@ public class AvvProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("B", new Style(Style.Shape.CIRCLE, Style.parseColor("#abb1b1"), Style.BLACK));
|
||||
STYLES.put("BB1", new Style(Style.Shape.CIRCLE, Style.parseColor("#93117e"), Style.WHITE));
|
||||
STYLES.put("BB3", new Style(Style.Shape.CIRCLE, Style.parseColor("#ee7f00"), Style.WHITE));
|
||||
|
|
|
@ -26,15 +26,13 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class BahnProvider extends AbstractHafasProvider
|
||||
{
|
||||
public final class BahnProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "https://reiseauskunft.bahn.de/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.ON_DEMAND, null, null,
|
||||
null, null };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY,
|
||||
Product.SUBWAY, Product.TRAM, Product.ON_DEMAND, null, null, null, null };
|
||||
|
||||
public BahnProvider()
|
||||
{
|
||||
public BahnProvider() {
|
||||
super(NetworkId.DB, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardEndpoint("https://mobile.bahn.de/bin/mobil/bhftafel.exe/dn");
|
||||
|
@ -43,16 +41,14 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
private static final Pattern P_SPLIT_NAME_ONE_COMMA = Pattern.compile("([^,]*), ([^,]*)");
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_ONE_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -61,8 +57,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -71,8 +66,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -83,8 +77,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_NORMALIZE_LINE_NAME_TRAM = Pattern.compile("str\\s+(.*)", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
protected String normalizeLineName(final String lineName)
|
||||
{
|
||||
protected String normalizeLineName(final String lineName) {
|
||||
final Matcher mTram = P_NORMALIZE_LINE_NAME_TRAM.matcher(lineName);
|
||||
if (mTram.matches())
|
||||
return mTram.group(1);
|
||||
|
@ -93,8 +86,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("N".equals(ucType))
|
||||
|
|
|
@ -43,8 +43,7 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class BayernProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class BayernProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://mobile.defas-fgi.de/beg/";
|
||||
|
||||
// http://mobile.defas-fgi.de/xml/
|
||||
|
@ -53,8 +52,7 @@ public class BayernProvider extends AbstractEfaProvider
|
|||
private static final String TRIP_ENDPOINT = "XML_TRIP_REQUEST2";
|
||||
private static final String STOP_FINDER_ENDPOINT = "XML_STOPFINDER_REQUEST";
|
||||
|
||||
public BayernProvider()
|
||||
{
|
||||
public BayernProvider() {
|
||||
super(NetworkId.BAYERN, API_BASE, DEPARTURE_MONITOR_ENDPOINT, TRIP_ENDPOINT, STOP_FINDER_ENDPOINT, null);
|
||||
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
|
@ -63,33 +61,26 @@ public class BayernProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("M".equals(trainType) && trainNum != null && trainName != null && trainName.endsWith("Meridian"))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "M" + trainNum);
|
||||
if ("ZUG".equals(trainType) && trainNum != null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, trainNum);
|
||||
}
|
||||
else if ("1".equals(mot))
|
||||
{
|
||||
} else if ("1".equals(mot)) {
|
||||
if ("ABR".equals(trainType) || "ABELLIO Rail NRW GmbH".equals(trainName))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "ABR" + trainNum);
|
||||
if ("SBB".equals(trainType) || "SBB GmbH".equals(trainName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "SBB" + Strings.nullToEmpty(trainNum));
|
||||
}
|
||||
else if ("5".equals(mot))
|
||||
{
|
||||
} else if ("5".equals(mot)) {
|
||||
if (name != null && name.startsWith("Stadtbus Linie ")) // Lindau
|
||||
return super.parseLine(id, network, mot, symbol, name.substring(15), longName, trainType, trainNum, trainName);
|
||||
return super.parseLine(id, network, mot, symbol, name.substring(15), longName, trainType, trainNum,
|
||||
trainName);
|
||||
else
|
||||
return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
|
||||
}
|
||||
else if ("16".equals(mot))
|
||||
{
|
||||
} else if ("16".equals(mot)) {
|
||||
if ("EC".equals(trainType) && trainNum != null)
|
||||
return new Line(id, network, Product.HIGH_SPEED_TRAIN, "EC" + trainNum);
|
||||
if ("IC".equals(trainType) && trainNum != null)
|
||||
|
@ -119,9 +110,8 @@ public class BayernProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation())
|
||||
return mobileCoordRequest(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
|
||||
|
@ -132,32 +122,28 @@ public class BayernProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
checkNotNull(Strings.emptyToNull(stationId));
|
||||
|
||||
return queryDeparturesMobile(stationId, time, maxDepartures, equivs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return mobileStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
for (final Product p : products)
|
||||
{
|
||||
if (products != null) {
|
||||
for (final Product p : products) {
|
||||
if (p == Product.HIGH_SPEED_TRAIN)
|
||||
uri.append("&inclMOT_15=on&inclMOT_16=on");
|
||||
|
||||
|
@ -175,16 +161,15 @@ public class BayernProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return queryTripsMobile(from, via, to, date, dep, products, optimize, walkSpeed, accessibility, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException {
|
||||
return queryMoreTripsMobile(contextObj, later);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,12 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class BsvagProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class BsvagProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://bsvg.efa.de/bsvagstd/";
|
||||
|
||||
// http://212.68.73.240/vrbstd/
|
||||
|
||||
public BsvagProvider()
|
||||
{
|
||||
public BsvagProvider() {
|
||||
super(NetworkId.BSVAG, API_BASE);
|
||||
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
|
@ -51,12 +49,12 @@ public class BsvagProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
uri.append("&inclMOT_11=on");
|
||||
|
||||
|
@ -65,8 +63,7 @@ public class BsvagProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Braunschweig
|
||||
STYLES.put("TM1", new Style(Style.parseColor("#62c2a2"), Style.WHITE));
|
||||
STYLES.put("TM2", new Style(Style.parseColor("#b35e89"), Style.WHITE));
|
||||
|
|
|
@ -26,18 +26,15 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class BvbProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class BvbProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://www.efa-bvb.ch/bvb/";
|
||||
|
||||
public BvbProvider()
|
||||
{
|
||||
public BvbProvider() {
|
||||
super(NetworkId.BVB, API_BASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return xmlStopfinderRequest(new Location(LocationType.STATION, null, null, constraint.toString()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,12 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class BvgProvider extends AbstractHafasProvider
|
||||
{
|
||||
public final class BvgProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://bvg-apps.hafas.de/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.FERRY,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.ON_DEMAND };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.FERRY, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.ON_DEMAND };
|
||||
|
||||
public BvgProvider()
|
||||
{
|
||||
public BvgProvider() {
|
||||
super(NetworkId.BVG, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsUseWeight(false);
|
||||
|
@ -54,8 +52,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_SPLIT_NAME_BUS = Pattern.compile("(.*?)(\\s+\\[[^\\]]+\\])?");
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(String name)
|
||||
{
|
||||
protected String[] splitStationName(String name) {
|
||||
final Matcher mSu = P_SPLIT_NAME_SU.matcher(name);
|
||||
if (!mSu.matches())
|
||||
throw new IllegalStateException(name);
|
||||
|
@ -78,8 +75,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
return super.splitStationName(name);
|
||||
}
|
||||
|
||||
private String normalizePlace(final String place)
|
||||
{
|
||||
private String normalizePlace(final String place) {
|
||||
if ("Bln".equals(place))
|
||||
return "Berlin";
|
||||
else
|
||||
|
@ -87,8 +83,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -97,8 +92,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -106,11 +100,11 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
return super.splitStationName(address);
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE_NAME_TRAM = Pattern.compile("(?:tra|tram)\\s+(.*)", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern P_NORMALIZE_LINE_NAME_TRAM = Pattern.compile("(?:tra|tram)\\s+(.*)",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
protected String normalizeLineName(final String lineName)
|
||||
{
|
||||
protected String normalizeLineName(final String lineName) {
|
||||
final Matcher mTram = P_NORMALIZE_LINE_NAME_TRAM.matcher(lineName);
|
||||
if (mTram.matches())
|
||||
return mTram.group(1);
|
||||
|
@ -119,8 +113,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String lineAndType)
|
||||
{
|
||||
protected Line parseLineAndType(final String lineAndType) {
|
||||
if ("X#".equals(lineAndType))
|
||||
return newLine(Product.HIGH_SPEED_TRAIN, "X", null); // InterConnex
|
||||
else
|
||||
|
@ -128,17 +121,19 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line newLine(final Product product, final String normalizedName, final String comment, final Attr... attrs)
|
||||
{
|
||||
protected Line newLine(final Product product, final String normalizedName, final String comment,
|
||||
final Attr... attrs) {
|
||||
if (product == Product.SUBURBAN_TRAIN && "S41".equals(normalizedName))
|
||||
return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.CIRCLE_CLOCKWISE));
|
||||
if (product == Product.SUBURBAN_TRAIN && "S42".equals(normalizedName))
|
||||
return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.CIRCLE_ANTICLOCKWISE));
|
||||
|
||||
if (product == Product.BUS && "S41".equals(normalizedName))
|
||||
return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE));
|
||||
return super.newLine(product, normalizedName, comment,
|
||||
concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE));
|
||||
if (product == Product.BUS && "S42".equals(normalizedName))
|
||||
return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE));
|
||||
return super.newLine(product, normalizedName, comment,
|
||||
concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE));
|
||||
|
||||
if (product == Product.BUS && "TXL".equals(normalizedName))
|
||||
return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.LINE_AIRPORT));
|
||||
|
@ -150,8 +145,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
return super.newLine(product, normalizedName, comment, attrs);
|
||||
}
|
||||
|
||||
private Attr[] concatAttrs(final Attr[] attrs1, final Attr... attrs2)
|
||||
{
|
||||
private Attr[] concatAttrs(final Attr[] attrs1, final Attr... attrs2) {
|
||||
final int attrs1length = attrs1.length;
|
||||
final int attrs2length = attrs2.length;
|
||||
|
||||
|
@ -166,8 +160,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("SS1", new Style(Style.rgb(221, 77, 174), Style.WHITE));
|
||||
STYLES.put("SS2", new Style(Style.rgb(16, 132, 73), Style.WHITE));
|
||||
STYLES.put("SS25", new Style(Style.rgb(16, 132, 73), Style.WHITE));
|
||||
|
@ -280,8 +273,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Point[] getArea()
|
||||
{
|
||||
public Point[] getArea() {
|
||||
return new Point[] { Point.fromDouble(52.674189, 13.074604), Point.fromDouble(52.341100, 13.757130) };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,12 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class DingProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class DingProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://www.ding-ulm.de/ding2/";
|
||||
|
||||
// http://www.ding.eu/swu
|
||||
|
||||
public DingProvider()
|
||||
{
|
||||
public DingProvider() {
|
||||
super(NetworkId.DING, API_BASE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,25 +25,23 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class DsbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class DsbProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://mobil.rejseplanen.dk/mobil-bin/";
|
||||
// http://dk.hafas.de/bin/fat/
|
||||
// http://mobil.rejseplanen.dk/mobil-bin/
|
||||
// http://www.dsb.dk/Rejseplan/bin/
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.BUS, Product.BUS, Product.BUS, Product.FERRY, Product.SUBWAY };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.BUS,
|
||||
Product.BUS, Product.BUS, Product.FERRY, Product.SUBWAY };
|
||||
|
||||
public DsbProvider()
|
||||
{
|
||||
public DsbProvider() {
|
||||
super(NetworkId.DSB, API_BASE, "mn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_PAREN.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -52,14 +50,12 @@ public class DsbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("ICL".equals(ucType))
|
||||
|
|
|
@ -20,12 +20,10 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class DubProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class DubProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://wojhati.rta.ae/dub/";
|
||||
|
||||
public DubProvider()
|
||||
{
|
||||
public DubProvider() {
|
||||
super(NetworkId.DUB, API_BASE);
|
||||
|
||||
setTimeZone("Asia/Dubai");
|
||||
|
|
|
@ -36,37 +36,33 @@ import de.schildbach.pte.dto.QueryTripsResult;
|
|||
*
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class EireannProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class EireannProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://journeyplanner.buseireann.ie/jp/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { null, null, null, Product.BUS };
|
||||
|
||||
public EireannProvider()
|
||||
{
|
||||
public EireannProvider() {
|
||||
super(NetworkId.EIREANN, API_BASE, "en", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return queryTripsXml(from, via, to, date, dep, products, walkSpeed, accessibility, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
return queryMoreTripsXml(context, later);
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([^#]+)#");
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String lineAndType)
|
||||
{
|
||||
protected Line parseLineAndType(final String lineAndType) {
|
||||
final Matcher mLine = P_NORMALIZE_LINE.matcher(lineAndType);
|
||||
if (mLine.matches())
|
||||
return newLine(Product.BUS, mLine.group(1), null);
|
||||
|
@ -75,8 +71,7 @@ public class EireannProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("COA".equals(ucType))
|
||||
|
|
|
@ -25,58 +25,47 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
* @author Nicolas Derive
|
||||
* @author Stéphane Guillou
|
||||
*/
|
||||
public class FranceNorthEastProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class FranceNorthEastProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "fr-ne";
|
||||
// dataset available at: https://navitia.opendatasoft.com/explore/dataset/fr-ne/
|
||||
|
||||
public FranceNorthEastProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public FranceNorthEastProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.FRANCENORTHEAST, apiBase, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
public FranceNorthEastProvider(final String authorization)
|
||||
{
|
||||
public FranceNorthEastProvider(final String authorization) {
|
||||
super(NetworkId.FRANCENORTHEAST, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Style getLineStyle(final Product product, final String code, final String color)
|
||||
{
|
||||
switch (product)
|
||||
{
|
||||
case REGIONAL_TRAIN:
|
||||
{
|
||||
protected Style getLineStyle(final Product product, final String code, final String color) {
|
||||
switch (product) {
|
||||
case REGIONAL_TRAIN: {
|
||||
// Rail (route_type = 2) for TER and Corail Intercité/Lunéa (all SNCF)
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBURBAN_TRAIN:
|
||||
{
|
||||
case SUBURBAN_TRAIN: {
|
||||
// Rail (route_type = 2) for Transilien (SNCF)
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case TRAM:
|
||||
{
|
||||
case TRAM: {
|
||||
// Tram (route_type = 0) for Strasboug (CTS) and Nancy (Stan)
|
||||
return new Style(Shape.RECT, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case BUS:
|
||||
{
|
||||
case BUS: {
|
||||
// Bus (route_type = 3)
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBWAY:
|
||||
{
|
||||
case SUBWAY: {
|
||||
// Subway (route_type = 1) for Lille (Transpole)
|
||||
return new Style(Shape.CIRCLE, Style.TRANSPARENT, Style.parseColor(color), Style.parseColor(color));
|
||||
}
|
||||
|
|
|
@ -24,61 +24,49 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Anthony Chaput
|
||||
*/
|
||||
public class FranceSouthEastProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class FranceSouthEastProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "fr-se";
|
||||
|
||||
public FranceSouthEastProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public FranceSouthEastProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.FRANCESOUTHEAST, apiBase, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
public FranceSouthEastProvider(final String authorization)
|
||||
{
|
||||
public FranceSouthEastProvider(final String authorization) {
|
||||
super(NetworkId.FRANCESOUTHEAST, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Style getLineStyle(final Product product, final String code, final String color)
|
||||
{
|
||||
switch (product)
|
||||
{
|
||||
case REGIONAL_TRAIN:
|
||||
{
|
||||
protected Style getLineStyle(final Product product, final String code, final String color) {
|
||||
switch (product) {
|
||||
case REGIONAL_TRAIN: {
|
||||
// TER + Intercités
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBURBAN_TRAIN:
|
||||
{
|
||||
case SUBURBAN_TRAIN: {
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case TRAM:
|
||||
{
|
||||
case TRAM: {
|
||||
// Tram
|
||||
return new Style(Shape.CIRCLE, Style.TRANSPARENT, Style.parseColor(color), Style.parseColor(color));
|
||||
}
|
||||
case BUS:
|
||||
{
|
||||
case BUS: {
|
||||
// Bus + Transgironde
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case FERRY:
|
||||
{
|
||||
case FERRY: {
|
||||
// Batcub
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBWAY:
|
||||
{
|
||||
case SUBWAY: {
|
||||
// Toulouse subway (from Tisseo network)
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
|
|
|
@ -24,61 +24,49 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Nicolas Derive
|
||||
*/
|
||||
public class FrenchSouthWestProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class FrenchSouthWestProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "fr-sw";
|
||||
|
||||
public FrenchSouthWestProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public FrenchSouthWestProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.FRENCHSOUTHWEST, apiBase, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
public FrenchSouthWestProvider(final String authorization)
|
||||
{
|
||||
public FrenchSouthWestProvider(final String authorization) {
|
||||
super(NetworkId.FRENCHSOUTHWEST, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Style getLineStyle(final Product product, final String code, final String color)
|
||||
{
|
||||
switch (product)
|
||||
{
|
||||
case REGIONAL_TRAIN:
|
||||
{
|
||||
protected Style getLineStyle(final Product product, final String code, final String color) {
|
||||
switch (product) {
|
||||
case REGIONAL_TRAIN: {
|
||||
// TER + Intercités
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBURBAN_TRAIN:
|
||||
{
|
||||
case SUBURBAN_TRAIN: {
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case TRAM:
|
||||
{
|
||||
case TRAM: {
|
||||
// Tram
|
||||
return new Style(Shape.CIRCLE, Style.TRANSPARENT, Style.parseColor(color), Style.parseColor(color));
|
||||
}
|
||||
case BUS:
|
||||
{
|
||||
case BUS: {
|
||||
// Bus + Transgironde
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case FERRY:
|
||||
{
|
||||
case FERRY: {
|
||||
// Batcub
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBWAY:
|
||||
{
|
||||
case SUBWAY: {
|
||||
// Toulouse subway (from Tisseo network)
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
|
|
|
@ -29,21 +29,18 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class GvhProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class GvhProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://bhb.efa.de/bhb/";
|
||||
|
||||
// http://www.efa.de/efaws2/cmsembedded_gvh/
|
||||
// http://bhb.efa.de/bhb/
|
||||
// http://mobil.efa.de/mobile3/
|
||||
|
||||
public GvhProvider()
|
||||
{
|
||||
public GvhProvider() {
|
||||
this(API_BASE);
|
||||
}
|
||||
|
||||
public GvhProvider(final String apiBase)
|
||||
{
|
||||
public GvhProvider(final String apiBase) {
|
||||
super(NetworkId.GVH, apiBase);
|
||||
|
||||
setStyles(STYLES);
|
||||
|
@ -51,12 +48,10 @@ public class GvhProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("S4".equals(trainNum))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "S4");
|
||||
if (longName != null && longName.startsWith("Bus ") && name != null)
|
||||
|
@ -68,8 +63,7 @@ public class GvhProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Hannover
|
||||
STYLES.put("SS1", new Style(Style.Shape.CIRCLE, Style.parseColor("#816ba8"), Style.WHITE));
|
||||
STYLES.put("SS2", new Style(Style.Shape.CIRCLE, Style.parseColor("#007a3b"), Style.WHITE));
|
||||
|
@ -151,8 +145,10 @@ public class GvhProvider extends AbstractEfaProvider
|
|||
|
||||
// Hamburg
|
||||
// STYLES.put("SS1", new Style(Style.parseColor("#00933B"), Style.WHITE));
|
||||
// STYLES.put("SS11", new Style(Style.WHITE, Style.parseColor("#00933B"), Style.parseColor("#00933B")));
|
||||
// STYLES.put("SS2", new Style(Style.WHITE, Style.parseColor("#9D271A"), Style.parseColor("#9D271A")));
|
||||
// STYLES.put("SS11", new Style(Style.WHITE, Style.parseColor("#00933B"),
|
||||
// Style.parseColor("#00933B")));
|
||||
// STYLES.put("SS2", new Style(Style.WHITE, Style.parseColor("#9D271A"),
|
||||
// Style.parseColor("#9D271A")));
|
||||
// STYLES.put("SS21", new Style(Style.parseColor("#9D271A"), Style.WHITE));
|
||||
// STYLES.put("SS3", new Style(Style.parseColor("#411273"), Style.WHITE));
|
||||
// STYLES.put("SS31", new Style(Style.parseColor("#411273"), Style.WHITE));
|
||||
|
|
|
@ -66,8 +66,7 @@ import de.schildbach.pte.util.XmlPullUtil;
|
|||
/**
|
||||
* @author Mats Sjöberg <mats@sjoberg.fi>
|
||||
*/
|
||||
public class HslProvider extends AbstractNetworkProvider
|
||||
{
|
||||
public class HslProvider extends AbstractNetworkProvider {
|
||||
private static final String API_BASE = "http://api.reittiopas.fi/hsl/";
|
||||
private static final String SERVER_PRODUCT = "hsl";
|
||||
private static final String SERVER_VERSION = "1_2_0";
|
||||
|
@ -79,31 +78,26 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
private String user;
|
||||
private String pass;
|
||||
|
||||
public HslProvider(String user, String pass)
|
||||
{
|
||||
public HslProvider(String user, String pass) {
|
||||
super(NetworkId.HSL);
|
||||
|
||||
this.user = user;
|
||||
this.pass = pass;
|
||||
|
||||
try
|
||||
{
|
||||
parserFactory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
{
|
||||
try {
|
||||
parserFactory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
|
||||
null);
|
||||
} catch (final XmlPullParserException x) {
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCapability(final Capability capability)
|
||||
{
|
||||
protected boolean hasCapability(final Capability capability) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private StringBuilder apiUri(final String request)
|
||||
{
|
||||
private StringBuilder apiUri(final String request) {
|
||||
StringBuilder uri = new StringBuilder(API_BASE);
|
||||
uri.append(SERVER_VERSION + "/");
|
||||
uri.append("?user=" + user);
|
||||
|
@ -115,8 +109,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
return uri;
|
||||
}
|
||||
|
||||
private Point coordStrToPoint(final String coordStr)
|
||||
{
|
||||
private Point coordStrToPoint(final String coordStr) {
|
||||
if (coordStr == null)
|
||||
return null;
|
||||
|
||||
|
@ -124,8 +117,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
return Point.fromDouble(Double.parseDouble(parts[1]), Double.parseDouble(parts[0]));
|
||||
}
|
||||
|
||||
private Point xmlCoordsToPoint(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
{
|
||||
private Point xmlCoordsToPoint(final XmlPullParser pp) throws XmlPullParserException, IOException {
|
||||
XmlPullUtil.enter(pp, "coord");
|
||||
String x = xmlValueTag(pp, "x");
|
||||
String y = xmlValueTag(pp, "y");
|
||||
|
@ -133,19 +125,17 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
return Point.fromDouble(Double.parseDouble(y), Double.parseDouble(x));
|
||||
}
|
||||
|
||||
private String xmlValueTag(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
private String xmlValueTag(final XmlPullParser pp, final String tagName)
|
||||
throws XmlPullParserException, IOException {
|
||||
XmlPullUtil.skipUntil(pp, tagName);
|
||||
return XmlPullUtil.valueTag(pp, tagName);
|
||||
}
|
||||
|
||||
private String locationToCoords(final Location loc)
|
||||
{
|
||||
private String locationToCoords(final Location loc) {
|
||||
return String.format("%2.6f,%2.6f", loc.getLonAsDouble(), loc.getLatAsDouble());
|
||||
}
|
||||
|
||||
private Location queryStop(final String stationId) throws IOException
|
||||
{
|
||||
private Location queryStop(final String stationId) throws IOException {
|
||||
final StringBuilder uri = apiUri("stop");
|
||||
|
||||
uri.append("&code=").append(stationId);
|
||||
|
@ -154,8 +144,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
InputStream is = null;
|
||||
String firstChars = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
is = httpClient.getInputStream(uri.toString());
|
||||
firstChars = HttpClient.peekFirstChars(is);
|
||||
|
||||
|
@ -170,13 +159,9 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
final Point pt = coordStrToPoint(xmlValueTag(pp, "coords"));
|
||||
|
||||
return new Location(LocationType.STATION, id, pt.lat, pt.lon, null, name);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
{
|
||||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
|
@ -185,13 +170,11 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
// Determine stations near to given location. At least one of
|
||||
// stationId or lat/lon pair must be present.
|
||||
// NOTE: HSL returns only stops, not other locations, so "types" is not honoured.
|
||||
public NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance, int maxStations)
|
||||
throws IOException
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance,
|
||||
int maxStations) throws IOException {
|
||||
final StringBuilder uri = apiUri("stops_area");
|
||||
|
||||
if (!location.hasLocation())
|
||||
{
|
||||
if (!location.hasLocation()) {
|
||||
if (location.type != LocationType.STATION)
|
||||
throw new IllegalArgumentException("cannot handle: " + location.type);
|
||||
if (!location.hasId())
|
||||
|
@ -205,8 +188,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
InputStream is = null;
|
||||
String firstChars = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
is = httpClient.getInputStream(uri.toString());
|
||||
firstChars = HttpClient.peekFirstChars(is);
|
||||
|
||||
|
@ -218,8 +200,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
XmlPullUtil.enter(pp, "response");
|
||||
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
|
||||
final String id = xmlValueTag(pp, "code");
|
||||
|
@ -233,44 +214,32 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
}
|
||||
|
||||
return new NearbyLocationsResult(header, stations);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
{
|
||||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Line newLine(String code, int type, String message)
|
||||
{
|
||||
private Line newLine(String code, int type, String message) {
|
||||
String label = code.substring(1, 5).trim().replaceAll("^0+", "");
|
||||
Product product = Product.BUS;
|
||||
char acode = code.substring(0, 1).charAt(0);
|
||||
|
||||
int color = 0xFF193695;
|
||||
|
||||
if (label.equals("1300M") || type == 6)
|
||||
{
|
||||
if (label.equals("1300M") || type == 6) {
|
||||
label = "Metro";
|
||||
product = Product.SUBWAY;
|
||||
color = 0xFFfb6500;
|
||||
}
|
||||
else if (label.equals("1019") || type == 7)
|
||||
{
|
||||
} else if (label.equals("1019") || type == 7) {
|
||||
label = "Ferry";
|
||||
product = Product.FERRY;
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
} else if (type == 2) {
|
||||
product = Product.TRAM;
|
||||
color = 0xFF00ab67;
|
||||
}
|
||||
else if (type == 12 || (type == 0 && acode == '3'))
|
||||
{
|
||||
} else if (type == 12 || (type == 0 && acode == '3')) {
|
||||
product = Product.REGIONAL_TRAIN;
|
||||
color = 0xFF2cbe2c;
|
||||
if ((label.charAt(0) == '1' || label.charAt(0) == '2') && label.length() == 2)
|
||||
|
@ -283,13 +252,12 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
}
|
||||
|
||||
// Get departures at a given station, probably live
|
||||
public QueryDeparturesResult queryDepartures(String stationId, @Nullable Date queryDate, int maxDepartures, boolean equivs) throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(String stationId, @Nullable Date queryDate, int maxDepartures,
|
||||
boolean equivs) throws IOException {
|
||||
final StringBuilder uri = apiUri("stop");
|
||||
|
||||
uri.append("&code=").append(stationId);
|
||||
if (queryDate != null)
|
||||
{
|
||||
if (queryDate != null) {
|
||||
uri.append("&date=").append(new SimpleDateFormat("yyyyMMdd").format(queryDate));
|
||||
uri.append("&time=").append(new SimpleDateFormat("HHmm").format(queryDate));
|
||||
}
|
||||
|
@ -298,8 +266,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
InputStream is = null;
|
||||
String firstChars = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
is = httpClient.getInputStream(uri.toString());
|
||||
firstChars = HttpClient.peekFirstChars(is);
|
||||
|
||||
|
@ -317,8 +284,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
XmlPullUtil.skipUntil(pp, "lines");
|
||||
XmlPullUtil.enter(pp, "lines");
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
final String[] parts = XmlPullUtil.valueTag(pp, "node").split(":");
|
||||
lines.put(parts[0], newLine(parts[0], 0, parts[1]));
|
||||
}
|
||||
|
@ -331,8 +297,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
XmlPullUtil.enter(pp, "departures");
|
||||
|
||||
final List<Departure> departures = new ArrayList<Departure>(maxDepartures);
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
final String code = xmlValueTag(pp, "code");
|
||||
final String time = xmlValueTag(pp, "time");
|
||||
|
@ -353,13 +318,9 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
{
|
||||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
|
@ -373,8 +334,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
* @return location suggestions
|
||||
* @throws IOException
|
||||
*/
|
||||
public SuggestLocationsResult suggestLocations(CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(CharSequence constraint) throws IOException {
|
||||
final StringBuilder uri = apiUri("geocode");
|
||||
|
||||
// Since HSL is picky about the input we clean out any
|
||||
|
@ -387,8 +347,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
InputStream is = null;
|
||||
String firstChars = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
is = httpClient.getInputStream(uri.toString());
|
||||
firstChars = HttpClient.peekFirstChars(is);
|
||||
|
||||
|
@ -405,8 +364,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
int weight = 10000;
|
||||
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
final String locType = xmlValueTag(pp, "locType");
|
||||
String name = xmlValueTag(pp, "name");
|
||||
|
@ -437,21 +395,16 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
}
|
||||
|
||||
return new SuggestLocationsResult(header, locations);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
{
|
||||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class QueryTripsHslContext implements QueryTripsContext
|
||||
{
|
||||
public static class QueryTripsHslContext implements QueryTripsContext {
|
||||
public final String uri;
|
||||
public Date date;
|
||||
public Date prevDate = null;
|
||||
|
@ -461,8 +414,8 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
public final Location to;
|
||||
public List<Trip> trips;
|
||||
|
||||
public QueryTripsHslContext(final String uri, final Location from, final Location via, final Location to, final Date date)
|
||||
{
|
||||
public QueryTripsHslContext(final String uri, final Location from, final Location via, final Location to,
|
||||
final Date date) {
|
||||
this.uri = uri;
|
||||
this.from = from;
|
||||
this.via = via;
|
||||
|
@ -471,27 +424,23 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
this.trips = new ArrayList<Trip>();
|
||||
}
|
||||
|
||||
public boolean canQueryLater()
|
||||
{
|
||||
public boolean canQueryLater() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canQueryEarlier()
|
||||
{
|
||||
public boolean canQueryEarlier() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Query trips, asking for any ambiguousnesses
|
||||
// NOTE: HSL ignores accessibility
|
||||
public QueryTripsResult queryTrips(Location from, @Nullable Location via, Location to, Date date, boolean dep, @Nullable Set<Product> products,
|
||||
@Nullable Optimize optimize, @Nullable WalkSpeed walkSpeed, @Nullable Accessibility accessibility, @Nullable Set<Option> options)
|
||||
throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(Location from, @Nullable Location via, Location to, Date date, boolean dep,
|
||||
@Nullable Set<Product> products, @Nullable Optimize optimize, @Nullable WalkSpeed walkSpeed,
|
||||
@Nullable Accessibility accessibility, @Nullable Set<Option> options) throws IOException {
|
||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
||||
if (!from.isIdentified())
|
||||
{
|
||||
if (!from.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(from.name).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS);
|
||||
|
@ -500,8 +449,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
from = locations.get(0);
|
||||
}
|
||||
|
||||
if (via != null && !via.isIdentified())
|
||||
{
|
||||
if (via != null && !via.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(via.name).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS);
|
||||
|
@ -510,8 +458,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
via = locations.get(0);
|
||||
}
|
||||
|
||||
if (!to.isIdentified())
|
||||
{
|
||||
if (!to.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(to.name).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS);
|
||||
|
@ -533,10 +480,10 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
uri.append(String.format("&walk_speed=%d", walkSpeed == WalkSpeed.SLOW ? 30 : 100));
|
||||
uri.append("&show=5");
|
||||
|
||||
if (products != null && products.size() > 0)
|
||||
{
|
||||
if (products != null && products.size() > 0) {
|
||||
List<String> tt = new ArrayList<String>();
|
||||
if (products.contains(Product.HIGH_SPEED_TRAIN) || products.contains(Product.REGIONAL_TRAIN) || products.contains(Product.SUBURBAN_TRAIN))
|
||||
if (products.contains(Product.HIGH_SPEED_TRAIN) || products.contains(Product.REGIONAL_TRAIN)
|
||||
|| products.contains(Product.SUBURBAN_TRAIN))
|
||||
tt.add("train");
|
||||
if (products.contains(Product.SUBWAY))
|
||||
tt.add("metro");
|
||||
|
@ -566,18 +513,14 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
* @return result object that contains possible trips
|
||||
* @throws IOException
|
||||
*/
|
||||
public QueryTripsResult queryMoreTrips(QueryTripsContext contextObj, boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(QueryTripsContext contextObj, boolean later) throws IOException {
|
||||
final QueryTripsHslContext context = (QueryTripsHslContext) contextObj;
|
||||
|
||||
QueryTripsResult result;
|
||||
|
||||
if (later)
|
||||
{
|
||||
if (later) {
|
||||
result = queryHslTrips(context.from, context.via, context.to, context, context.nextDate, later);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// if we are fetching earlier trips, we have
|
||||
// to do a hack to search backwards in small
|
||||
// steps
|
||||
|
@ -588,8 +531,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
final Calendar cal = new GregorianCalendar(timeZone);
|
||||
cal.setTime(context.prevDate);
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
cal.add(Calendar.MINUTE, -EARLIER_TRIPS_MINUTE_OFFSET);
|
||||
result = queryHslTrips(context.from, context.via, context.to, context, cal.getTime(), later);
|
||||
|
||||
|
@ -597,16 +539,14 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
// keep trying if we are fetching earlier
|
||||
// trips and the list of trips hasn't grown enough
|
||||
}
|
||||
while ((result.trips.size() - contextTrips < EARLIER_TRIPS_MINIMUM) && tries < 10);
|
||||
} while ((result.trips.size() - contextTrips < EARLIER_TRIPS_MINIMUM) && tries < 10);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private QueryTripsResult queryHslTrips(final Location from, final Location via, final Location to, QueryTripsHslContext context, Date date,
|
||||
boolean later) throws IOException
|
||||
{
|
||||
private QueryTripsResult queryHslTrips(final Location from, final Location via, final Location to,
|
||||
QueryTripsHslContext context, Date date, boolean later) throws IOException {
|
||||
final StringBuilder uri = new StringBuilder(context.uri);
|
||||
|
||||
uri.append("&date=").append(new SimpleDateFormat("yyyyMMdd").format(date));
|
||||
|
@ -617,8 +557,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
context.date = date;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
is = httpClient.getInputStream(uri.toString());
|
||||
firstChars = HttpClient.peekFirstChars(is);
|
||||
|
||||
|
@ -638,8 +577,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
int insert = later ? trips.size() : 0;
|
||||
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
|
@ -650,8 +588,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
XmlPullUtil.enter(pp, "legs");
|
||||
int numTransfers = 0;
|
||||
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
|
||||
int distance = Integer.parseInt(xmlValueTag(pp, "length"));
|
||||
|
@ -671,8 +608,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
|
||||
XmlPullUtil.skipUntil(pp, "locs");
|
||||
XmlPullUtil.enter(pp, "locs");
|
||||
while (XmlPullUtil.test(pp, "node"))
|
||||
{
|
||||
while (XmlPullUtil.test(pp, "node")) {
|
||||
XmlPullUtil.enter(pp, "node");
|
||||
Point pt = xmlCoordsToPoint(pp);
|
||||
|
||||
|
@ -683,8 +619,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
String shortCode = XmlPullUtil.optValueTag(pp, "shortCode", null);
|
||||
String stopAddress = XmlPullUtil.optValueTag(pp, "stopAddress", null);
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
if (name == null) {
|
||||
name = (path.size() == 0 && from != null && from.name != null) ? from.name : null;
|
||||
}
|
||||
|
||||
|
@ -697,20 +632,16 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
type = LocationType.STATION;
|
||||
Location loc = new Location(type, code, pt.lat, pt.lon, stopAddress, name);
|
||||
|
||||
if (path.size() == 0)
|
||||
{
|
||||
if (path.size() == 0) {
|
||||
departure = loc;
|
||||
departureTime = depDate;
|
||||
if (type == LocationType.STATION)
|
||||
departureStop = new Stop(loc, true, departureTime, null, null, null);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
arrival = loc;
|
||||
arrivalTime = arrDate;
|
||||
if (type == LocationType.STATION)
|
||||
{
|
||||
if (type == LocationType.STATION) {
|
||||
stops.add(new Stop(loc, arrDate, null, depDate, null));
|
||||
}
|
||||
}
|
||||
|
@ -721,21 +652,18 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
XmlPullUtil.skipExit(pp, "locs");
|
||||
XmlPullUtil.skipExit(pp, "node");
|
||||
|
||||
if (legType.equals("walk"))
|
||||
{
|
||||
if (legType.equals("walk")) {
|
||||
// ugly hack to set the name of the last arrival
|
||||
if (arrival != null && arrival.name == null)
|
||||
{
|
||||
arrival = new Location(arrival.type, arrival.id, arrival.lat, arrival.lon, arrival.place, to.name);
|
||||
if (arrival != null && arrival.name == null) {
|
||||
arrival = new Location(arrival.type, arrival.id, arrival.lat, arrival.lon, arrival.place,
|
||||
to.name);
|
||||
}
|
||||
|
||||
legs.add(new Trip.Individual(Trip.Individual.Type.WALK, departure, departureTime, arrival, arrivalTime, path, distance));
|
||||
}
|
||||
else
|
||||
{
|
||||
legs.add(new Trip.Individual(Trip.Individual.Type.WALK, departure, departureTime, arrival,
|
||||
arrivalTime, path, distance));
|
||||
} else {
|
||||
Stop arrivalStop = null;
|
||||
if (stops.size() > 0)
|
||||
{
|
||||
if (stops.size() > 0) {
|
||||
Stop last = stops.getLast();
|
||||
arrivalStop = new Stop(last.location, false, last.plannedArrivalTime, null, null, null);
|
||||
stops.removeLast();
|
||||
|
@ -754,8 +682,7 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
XmlPullUtil.skipExit(pp, "node");
|
||||
|
||||
Trip t = new Trip(null, from, to, legs, null, null, numTransfers - 1);
|
||||
if (!tripSet.contains(t.getId()))
|
||||
{
|
||||
if (!tripSet.contains(t.getId())) {
|
||||
Date thisTime = t.getFirstDepartureTime();
|
||||
while (insert < trips.size() && thisTime.after(trips.get(insert).getFirstDepartureTime()))
|
||||
insert++;
|
||||
|
@ -773,13 +700,9 @@ public class HslProvider extends AbstractNetworkProvider
|
|||
context.prevDate = firstDate;
|
||||
context.trips = trips;
|
||||
return new QueryTripsResult(header, uri.toString(), from, via, to, context, trips);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
{
|
||||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
|
|
|
@ -57,15 +57,13 @@ import de.schildbach.pte.util.ParserUtils;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class InvgProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class InvgProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://fpa.invg.de/bin/";
|
||||
// http://invg.hafas.de/bin/
|
||||
private static final Product[] PRODUCTS_MAP = { null, null, null, null, null, null, null, null, null, null };
|
||||
private static final long PARSER_DAY_ROLLOVER_THRESHOLD_MS = 12 * 60 * 60 * 1000;
|
||||
|
||||
public InvgProvider()
|
||||
{
|
||||
public InvgProvider() {
|
||||
super(NetworkId.INVG, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardCanDoEquivs(false);
|
||||
|
@ -76,8 +74,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCapability(final Capability capability)
|
||||
{
|
||||
protected boolean hasCapability(final Capability capability) {
|
||||
if (capability == Capability.TRIPS)
|
||||
return false;
|
||||
else
|
||||
|
@ -87,8 +84,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
private static final String[] PLACES = { "Ingolstadt", "München" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -101,8 +97,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -111,8 +106,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -121,27 +115,21 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxStations) throws IOException
|
||||
{
|
||||
if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxStations) throws IOException {
|
||||
if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern
|
||||
.compile(
|
||||
".*?" //
|
||||
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern.compile(".*?" //
|
||||
+ "(?:" //
|
||||
+ "<div class=\"summary clearfix\">.*?<div class=\"block\">.*?(<div>.*?</div>.*?<div class=\"last\">.*?</div>).*?</div>.*?" //
|
||||
+ "<div class=\"linkGroup\">.*?input=(\\d+).*?" // locationId
|
||||
|
@ -149,13 +137,16 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
+ "|(Eingabe kann nicht interpretiert)|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden))" //
|
||||
+ ".*?" //
|
||||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile(".*?" //
|
||||
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile(
|
||||
".*?" //
|
||||
+ "<span class=\"output\">(.*?)<.*?" // location
|
||||
+ "<span class=\"output\">\n(\\d{2}\\.\\d{2}\\.\\d{2}).*?" // date
|
||||
+ "Abfahrt (\\d{1,2}:\\d{2}).*?" // time
|
||||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>",
|
||||
Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(
|
||||
".*?" //
|
||||
+ "<td class=\"time\">(\\d{1,2}:\\d{2})</td>\n" // plannedTime
|
||||
+ "(?:<td class=\"[\\w ]*prognosis[\\w ]*\">\n" //
|
||||
+ "(?: |<span class=\"rtLimit\\d\">(pünktlich|\\d{1,2}:\\d{2})</span>)\n</td>\n" // predictedTime
|
||||
|
@ -170,9 +161,8 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
, Pattern.DOTALL);
|
||||
|
||||
@Override
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
checkNotNull(Strings.emptyToNull(stationId));
|
||||
|
||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
@ -185,16 +175,13 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
|
||||
// parse page
|
||||
final Matcher mHeadCoarse = P_DEPARTURES_HEAD_COARSE.matcher(page);
|
||||
if (mHeadCoarse.matches())
|
||||
{
|
||||
if (mHeadCoarse.matches()) {
|
||||
// messages
|
||||
if (mHeadCoarse.group(4) != null)
|
||||
{
|
||||
if (mHeadCoarse.group(4) != null) {
|
||||
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId),
|
||||
Collections.<Departure> emptyList(), null));
|
||||
return result;
|
||||
}
|
||||
else if (mHeadCoarse.group(5) != null)
|
||||
} else if (mHeadCoarse.group(5) != null)
|
||||
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||
else if (mHeadCoarse.group(6) != null)
|
||||
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||
|
@ -202,8 +189,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
final String locationId = mHeadCoarse.group(2);
|
||||
|
||||
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
||||
if (mHeadFine.matches())
|
||||
{
|
||||
if (mHeadFine.matches()) {
|
||||
final String[] placeAndName = splitStationName(ParserUtils.resolveEntities(mHeadFine.group(1)));
|
||||
final Calendar currentTime = new GregorianCalendar(timeZone);
|
||||
currentTime.clear();
|
||||
|
@ -213,8 +199,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
String oldZebra = null;
|
||||
|
||||
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(3));
|
||||
while (mDepCoarse.find())
|
||||
{
|
||||
while (mDepCoarse.find()) {
|
||||
final String zebra = mDepCoarse.group(1);
|
||||
if (oldZebra != null && zebra.equals(oldZebra))
|
||||
throw new IllegalArgumentException("missed row? last:" + zebra);
|
||||
|
@ -222,32 +207,26 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
oldZebra = zebra;
|
||||
|
||||
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(2));
|
||||
if (mDepFine.matches())
|
||||
{
|
||||
if (mDepFine.matches()) {
|
||||
final Calendar plannedTime = new GregorianCalendar(timeZone);
|
||||
plannedTime.setTimeInMillis(currentTime.getTimeInMillis());
|
||||
ParserUtils.parseEuropeanTime(plannedTime, mDepFine.group(1));
|
||||
|
||||
if (plannedTime.getTimeInMillis() - currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
if (plannedTime.getTimeInMillis()
|
||||
- currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
plannedTime.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
final Calendar predictedTime;
|
||||
final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
|
||||
if (prognosis != null)
|
||||
{
|
||||
if (prognosis != null) {
|
||||
predictedTime = new GregorianCalendar(timeZone);
|
||||
if (prognosis.equals("pünktlich"))
|
||||
{
|
||||
if (prognosis.equals("pünktlich")) {
|
||||
predictedTime.setTimeInMillis(plannedTime.getTimeInMillis());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
predictedTime.setTimeInMillis(currentTime.getTimeInMillis());
|
||||
ParserUtils.parseEuropeanTime(predictedTime, prognosis);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
predictedTime = null;
|
||||
}
|
||||
|
||||
|
@ -258,56 +237,50 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
final String destinationId = mDepFine.group(5);
|
||||
final String destinationName = ParserUtils.resolveEntities(mDepFine.group(6));
|
||||
final Location destination;
|
||||
if (destinationId != null)
|
||||
{
|
||||
if (destinationId != null) {
|
||||
final String[] destinationPlaceAndName = splitStationName(destinationName);
|
||||
destination = new Location(LocationType.STATION, destinationId, destinationPlaceAndName[0], destinationPlaceAndName[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
destination = new Location(LocationType.STATION, destinationId, destinationPlaceAndName[0],
|
||||
destinationPlaceAndName[1]);
|
||||
} else {
|
||||
destination = new Location(LocationType.ANY, null, null, destinationName);
|
||||
}
|
||||
|
||||
final Position position = parsePosition(ParserUtils.resolveEntities(mDepFine.group(7)));
|
||||
|
||||
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line,
|
||||
position, destination, null, null);
|
||||
final Departure dep = new Departure(plannedTime.getTime(),
|
||||
predictedTime != null ? predictedTime.getTime() : null, line, position, destination,
|
||||
null, null);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(2) + "' on " + stationId);
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"cannot parse '" + mDepCoarse.group(2) + "' on " + stationId);
|
||||
}
|
||||
}
|
||||
|
||||
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, locationId, placeAndName[0], placeAndName[1]),
|
||||
departures, null));
|
||||
result.stationDepartures.add(new StationDepartures(
|
||||
new Location(LocationType.STATION, locationId, placeAndName[0], placeAndName[1]), departures,
|
||||
null));
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot parse '" + mHeadCoarse.group(1) + "' on " + stationId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot parse '" + page + "' on " + stationId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return queryTripsXml(from, via, to, date, dep, products, walkSpeed, accessibility, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
return queryMoreTripsXml(context, later);
|
||||
}
|
||||
|
||||
|
@ -317,34 +290,28 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
protected static final Pattern P_NORMALIZE_LINE_BUS_X = Pattern.compile("Bus\\s*X\\s*(\\d+)");
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final String type, final String line, final boolean wheelchairAccess)
|
||||
{
|
||||
if ("1".equals(type))
|
||||
{
|
||||
protected Line parseLine(final String type, final String line, final boolean wheelchairAccess) {
|
||||
if ("1".equals(type)) {
|
||||
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
|
||||
if (mBus.matches())
|
||||
{
|
||||
if (mBus.matches()) {
|
||||
final String label = mBus.group(1);
|
||||
return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
|
||||
}
|
||||
|
||||
final Matcher mNachtbus = P_NORMALIZE_LINE_NACHTBUS.matcher(line);
|
||||
if (mNachtbus.matches())
|
||||
{
|
||||
if (mNachtbus.matches()) {
|
||||
final String label = "N" + mNachtbus.group(1);
|
||||
return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
|
||||
}
|
||||
|
||||
final Matcher mBusS = P_NORMALIZE_LINE_BUS_S.matcher(line);
|
||||
if (mBusS.matches())
|
||||
{
|
||||
if (mBusS.matches()) {
|
||||
final String label = "S" + mBusS.group(1);
|
||||
return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
|
||||
}
|
||||
|
||||
final Matcher mBusX = P_NORMALIZE_LINE_BUS_X.matcher(line);
|
||||
if (mBusX.matches())
|
||||
{
|
||||
if (mBusX.matches()) {
|
||||
final String label = "X" + mBusX.group(1);
|
||||
return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
|
||||
}
|
||||
|
@ -354,8 +321,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
if ("1".equals(type))
|
||||
return Product.BUS;
|
||||
|
||||
|
@ -365,8 +331,7 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("B10", new Style(Style.parseColor("#DA2510"), Style.WHITE));
|
||||
STYLES.put("B11", new Style(Style.parseColor("#EE9B78"), Style.BLACK));
|
||||
STYLES.put("B15", new Style(Style.parseColor("#84C326"), Style.BLACK));
|
||||
|
@ -376,7 +341,8 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
STYLES.put("B20", new Style(Style.parseColor("#EA891C"), Style.BLACK));
|
||||
STYLES.put("B21", new Style(Style.parseColor("#31B2EA"), Style.BLACK));
|
||||
STYLES.put("B25", new Style(Style.parseColor("#7F65A0"), Style.WHITE));
|
||||
STYLES.put("B26", new Style(Style.parseColor("#00BF73"), Style.WHITE)); // not present in Fahrplan 2012/2013
|
||||
STYLES.put("B26", new Style(Style.parseColor("#00BF73"), Style.WHITE)); // not present in Fahrplan
|
||||
// 2012/2013
|
||||
STYLES.put("B30", new Style(Style.parseColor("#901E78"), Style.WHITE));
|
||||
STYLES.put("B31", new Style(Style.parseColor("#DCE722"), Style.BLACK));
|
||||
STYLES.put("B40", new Style(Style.parseColor("#009240"), Style.WHITE));
|
||||
|
@ -388,11 +354,14 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
STYLES.put("B53", new Style(Style.parseColor("#BEB405"), Style.BLACK));
|
||||
STYLES.put("B55", new Style(Style.parseColor("#FFF500"), Style.BLACK));
|
||||
STYLES.put("B60", new Style(Style.parseColor("#0072B7"), Style.WHITE));
|
||||
STYLES.put("B61", new Style(Style.rgb(204, 184, 122), Style.BLACK)); // not present in Fahrplan 2012/2013
|
||||
STYLES.put("B62", new Style(Style.rgb(204, 184, 122), Style.BLACK)); // not present in Fahrplan 2012/2013
|
||||
STYLES.put("B61", new Style(Style.rgb(204, 184, 122), Style.BLACK)); // not present in Fahrplan
|
||||
// 2012/2013
|
||||
STYLES.put("B62", new Style(Style.rgb(204, 184, 122), Style.BLACK)); // not present in Fahrplan
|
||||
// 2012/2013
|
||||
STYLES.put("B65", new Style(Style.parseColor("#B7DDD2"), Style.BLACK));
|
||||
STYLES.put("B70", new Style(Style.parseColor("#D49016"), Style.BLACK));
|
||||
STYLES.put("B71", new Style(Style.parseColor("#996600"), Style.BLACK)); // not present in Fahrplan 2012/2013
|
||||
STYLES.put("B71", new Style(Style.parseColor("#996600"), Style.BLACK)); // not present in Fahrplan
|
||||
// 2012/2013
|
||||
STYLES.put("B85", new Style(Style.parseColor("#F6BAD3"), Style.BLACK));
|
||||
STYLES.put("B111", new Style(Style.parseColor("#EE9B78"), Style.BLACK));
|
||||
|
||||
|
|
|
@ -22,33 +22,28 @@ import de.schildbach.pte.util.WordUtils;
|
|||
/**
|
||||
* @author Antonio El Khoury
|
||||
*/
|
||||
public class ItalyProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class ItalyProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "it";
|
||||
|
||||
public ItalyProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public ItalyProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.IT, apiBase, authorization);
|
||||
|
||||
setTimeZone("Europe/Rome");
|
||||
}
|
||||
|
||||
public ItalyProvider(final String authorization)
|
||||
{
|
||||
public ItalyProvider(final String authorization) {
|
||||
super(NetworkId.IT, authorization);
|
||||
|
||||
setTimeZone("Europe/Rome");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocationName(String name)
|
||||
{
|
||||
protected String getLocationName(String name) {
|
||||
return WordUtils.capitalizeFully(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class IvbProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class IvbProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://efa.ivb.at/ivb/";
|
||||
|
||||
public IvbProvider()
|
||||
{
|
||||
public IvbProvider() {
|
||||
super(NetworkId.IVB, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
|
|
@ -35,13 +35,11 @@ import de.schildbach.pte.dto.Product;
|
|||
*
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class JetProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class JetProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://planner.jet.org.il/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { null, null, Product.TRAM, Product.BUS };
|
||||
|
||||
public JetProvider()
|
||||
{
|
||||
public JetProvider() {
|
||||
super(NetworkId.JET, API_BASE, "yn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -49,31 +47,24 @@ public class JetProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.hasLocation())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation()) {
|
||||
return nearbyLocationsByCoordinate(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
else if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
} else if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -84,8 +75,7 @@ public class JetProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_NORMALIZE_BUS = Pattern.compile("([א]?\\d{1,3})#");
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String lineAndType)
|
||||
{
|
||||
protected Line parseLineAndType(final String lineAndType) {
|
||||
if ("רק1#".equals(lineAndType))
|
||||
return newLine(Product.TRAM, "רק1", null);
|
||||
|
||||
|
|
|
@ -31,17 +31,14 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class KvvProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class KvvProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://213.144.24.66/kvv2/";
|
||||
|
||||
public KvvProvider()
|
||||
{
|
||||
public KvvProvider() {
|
||||
this(API_BASE);
|
||||
}
|
||||
|
||||
public KvvProvider(final String apiBase)
|
||||
{
|
||||
public KvvProvider(final String apiBase) {
|
||||
super(NetworkId.KVV, apiBase);
|
||||
|
||||
setStyles(STYLES);
|
||||
|
@ -51,26 +48,22 @@ public class KvvProvider extends AbstractEfaProvider
|
|||
private static final Pattern P_LINE = Pattern.compile("(.*?)\\s+\\([\\w/]+\\)", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, @Nullable String symbol,
|
||||
@Nullable String name, @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if (symbol != null)
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
@Nullable String symbol, @Nullable String name, @Nullable String longName, final @Nullable String trainType,
|
||||
final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if (symbol != null) {
|
||||
final Matcher m = P_LINE.matcher(symbol);
|
||||
if (m.matches())
|
||||
symbol = m.group(1);
|
||||
}
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
if (name != null) {
|
||||
final Matcher m = P_LINE.matcher(name);
|
||||
if (m.matches())
|
||||
name = m.group(1);
|
||||
}
|
||||
|
||||
if (longName != null)
|
||||
{
|
||||
if (longName != null) {
|
||||
final Matcher m = P_LINE.matcher(longName);
|
||||
if (m.matches())
|
||||
longName = m.group(1);
|
||||
|
@ -81,8 +74,7 @@ public class KvvProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// S-Bahn
|
||||
STYLES.put("SS1", new Style(Style.parseColor("#00a76c"), Style.WHITE));
|
||||
STYLES.put("SS11", new Style(Style.parseColor("#00a76c"), Style.WHITE));
|
||||
|
|
|
@ -25,14 +25,12 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class LinzProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class LinzProvider extends AbstractEfaProvider {
|
||||
public static final String API_BASE = "https://www.linzag.at/linz2/";
|
||||
|
||||
// http://www.linzag.at/static/
|
||||
|
||||
public LinzProvider()
|
||||
{
|
||||
public LinzProvider() {
|
||||
super(NetworkId.LINZ, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
@ -41,8 +39,7 @@ public class LinzProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("B11", new Style(Style.Shape.RECT, Style.parseColor("#f27b02"), Style.WHITE));
|
||||
STYLES.put("B12", new Style(Style.Shape.RECT, Style.parseColor("#00863a"), Style.WHITE));
|
||||
STYLES.put("B17", new Style(Style.Shape.RECT, Style.parseColor("#f47a00"), Style.WHITE));
|
||||
|
|
|
@ -20,8 +20,7 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class LocationUtils
|
||||
{
|
||||
public final class LocationUtils {
|
||||
/**
|
||||
* @param lat1
|
||||
* latitude of origin point in decimal degrees
|
||||
|
@ -34,8 +33,7 @@ public final class LocationUtils
|
|||
*
|
||||
* @return distance in meters
|
||||
*/
|
||||
public static float computeDistance(double lat1, double lon1, double lat2, double lon2)
|
||||
{
|
||||
public static float computeDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||
// Based on http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
|
||||
// using the "Inverse Formula" (section 4)
|
||||
|
||||
|
@ -73,8 +71,7 @@ public final class LocationUtils
|
|||
double sinLambda = 0.0;
|
||||
|
||||
double lambda = L; // initial guess
|
||||
for (int iter = 0; iter < MAXITERS; iter++)
|
||||
{
|
||||
for (int iter = 0; iter < MAXITERS; iter++) {
|
||||
final double lambdaOrig = lambda;
|
||||
cosLambda = Math.cos(lambda);
|
||||
sinLambda = Math.sin(lambda);
|
||||
|
@ -95,13 +92,12 @@ public final class LocationUtils
|
|||
(256.0 + uSquared * (-128.0 + uSquared * (74.0 - 47.0 * uSquared)));
|
||||
final double C = (f / 16.0) * cosSqAlpha * (4.0 + f * (4.0 - 3.0 * cosSqAlpha)); // (10)
|
||||
final double cos2SMSq = cos2SM * cos2SM;
|
||||
deltaSigma = B
|
||||
* sinSigma
|
||||
* // (6)
|
||||
(cos2SM + (B / 4.0)
|
||||
* (cosSigma * (-1.0 + 2.0 * cos2SMSq) - (B / 6.0) * cos2SM * (-3.0 + 4.0 * sinSigma * sinSigma) * (-3.0 + 4.0 * cos2SMSq)));
|
||||
deltaSigma = B * sinSigma * // (6)
|
||||
(cos2SM + (B / 4.0) * (cosSigma * (-1.0 + 2.0 * cos2SMSq)
|
||||
- (B / 6.0) * cos2SM * (-3.0 + 4.0 * sinSigma * sinSigma) * (-3.0 + 4.0 * cos2SMSq)));
|
||||
|
||||
lambda = L + (1.0 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SM + C * cosSigma * (-1.0 + 2.0 * cos2SM * cos2SM))); // (11)
|
||||
lambda = L + (1.0 - C) * f * sinAlpha
|
||||
* (sigma + C * sinSigma * (cos2SM + C * cosSigma * (-1.0 + 2.0 * cos2SM * cos2SM))); // (11)
|
||||
|
||||
final double delta = (lambda - lambdaOrig) / lambda;
|
||||
|
||||
|
|
|
@ -26,14 +26,13 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class LuProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class LuProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://mobiliteitszentral.hafas.de/hafas/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.BUS, Product.BUS, Product.BUS, Product.BUS };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.BUS, Product.BUS,
|
||||
Product.BUS, Product.BUS };
|
||||
|
||||
public LuProvider()
|
||||
{
|
||||
public LuProvider() {
|
||||
super(NetworkId.LU, API_BASE, "fn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -41,8 +40,7 @@ public class LuProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -51,8 +49,7 @@ public class LuProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -61,8 +58,7 @@ public class LuProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("CRE".equals(ucType))
|
||||
|
|
|
@ -27,12 +27,10 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class MerseyProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class MerseyProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://jp.merseytravel.gov.uk/nwm/";
|
||||
|
||||
public MerseyProvider()
|
||||
{
|
||||
public MerseyProvider() {
|
||||
super(NetworkId.MERSEY, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -40,16 +38,14 @@ public class MerseyProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
private static final Pattern P_POSITION_BOUND = Pattern.compile("([NESW]+)-bound", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
protected Position parsePosition(final String position)
|
||||
{
|
||||
protected Position parsePosition(final String position) {
|
||||
if (position == null)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -33,12 +33,10 @@ import de.schildbach.pte.dto.Style;
|
|||
*
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class MetProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class MetProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://jp.ptv.vic.gov.au/ptv/";
|
||||
|
||||
public MetProvider()
|
||||
{
|
||||
public MetProvider() {
|
||||
super(NetworkId.MET, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -49,21 +47,17 @@ public class MetProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("Regional Train :".equals(longName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, symbol);
|
||||
if ("Regional Train".equals(trainName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, null);
|
||||
if ("vPK".equals(symbol) && "Regional Train Pakenham".equals(longName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "V/Line");
|
||||
}
|
||||
else if ("1".equals(mot))
|
||||
{
|
||||
} else if ("1".equals(mot)) {
|
||||
if (trainType == null && trainNum != null)
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, trainNum);
|
||||
if ("Metropolitan Train".equals(trainName) && trainNum == null)
|
||||
|
@ -75,8 +69,7 @@ public class MetProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("R", new Style(Style.parseColor("#a24ba3"), Style.WHITE));
|
||||
STYLES.put("S", new Style(Style.parseColor("#3a75c4"), Style.WHITE));
|
||||
STYLES.put("T", new Style(Style.parseColor("#5bbf21"), Style.WHITE));
|
||||
|
|
|
@ -22,18 +22,15 @@ import de.schildbach.pte.dto.Position;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class MvgProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class MvgProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://mobil.mvg-online.de/mvgMobil/";
|
||||
|
||||
public MvgProvider()
|
||||
{
|
||||
public MvgProvider() {
|
||||
super(NetworkId.MVG, API_BASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Position parsePosition(final String position)
|
||||
{
|
||||
protected Position parsePosition(final String position) {
|
||||
if (position == null)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -33,17 +33,14 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class MvvProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class MvvProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://efa.mvv-muenchen.de/mobile/";
|
||||
|
||||
public MvvProvider()
|
||||
{
|
||||
public MvvProvider() {
|
||||
this(API_BASE);
|
||||
}
|
||||
|
||||
public MvvProvider(final String apiBase)
|
||||
{
|
||||
public MvvProvider(final String apiBase) {
|
||||
super(NetworkId.MVV, apiBase);
|
||||
|
||||
setIncludeRegionId(false);
|
||||
|
@ -52,12 +49,10 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("Mittelrheinbahn (trans regio)".equals(trainName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "MiRhBa");
|
||||
if ("Süd-Thüringen-Bahn".equals(longName))
|
||||
|
@ -70,9 +65,7 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
return new Line(id, network, Product.SUBURBAN_TRAIN, "A");
|
||||
if ("DB AG".equals(trainName))
|
||||
return new Line(id, network, null, symbol);
|
||||
}
|
||||
else if ("1".equals(mot))
|
||||
{
|
||||
} else if ("1".equals(mot)) {
|
||||
if ("S".equals(symbol) && "Pendelverkehr".equals(name))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "S⇆");
|
||||
}
|
||||
|
@ -83,14 +76,12 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
private static final Pattern P_POSITION = Pattern.compile("(Fern|Regio|S-Bahn|U-Bahn|U\\d(?:/U\\d)*)\\s+(.*)");
|
||||
|
||||
@Override
|
||||
protected Position parsePosition(final String position)
|
||||
{
|
||||
protected Position parsePosition(final String position) {
|
||||
if (position == null)
|
||||
return null;
|
||||
|
||||
final Matcher m = P_POSITION.matcher(position);
|
||||
if (m.matches())
|
||||
{
|
||||
if (m.matches()) {
|
||||
final char t = m.group(1).charAt(0);
|
||||
final Position p = super.parsePosition(m.group(2));
|
||||
if (t == 'S' || t == 'U')
|
||||
|
@ -104,8 +95,7 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("SS1", new Style(Style.parseColor("#00ccff"), Style.WHITE));
|
||||
STYLES.put("SS2", new Style(Style.parseColor("#66cc00"), Style.WHITE));
|
||||
STYLES.put("SS3", new Style(Style.parseColor("#880099"), Style.WHITE));
|
||||
|
@ -144,8 +134,7 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Point[] getArea()
|
||||
{
|
||||
public Point[] getArea() {
|
||||
return new Point[] { Point.fromDouble(48.140377, 11.560643) };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,14 +32,13 @@ import de.schildbach.pte.util.StringReplaceReader;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NasaProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class NasaProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://reiseauskunft.insa.de/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.TRAM, Product.BUS, Product.ON_DEMAND };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.TRAM, Product.BUS,
|
||||
Product.ON_DEMAND };
|
||||
|
||||
public NasaProvider()
|
||||
{
|
||||
public NasaProvider() {
|
||||
super(NetworkId.NASA, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -48,8 +47,7 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -58,8 +56,7 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -68,8 +65,7 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -78,37 +74,29 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.hasLocation())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation()) {
|
||||
return nearbyLocationsByCoordinate(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
else if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
} else if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addCustomReplaces(final StringReplaceReader reader)
|
||||
{
|
||||
protected void addCustomReplaces(final StringReplaceReader reader) {
|
||||
reader.replace("\"Florian Geyer\"", "Florian Geyer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(String type)
|
||||
{
|
||||
protected Product normalizeType(String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("ECW".equals(ucType))
|
||||
|
|
|
@ -20,8 +20,7 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public enum NetworkId
|
||||
{
|
||||
public enum NetworkId {
|
||||
// Europe
|
||||
RT,
|
||||
|
||||
|
|
|
@ -40,10 +40,8 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
*
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public interface NetworkProvider
|
||||
{
|
||||
public enum Capability
|
||||
{
|
||||
public interface NetworkProvider {
|
||||
public enum Capability {
|
||||
/* can suggest locations */
|
||||
SUGGEST_LOCATIONS,
|
||||
/* can determine nearby locations */
|
||||
|
@ -54,23 +52,19 @@ public interface NetworkProvider
|
|||
TRIPS
|
||||
}
|
||||
|
||||
public enum Optimize
|
||||
{
|
||||
public enum Optimize {
|
||||
LEAST_DURATION, LEAST_CHANGES, LEAST_WALKING
|
||||
}
|
||||
|
||||
public enum WalkSpeed
|
||||
{
|
||||
public enum WalkSpeed {
|
||||
SLOW, NORMAL, FAST
|
||||
}
|
||||
|
||||
public enum Accessibility
|
||||
{
|
||||
public enum Accessibility {
|
||||
NEUTRAL, LIMITED, BARRIER_FREE
|
||||
}
|
||||
|
||||
public enum Option
|
||||
{
|
||||
public enum Option {
|
||||
BIKE
|
||||
}
|
||||
|
||||
|
@ -79,8 +73,8 @@ public interface NetworkProvider
|
|||
boolean hasCapabilities(final Capability... capabilities);
|
||||
|
||||
/**
|
||||
* Find locations near to given location. At least one of lat/lon pair or station id must be present in that
|
||||
* location.
|
||||
* Find locations near to given location. At least one of lat/lon pair or station id must be present in
|
||||
* that location.
|
||||
*
|
||||
* @param types
|
||||
* types of locations to find
|
||||
|
@ -93,7 +87,8 @@ public interface NetworkProvider
|
|||
* @return nearby stations
|
||||
* @throws IOException
|
||||
*/
|
||||
NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance, int maxLocations) throws IOException;
|
||||
NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance,
|
||||
int maxLocations) throws IOException;
|
||||
|
||||
/**
|
||||
* Get departures at a given station, probably live
|
||||
|
@ -109,7 +104,8 @@ public interface NetworkProvider
|
|||
* @return result object containing the departures
|
||||
* @throws IOException
|
||||
*/
|
||||
QueryDeparturesResult queryDepartures(String stationId, @Nullable Date time, int maxDepartures, boolean equivs) throws IOException;
|
||||
QueryDeparturesResult queryDepartures(String stationId, @Nullable Date time, int maxDepartures, boolean equivs)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Meant for auto-completion of location names, like in an {@link android.widget.AutoCompleteTextView}
|
||||
|
@ -151,12 +147,13 @@ public interface NetworkProvider
|
|||
* route accessibility, or {@code null} for the provider default
|
||||
* @param options
|
||||
* additional options, or {@code null} for the provider default
|
||||
* @return result object that can contain alternatives to clear up ambiguousnesses, or contains possible trips
|
||||
* @return result object that can contain alternatives to clear up ambiguousnesses, or contains possible
|
||||
* trips
|
||||
* @throws IOException
|
||||
*/
|
||||
QueryTripsResult queryTrips(Location from, @Nullable Location via, Location to, Date date, boolean dep, @Nullable Set<Product> products,
|
||||
@Nullable Optimize optimize, @Nullable WalkSpeed walkSpeed, @Nullable Accessibility accessibility, @Nullable Set<Option> options)
|
||||
throws IOException;
|
||||
QueryTripsResult queryTrips(Location from, @Nullable Location via, Location to, Date date, boolean dep,
|
||||
@Nullable Set<Product> products, @Nullable Optimize optimize, @Nullable WalkSpeed walkSpeed,
|
||||
@Nullable Accessibility accessibility, @Nullable Set<Option> options) throws IOException;
|
||||
|
||||
/**
|
||||
* Query more trips (e.g. earlier or later)
|
||||
|
@ -186,7 +183,8 @@ public interface NetworkProvider
|
|||
/**
|
||||
* Gets the primary covered area of the network
|
||||
*
|
||||
* @return array containing points of a polygon (special case: just one coordinate defines just a center point)
|
||||
* @return array containing points of a polygon (special case: just one coordinate defines just a center
|
||||
* point)
|
||||
* @throws IOException
|
||||
*/
|
||||
Point[] getArea() throws IOException;
|
||||
|
|
|
@ -33,14 +33,12 @@ import de.schildbach.pte.dto.QueryTripsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NriProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class NriProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://hafas.websrv05.reiseinfo.no/bin/dev/nri/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.BUS, Product.TRAM, Product.SUBWAY,
|
||||
Product.FERRY, Product.FERRY, Product.FERRY };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.BUS,
|
||||
Product.TRAM, Product.SUBWAY, Product.FERRY, Product.FERRY, Product.FERRY };
|
||||
|
||||
public NriProvider()
|
||||
{
|
||||
public NriProvider() {
|
||||
super(NetworkId.NRI, API_BASE, "on", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -49,8 +47,7 @@ public class NriProvider extends AbstractHafasProvider
|
|||
private static final String[] PLACES = { "Oslo", "Bergen" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
for (final String place : PLACES)
|
||||
if (name.startsWith(place + " "))
|
||||
return new String[] { place, name.substring(place.length() + 1) };
|
||||
|
@ -59,28 +56,25 @@ public class NriProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return queryTripsXml(from, via, to, date, dep, products, walkSpeed, accessibility, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
return queryMoreTripsXml(context, later);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("AIR".equals(ucType))
|
||||
|
|
|
@ -30,15 +30,15 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NsProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class NsProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://hafas.bene-system.com/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
private static final Pattern HTML_NEARBY_STATIONS_PATTERN = Pattern.compile("<tr bgcolor=\"#(E7EEF9|99BAE4)\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY,
|
||||
Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
private static final Pattern HTML_NEARBY_STATIONS_PATTERN = Pattern
|
||||
.compile("<tr bgcolor=\"#(E7EEF9|99BAE4)\">(.*?)</tr>", Pattern.DOTALL);
|
||||
|
||||
public NsProvider()
|
||||
{
|
||||
public NsProvider() {
|
||||
super(NetworkId.NS, API_BASE, "nn", PRODUCTS_MAP);
|
||||
|
||||
setHtmlNearbyStationsPattern(HTML_NEARBY_STATIONS_PATTERN);
|
||||
|
@ -46,11 +46,9 @@ public class NsProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
|
@ -58,22 +56,18 @@ public class NsProvider extends AbstractHafasProvider
|
|||
uri.append("&L=profi");
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if (ucType.equals("SPR"))
|
||||
|
|
|
@ -34,17 +34,15 @@ import de.schildbach.pte.dto.QueryTripsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NvbwProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class NvbwProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://www.efa-bw.de/nvbw/"; // no intermeditate stops
|
||||
private final static String API_BASE_MOBILE = "http://www.efa-bw.de/android/";
|
||||
|
||||
// http://efa2.naldo.de/naldo/
|
||||
|
||||
public NvbwProvider()
|
||||
{
|
||||
super(NetworkId.NVBW, API_BASE + DEFAULT_DEPARTURE_MONITOR_ENDPOINT, API_BASE_MOBILE + DEFAULT_TRIP_ENDPOINT, API_BASE
|
||||
+ DEFAULT_STOPFINDER_ENDPOINT, API_BASE + DEFAULT_COORD_ENDPOINT);
|
||||
public NvbwProvider() {
|
||||
super(NetworkId.NVBW, API_BASE + DEFAULT_DEPARTURE_MONITOR_ENDPOINT, API_BASE_MOBILE + DEFAULT_TRIP_ENDPOINT,
|
||||
API_BASE + DEFAULT_STOPFINDER_ENDPOINT, API_BASE + DEFAULT_COORD_ENDPOINT);
|
||||
|
||||
setIncludeRegionId(false);
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
@ -55,12 +53,10 @@ public class NvbwProvider extends AbstractEfaProvider
|
|||
private static final Pattern P_LINE_S_AVG_VBK = Pattern.compile("(S\\d+) \\((?:AVG|VBK)\\)");
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if (("ICE".equals(trainName) || "InterCityExpress".equals(trainName)) && trainNum == null)
|
||||
return new Line(id, network, Product.HIGH_SPEED_TRAIN, "ICE");
|
||||
if ("InterCity".equals(trainName) && trainNum == null)
|
||||
|
@ -85,11 +81,8 @@ public class NvbwProvider extends AbstractEfaProvider
|
|||
return new Line(id, network, null, "Zug");
|
||||
if ("DB".equals(trainName) && trainNum == null)
|
||||
return new Line(id, network, null, "DB");
|
||||
}
|
||||
else if ("1".equals(mot))
|
||||
{
|
||||
if (symbol != null && symbol.equals(name))
|
||||
{
|
||||
} else if ("1".equals(mot)) {
|
||||
if (symbol != null && symbol.equals(name)) {
|
||||
final Matcher m = P_LINE_S_AVG_VBK.matcher(symbol);
|
||||
if (m.matches())
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, m.group(1));
|
||||
|
@ -100,16 +93,15 @@ public class NvbwProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return queryTripsMobile(from, via, to, date, dep, products, optimize, walkSpeed, accessibility, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException {
|
||||
return queryMoreTripsMobile(contextObj, later);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,13 @@ import de.schildbach.pte.util.StringReplaceReader;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NvvProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class NvvProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "https://auskunft.nvv.de/auskunft/bin/jp/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.BUS, Product.FERRY, Product.ON_DEMAND, Product.REGIONAL_TRAIN,
|
||||
Product.REGIONAL_TRAIN };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.BUS,
|
||||
Product.FERRY, Product.ON_DEMAND, Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN };
|
||||
|
||||
public NvvProvider()
|
||||
{
|
||||
public NvvProvider() {
|
||||
super(NetworkId.NVV, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -48,12 +46,11 @@ public class NvvProvider extends AbstractHafasProvider
|
|||
httpClient.setSslAcceptAllHostnames(true);
|
||||
}
|
||||
|
||||
private static final String[] PLACES = { "Frankfurt (Main)", "Offenbach (Main)", "Mainz", "Wiesbaden", "Marburg", "Kassel", "Hanau", "Göttingen",
|
||||
"Darmstadt", "Aschaffenburg", "Berlin", "Fulda" };
|
||||
private static final String[] PLACES = { "Frankfurt (Main)", "Offenbach (Main)", "Mainz", "Wiesbaden", "Marburg",
|
||||
"Kassel", "Hanau", "Göttingen", "Darmstadt", "Aschaffenburg", "Berlin", "Fulda" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
if (name.startsWith("F "))
|
||||
return new String[] { "Frankfurt", name.substring(2) };
|
||||
if (name.startsWith("OF "))
|
||||
|
@ -61,8 +58,7 @@ public class NvvProvider extends AbstractHafasProvider
|
|||
if (name.startsWith("MZ "))
|
||||
return new String[] { "Mainz", name.substring(3) };
|
||||
|
||||
for (final String place : PLACES)
|
||||
{
|
||||
for (final String place : PLACES) {
|
||||
if (name.startsWith(place + " - "))
|
||||
return new String[] { place, name.substring(place.length() + 3) };
|
||||
else if (name.startsWith(place + " ") || name.startsWith(place + "-"))
|
||||
|
@ -73,8 +69,7 @@ public class NvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -83,31 +78,24 @@ public class NvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.hasLocation())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation()) {
|
||||
return nearbyLocationsByCoordinate(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
else if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
} else if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?L=vs_rmv&near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addCustomReplaces(final StringReplaceReader reader)
|
||||
{
|
||||
protected void addCustomReplaces(final StringReplaceReader reader) {
|
||||
reader.replace("<ul>", " ");
|
||||
reader.replace("</ul>", " ");
|
||||
reader.replace("<li>", " ");
|
||||
|
@ -117,8 +105,7 @@ public class NvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("U-BAHN".equals(ucType))
|
||||
|
|
|
@ -30,54 +30,45 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class OebbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class OebbProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://fahrplan.oebb.at/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM,
|
||||
Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND, Product.HIGH_SPEED_TRAIN };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN,
|
||||
Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND,
|
||||
Product.HIGH_SPEED_TRAIN };
|
||||
|
||||
public OebbProvider()
|
||||
{
|
||||
public OebbProvider() {
|
||||
super(NetworkId.OEBB, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setDominantPlanStopTime(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.hasLocation())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation()) {
|
||||
return nearbyLocationsByCoordinate(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
else if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
} else if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Suchen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
private static final String[] PLACES = { "Wien", "Graz", "Linz/Donau", "Salzburg", "Innsbruck" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
for (final String place : PLACES)
|
||||
if (name.startsWith(place + " "))
|
||||
return new String[] { place, name.substring(place.length() + 1) };
|
||||
|
@ -86,8 +77,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -96,8 +86,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -106,8 +95,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if (ucType.equals("RR")) // Finnland, Connections only?
|
||||
|
|
|
@ -20,27 +20,23 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Stephane Berube
|
||||
*/
|
||||
public class OntarioProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class OntarioProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "ca-on";
|
||||
|
||||
public OntarioProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public OntarioProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.ONTARIO, apiBase, authorization);
|
||||
|
||||
setTimeZone("America/Toronto");
|
||||
}
|
||||
|
||||
public OntarioProvider(final String authorization)
|
||||
{
|
||||
public OntarioProvider(final String authorization) {
|
||||
super(NetworkId.ONTARIO, authorization);
|
||||
|
||||
setTimeZone("America/Toronto");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,18 +22,14 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Kjell Braden <afflux@pentabarf.de>
|
||||
*/
|
||||
public class PacaProvider extends AbstractTsiProvider
|
||||
{
|
||||
public PacaProvider()
|
||||
{
|
||||
public class PacaProvider extends AbstractTsiProvider {
|
||||
public PacaProvider() {
|
||||
super(NetworkId.PACA, "PACA", "http://www.pacamobilite.fr/WebServices/TransinfoService/api");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String translateToLocalProduct(final Product p)
|
||||
{
|
||||
switch (p)
|
||||
{
|
||||
protected String translateToLocalProduct(final Product p) {
|
||||
switch (p) {
|
||||
case HIGH_SPEED_TRAIN:
|
||||
return "RAPID_TRANSIT";
|
||||
case REGIONAL_TRAIN:
|
||||
|
|
|
@ -25,70 +25,56 @@ import de.schildbach.pte.util.WordUtils;
|
|||
/**
|
||||
* @author Antonio El Khoury
|
||||
*/
|
||||
public class ParisProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class ParisProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "fr-idf";
|
||||
|
||||
public ParisProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public ParisProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.PARIS, apiBase, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
public ParisProvider(final String authorization)
|
||||
{
|
||||
public ParisProvider(final String authorization) {
|
||||
super(NetworkId.PARIS, authorization);
|
||||
|
||||
setTimeZone("Europe/Paris");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Style getLineStyle(final Product product, final String code, final String color)
|
||||
{
|
||||
switch (product)
|
||||
{
|
||||
case SUBURBAN_TRAIN:
|
||||
{
|
||||
protected Style getLineStyle(final Product product, final String code, final String color) {
|
||||
switch (product) {
|
||||
case SUBURBAN_TRAIN: {
|
||||
// RER
|
||||
if (code.compareTo("F") < 0)
|
||||
{
|
||||
if (code.compareTo("F") < 0) {
|
||||
return new Style(Shape.CIRCLE, Style.TRANSPARENT, Style.parseColor(color), Style.parseColor(color));
|
||||
}
|
||||
// Transilien
|
||||
else
|
||||
{
|
||||
else {
|
||||
return new Style(Shape.ROUNDED, Style.TRANSPARENT, Style.parseColor(color), Style.parseColor(color));
|
||||
}
|
||||
}
|
||||
case REGIONAL_TRAIN:
|
||||
{
|
||||
case REGIONAL_TRAIN: {
|
||||
// TER + Intercités
|
||||
return new Style(Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case SUBWAY:
|
||||
{
|
||||
case SUBWAY: {
|
||||
// Metro
|
||||
return new Style(Shape.CIRCLE, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case TRAM:
|
||||
{
|
||||
case TRAM: {
|
||||
// Tram
|
||||
return new Style(Shape.RECT, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case BUS:
|
||||
{
|
||||
case BUS: {
|
||||
// Bus + Noctilien
|
||||
return new Style(Shape.RECT, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
case CABLECAR:
|
||||
{
|
||||
case CABLECAR: {
|
||||
// Orlyval
|
||||
return new Style(Shape.ROUNDED, Style.parseColor(color), computeForegroundColor(color));
|
||||
}
|
||||
|
@ -98,8 +84,7 @@ public class ParisProvider extends AbstractNavitiaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String getLocationName(String name)
|
||||
{
|
||||
protected String getLocationName(String name) {
|
||||
return WordUtils.capitalizeFully(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,12 @@ import de.schildbach.pte.util.StringReplaceReader;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class PlProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class PlProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://rozklad.bilkom.pl/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.SUBURBAN_TRAIN, Product.BUS, Product.BUS, Product.FERRY };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.BUS, Product.FERRY };
|
||||
|
||||
public PlProvider()
|
||||
{
|
||||
public PlProvider() {
|
||||
super(NetworkId.PL, API_BASE, "pn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -44,10 +42,8 @@ public class PlProvider extends AbstractHafasProvider
|
|||
private static final String[] PLACES = { "Warszawa", "Kraków" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
for (final String place : PLACES)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
for (final String place : PLACES) {
|
||||
if (name.endsWith(", " + place))
|
||||
return new String[] { place, name.substring(0, name.length() - place.length() - 2) };
|
||||
if (name.startsWith(place + " ") || name.startsWith(place + "-"))
|
||||
|
@ -58,8 +54,7 @@ public class PlProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void addCustomReplaces(final StringReplaceReader reader)
|
||||
{
|
||||
protected void addCustomReplaces(final StringReplaceReader reader) {
|
||||
reader.replace("dir=\"Sp ", " "); // Poland
|
||||
reader.replace("dir=\"B ", " "); // Poland
|
||||
reader.replace("dir=\"K ", " "); // Poland
|
||||
|
@ -69,14 +64,12 @@ public class PlProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("AR".equals(ucType)) // Arriva Polaczen
|
||||
|
|
|
@ -20,27 +20,23 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Stephane Berube
|
||||
*/
|
||||
public class QuebecProvider extends AbstractNavitiaProvider
|
||||
{
|
||||
public class QuebecProvider extends AbstractNavitiaProvider {
|
||||
private static String API_REGION = "ca-qc";
|
||||
|
||||
public QuebecProvider(final String apiBase, final String authorization)
|
||||
{
|
||||
public QuebecProvider(final String apiBase, final String authorization) {
|
||||
super(NetworkId.QUEBEC, apiBase, authorization);
|
||||
|
||||
setTimeZone("America/Montreal");
|
||||
}
|
||||
|
||||
public QuebecProvider(final String authorization)
|
||||
{
|
||||
public QuebecProvider(final String authorization) {
|
||||
super(NetworkId.QUEBEC, authorization);
|
||||
|
||||
setTimeZone("America/Montreal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String region()
|
||||
{
|
||||
public String region() {
|
||||
return API_REGION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,30 +25,27 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class RtProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class RtProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://railteam.hafas.de/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY,
|
||||
Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
|
||||
public RtProvider()
|
||||
{
|
||||
public RtProvider() {
|
||||
super(NetworkId.RT, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
private static final Pattern P_NUMBER = Pattern.compile("\\d{4,5}");
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("N".equals(ucType)) // Frankreich, Tours
|
||||
|
|
|
@ -25,13 +25,11 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class RtaChicagoProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class RtaChicagoProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://tripplanner.rtachicago.com/ccg3/";
|
||||
// "http://elb-jpinstances-1463028547.us-east-1.elb.amazonaws.com/ccg3/";
|
||||
|
||||
public RtaChicagoProvider()
|
||||
{
|
||||
public RtaChicagoProvider() {
|
||||
super(NetworkId.RTACHICAGO, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -39,12 +37,10 @@ public class RtaChicagoProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("UP-N".equals(symbol)) // Union Pacific North Line
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "UP-N");
|
||||
if ("UP-NW".equals(symbol)) // Union Pacific Northwest Line
|
||||
|
|
|
@ -25,28 +25,25 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SbbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class SbbProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://fahrplan.sbb.ch/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.FERRY, Product.SUBURBAN_TRAIN, Product.BUS, Product.CABLECAR, Product.REGIONAL_TRAIN, Product.TRAM };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.FERRY, Product.SUBURBAN_TRAIN, Product.BUS,
|
||||
Product.CABLECAR, Product.REGIONAL_TRAIN, Product.TRAM };
|
||||
|
||||
public SbbProvider()
|
||||
{
|
||||
public SbbProvider() {
|
||||
super(NetworkId.SBB, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -55,8 +52,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -65,8 +61,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -75,8 +70,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("IN".equals(ucType)) // Italien Roma-Lecce
|
||||
|
|
|
@ -29,17 +29,15 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SeProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class SeProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://samtrafiken.hafas.de/bin/";
|
||||
// http://reseplanerare.resrobot.se/bin/
|
||||
// http://api.vasttrafik.se/bin/
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.BUS,
|
||||
Product.REGIONAL_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.FERRY, Product.FERRY, Product.REGIONAL_TRAIN, null, null,
|
||||
null };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.BUS, Product.REGIONAL_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.FERRY, Product.FERRY, Product.REGIONAL_TRAIN, null, null, null };
|
||||
|
||||
public SeProvider()
|
||||
{
|
||||
public SeProvider() {
|
||||
super(NetworkId.SE, API_BASE, "sn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -52,8 +50,7 @@ public class SeProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_SPLIT_NAME_PAREN = Pattern.compile("(.*) \\((.{3,}?) kn\\)");
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher mParen = P_SPLIT_NAME_PAREN.matcher(name);
|
||||
if (mParen.matches())
|
||||
return new String[] { mParen.group(2), mParen.group(1) };
|
||||
|
@ -62,14 +59,12 @@ public class SeProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_LAST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -81,8 +76,7 @@ public class SeProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_NORMALIZE_LINE_SUBWAY = Pattern.compile("Tunnelbana\\s*(.*)");
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String line)
|
||||
{
|
||||
protected Line parseLineAndType(final String line) {
|
||||
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
|
||||
if (mBus.matches())
|
||||
return newLine(Product.BUS, mBus.group(1), null);
|
||||
|
|
|
@ -54,14 +54,12 @@ import de.schildbach.pte.util.ParserUtils;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SeptaProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class SeptaProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://airs1.septa.org/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBWAY, Product.TRAM, Product.BUS, Product.SUBURBAN_TRAIN };
|
||||
private static final long PARSER_DAY_ROLLOVER_THRESHOLD_MS = 12 * 60 * 60 * 1000;
|
||||
|
||||
public SeptaProvider()
|
||||
{
|
||||
public SeptaProvider() {
|
||||
super(NetworkId.SEPTA, API_BASE, "en", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardCanDoEquivs(false);
|
||||
|
@ -69,27 +67,23 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendDateTimeParameters(final StringBuilder uri, final Date time, final String dateParamName, final String timeParamName)
|
||||
{
|
||||
protected void appendDateTimeParameters(final StringBuilder uri, final Date time, final String dateParamName,
|
||||
final String timeParamName) {
|
||||
final Calendar c = new GregorianCalendar(timeZone);
|
||||
c.setTime(time);
|
||||
final int year = c.get(Calendar.YEAR);
|
||||
|
@ -104,9 +98,7 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
uri.append(ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%02d:%02d %s", hour, minute, amPm)));
|
||||
}
|
||||
|
||||
private static final Pattern P_DEPARTURES_PAGE_COARSE = Pattern
|
||||
.compile(
|
||||
".*?" //
|
||||
private static final Pattern P_DEPARTURES_PAGE_COARSE = Pattern.compile(".*?" //
|
||||
+ "(?:" //
|
||||
+ "<div class=\"hfsTitleText\">([^<]*)<.*?" // location
|
||||
+ "\n(\\d{2}/\\d{2}/\\d{4})[^\n]*\n" // date
|
||||
|
@ -115,7 +107,8 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
+ "|(input cannot be interpreted)|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden))" //
|
||||
+ ".*?" //
|
||||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>",
|
||||
Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
||||
+ "<td class=\"time\">(\\d{1,2}:\\d{2} [AP]M)</td>\n" // plannedTime
|
||||
+ "(?:<td class=\"[\\w ]*prognosis[\\w ]*\">\n" //
|
||||
|
@ -131,9 +124,8 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
, Pattern.DOTALL);
|
||||
|
||||
@Override
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
checkNotNull(Strings.emptyToNull(stationId));
|
||||
|
||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
@ -146,16 +138,13 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
|
||||
// parse page
|
||||
final Matcher mPageCoarse = P_DEPARTURES_PAGE_COARSE.matcher(page);
|
||||
if (mPageCoarse.matches())
|
||||
{
|
||||
if (mPageCoarse.matches()) {
|
||||
// messages
|
||||
if (mPageCoarse.group(5) != null)
|
||||
{
|
||||
if (mPageCoarse.group(5) != null) {
|
||||
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId),
|
||||
Collections.<Departure> emptyList(), null));
|
||||
return result;
|
||||
}
|
||||
else if (mPageCoarse.group(6) != null)
|
||||
} else if (mPageCoarse.group(6) != null)
|
||||
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||
else if (mPageCoarse.group(7) != null)
|
||||
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||
|
@ -170,8 +159,7 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
String oldZebra = null;
|
||||
|
||||
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mPageCoarse.group(4));
|
||||
while (mDepCoarse.find())
|
||||
{
|
||||
while (mDepCoarse.find()) {
|
||||
final String zebra = mDepCoarse.group(1);
|
||||
if (oldZebra != null && zebra.equals(oldZebra))
|
||||
throw new IllegalArgumentException("missed row? last:" + zebra);
|
||||
|
@ -179,32 +167,26 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
oldZebra = zebra;
|
||||
|
||||
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(2));
|
||||
if (mDepFine.matches())
|
||||
{
|
||||
if (mDepFine.matches()) {
|
||||
final Calendar plannedTime = new GregorianCalendar(timeZone);
|
||||
plannedTime.setTimeInMillis(currentTime.getTimeInMillis());
|
||||
ParserUtils.parseAmericanTime(plannedTime, mDepFine.group(1));
|
||||
|
||||
if (plannedTime.getTimeInMillis() - currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
if (plannedTime.getTimeInMillis()
|
||||
- currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
plannedTime.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
final Calendar predictedTime;
|
||||
final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
|
||||
if (prognosis != null)
|
||||
{
|
||||
if (prognosis != null) {
|
||||
predictedTime = new GregorianCalendar(timeZone);
|
||||
if (prognosis.equals("pünktlich"))
|
||||
{
|
||||
if (prognosis.equals("pünktlich")) {
|
||||
predictedTime.setTimeInMillis(plannedTime.getTimeInMillis());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
predictedTime.setTimeInMillis(currentTime.getTimeInMillis());
|
||||
ParserUtils.parseAmericanTime(predictedTime, prognosis);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
predictedTime = null;
|
||||
}
|
||||
|
||||
|
@ -215,57 +197,50 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
final String destinationId = mDepFine.group(5);
|
||||
final String destinationName = ParserUtils.resolveEntities(mDepFine.group(6));
|
||||
final Location destination;
|
||||
if (destinationId != null)
|
||||
{
|
||||
if (destinationId != null) {
|
||||
final String[] destinationPlaceAndName = splitStationName(destinationName);
|
||||
destination = new Location(LocationType.STATION, destinationId, destinationPlaceAndName[0], destinationPlaceAndName[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
destination = new Location(LocationType.STATION, destinationId, destinationPlaceAndName[0],
|
||||
destinationPlaceAndName[1]);
|
||||
} else {
|
||||
destination = new Location(LocationType.ANY, null, null, destinationName);
|
||||
}
|
||||
|
||||
final Position position = parsePosition(ParserUtils.resolveEntities(mDepFine.group(7)));
|
||||
|
||||
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line,
|
||||
position, destination, null, null);
|
||||
final Departure dep = new Departure(plannedTime.getTime(),
|
||||
predictedTime != null ? predictedTime.getTime() : null, line, position, destination, null,
|
||||
null);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(2) + "' on " + stationId);
|
||||
}
|
||||
}
|
||||
|
||||
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId, placeAndName[0], placeAndName[1]),
|
||||
departures, null));
|
||||
result.stationDepartures.add(new StationDepartures(
|
||||
new Location(LocationType.STATION, stationId, placeAndName[0], placeAndName[1]), departures, null));
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot parse '" + page + "' on " + stationId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return queryTripsXml(from, via, to, date, dep, products, walkSpeed, accessibility, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
return queryMoreTripsXml(context, later);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_LAST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -274,8 +249,7 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
// Regional
|
||||
|
|
|
@ -30,12 +30,10 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SfProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class SfProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://tripplanner.transit.511.org/mtc/";
|
||||
|
||||
public SfProvider()
|
||||
{
|
||||
public SfProvider() {
|
||||
super(NetworkId.SF, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -46,8 +44,7 @@ public class SfProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String normalizeLocationName(final String name)
|
||||
{
|
||||
protected String normalizeLocationName(final String name) {
|
||||
if (name == null || name.length() == 0)
|
||||
return null;
|
||||
|
||||
|
@ -55,8 +52,7 @@ public class SfProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Position parsePosition(final String position)
|
||||
{
|
||||
protected Position parsePosition(final String position) {
|
||||
if (position == null)
|
||||
return null;
|
||||
|
||||
|
@ -72,15 +68,15 @@ public class SfProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
if (("XAA".equals(symbol) || "Daly City / Fremont".equals(symbol)) && ("DALY/FREMONT".equals(name) || "Daly City / Fremont".equals(name)))
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if (("XAA".equals(symbol) || "Daly City / Fremont".equals(symbol))
|
||||
&& ("DALY/FREMONT".equals(name) || "Daly City / Fremont".equals(name)))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "DALY/FRMT");
|
||||
if (("FRE".equals(symbol) || "Fremont / Daly City".equals(symbol)) && ("FREMONT/DALY".equals(name) || "Fremont / Daly City".equals(name)))
|
||||
if (("FRE".equals(symbol) || "Fremont / Daly City".equals(symbol))
|
||||
&& ("FREMONT/DALY".equals(name) || "Fremont / Daly City".equals(name)))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "FRMT/DALY");
|
||||
if (("XAC".equals(symbol) || "Fremont / Richmond".equals(symbol)) && "Fremont / Richmond".equals(name))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "FRMT/RICH");
|
||||
|
@ -92,9 +88,11 @@ public class SfProvider extends AbstractEfaProvider
|
|||
if (("SFI".equals(symbol) || "SFO / Pittsburg Bay Point".equals(symbol))
|
||||
&& ("SFIA/BAY PT".equals(name) || "SFO / Pittsburg Bay Point".equals(name)))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "SFIA/PITT");
|
||||
if (("XAF".equals(symbol) || "Millbrae / Richmond".equals(symbol)) && ("MILL/RICH".equals(name) || "Millbrae / Richmond".equals(name)))
|
||||
if (("XAF".equals(symbol) || "Millbrae / Richmond".equals(symbol))
|
||||
&& ("MILL/RICH".equals(name) || "Millbrae / Richmond".equals(name)))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "MLBR/RICH");
|
||||
if (("XAG".equals(symbol) || "Richmond / Millbrae".equals(symbol)) && ("RICH/MILL".equals(name) || "Richmond / Millbrae".equals(name)))
|
||||
if (("XAG".equals(symbol) || "Richmond / Millbrae".equals(symbol))
|
||||
&& ("RICH/MILL".equals(name) || "Richmond / Millbrae".equals(name)))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "RICH/MLBR");
|
||||
if (("XAH".equals(symbol) || "Daly City / Dublin Pleasanton".equals(symbol))
|
||||
&& ("DALY/DUBLIN".equals(name) || "Daly City / Dublin Pleasanton".equals(name)))
|
||||
|
@ -140,8 +138,7 @@ public class SfProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// BART
|
||||
STYLES.put("RDALY/FRMT", new Style(Style.parseColor("#4EBF49"), Style.WHITE));
|
||||
STYLES.put("RFRMT/DALY", new Style(Style.parseColor("#4EBF49"), Style.WHITE));
|
||||
|
|
|
@ -45,14 +45,13 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class ShProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class ShProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://nah.sh.hafas.de/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY,
|
||||
Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
|
||||
public ShProvider(final String jsonApiAuthorization)
|
||||
{
|
||||
public ShProvider(final String jsonApiAuthorization) {
|
||||
super(NetworkId.SH, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonApiVersion("1.10");
|
||||
|
@ -66,8 +65,7 @@ public class ShProvider extends AbstractHafasProvider
|
|||
private static final String[] PLACES = { "Hamburg", "Kiel", "Lübeck", "Flensburg", "Neumünster" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
for (final String place : PLACES)
|
||||
if (name.startsWith(place + " ") || name.startsWith(place + "-"))
|
||||
return new String[] { place, name.substring(place.length() + 1) };
|
||||
|
@ -76,8 +74,7 @@ public class ShProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -86,8 +83,7 @@ public class ShProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -96,9 +92,8 @@ public class ShProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation())
|
||||
return jsonLocGeoPos(types, location.lat, location.lon);
|
||||
else
|
||||
|
@ -106,38 +101,34 @@ public class ShProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
return jsonStationBoard(stationId, time, maxDepartures, equivs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return jsonLocMatch(constraint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return jsonTripSearch(from, to, date, dep, products, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
final JsonContext jsonContext = (JsonContext) context;
|
||||
return jsonTripSearch(jsonContext.from, jsonContext.to, jsonContext.date, jsonContext.dep, jsonContext.products,
|
||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Fare parseJsonTripFare(final @Nullable String fareSetName, final @Nullable String fareSetDescription, String name,
|
||||
final Currency currency, final float price)
|
||||
{
|
||||
protected Fare parseJsonTripFare(final @Nullable String fareSetName, final @Nullable String fareSetDescription,
|
||||
String name, final Currency currency, final float price) {
|
||||
if (!"Normalpreis".equals(fareSetDescription) || !name.startsWith("Einzelfahrkarte "))
|
||||
return null;
|
||||
name = name.substring(16);
|
||||
|
@ -151,8 +142,7 @@ public class ShProvider extends AbstractHafasProvider
|
|||
|
||||
protected static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Busse Kiel
|
||||
putKielBusStyle("1", new Style(Style.parseColor("#7288af"), Style.WHITE));
|
||||
putKielBusStyle("2", new Style(Style.parseColor("#50bbb4"), Style.WHITE));
|
||||
|
@ -191,8 +181,7 @@ public class ShProvider extends AbstractHafasProvider
|
|||
putKielBusStyle("512S", new Style(Style.parseColor("#0f3f93"), Style.WHITE));
|
||||
}
|
||||
|
||||
private static void putKielBusStyle(final String name, final Style style)
|
||||
{
|
||||
private static void putKielBusStyle(final String name, final Style style) {
|
||||
STYLES.put("Autokraft Kiel GmbH|B" + name, style);
|
||||
STYLES.put("Kieler Verkehrsgesellschaft mbH|B" + name, style);
|
||||
}
|
||||
|
|
|
@ -32,15 +32,14 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SncbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class SncbProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://www.belgianrail.be/jp/sncb-nmbs-routeplanner/";
|
||||
// http://hari.b-rail.be/hafas/bin/
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, null, Product.HIGH_SPEED_TRAIN, null, null, Product.BUS,
|
||||
Product.REGIONAL_TRAIN, null, Product.SUBWAY, Product.BUS, Product.TRAM, null, null, null, null, null };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, null, Product.HIGH_SPEED_TRAIN, null,
|
||||
null, Product.BUS, Product.REGIONAL_TRAIN, null, Product.SUBWAY, Product.BUS, Product.TRAM, null, null,
|
||||
null, null, null };
|
||||
|
||||
public SncbProvider()
|
||||
{
|
||||
public SncbProvider() {
|
||||
super(NetworkId.SNCB, API_BASE, "nn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -51,8 +50,7 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
private static final String[] PLACES = { "Antwerpen", "Gent", "Charleroi", "Liege", "Liège", "Brussel" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
for (final String place : PLACES)
|
||||
if (name.startsWith(place + " ") || name.startsWith(place + "-"))
|
||||
return new String[] { place, name.substring(place.length() + 1) };
|
||||
|
@ -61,8 +59,7 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -71,37 +68,29 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.hasLocation())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation()) {
|
||||
return nearbyLocationsByCoordinate(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
else if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
} else if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Zoek");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("THALYS".equals(ucType))
|
||||
|
|
|
@ -27,8 +27,7 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class Standard
|
||||
{
|
||||
public class Standard {
|
||||
public static final int COLOR_BACKGROUND_HIGH_SPEED_TRAIN = Style.WHITE;
|
||||
public static final int COLOR_BACKGROUND_REGIONAL_TRAIN = Style.GRAY;
|
||||
public static final int COLOR_BACKGROUND_SUBURBAN_TRAIN = Style.parseColor("#006e34");
|
||||
|
@ -39,9 +38,9 @@ public class Standard
|
|||
|
||||
public static final Map<Product, Style> STYLES = new HashMap<Product, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
STYLES.put(Product.HIGH_SPEED_TRAIN, new Style(Shape.RECT, COLOR_BACKGROUND_HIGH_SPEED_TRAIN, Style.RED, Style.RED));
|
||||
static {
|
||||
STYLES.put(Product.HIGH_SPEED_TRAIN,
|
||||
new Style(Shape.RECT, COLOR_BACKGROUND_HIGH_SPEED_TRAIN, Style.RED, Style.RED));
|
||||
STYLES.put(Product.REGIONAL_TRAIN, new Style(Shape.RECT, COLOR_BACKGROUND_REGIONAL_TRAIN, Style.WHITE));
|
||||
STYLES.put(Product.SUBURBAN_TRAIN, new Style(Shape.CIRCLE, COLOR_BACKGROUND_SUBURBAN_TRAIN, Style.WHITE));
|
||||
STYLES.put(Product.SUBWAY, new Style(Shape.RECT, COLOR_BACKGROUND_SUBWAY, Style.WHITE));
|
||||
|
|
|
@ -25,24 +25,20 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class StvProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class StvProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://fahrplan.verbundlinie.at/stv/";
|
||||
|
||||
public StvProvider()
|
||||
{
|
||||
public StvProvider() {
|
||||
super(NetworkId.STV, API_BASE);
|
||||
|
||||
setIncludeRegionId(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("M".equals(trainType) && trainNum != null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "M" + trainNum);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,10 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SydneyProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class SydneyProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "https://tp.transportnsw.info/nsw/";
|
||||
|
||||
public SydneyProvider()
|
||||
{
|
||||
public SydneyProvider() {
|
||||
super(NetworkId.SYDNEY, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -49,17 +47,15 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
for (final Product p : products)
|
||||
{
|
||||
if (products != null) {
|
||||
for (final Product p : products) {
|
||||
if (p == Product.BUS)
|
||||
uri.append("&inclMOT_11=on"); // school bus
|
||||
}
|
||||
|
@ -75,8 +71,7 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String normalizeLocationName(final String name)
|
||||
{
|
||||
protected String normalizeLocationName(final String name) {
|
||||
if (name == null || name.length() == 0)
|
||||
return null;
|
||||
|
||||
|
@ -84,12 +79,10 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("1".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("1".equals(mot)) {
|
||||
if ("BMT".equals(symbol) || "Blue Mountains Line".equals(symbol))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "BMT");
|
||||
if ("CCN".equals(symbol) || "Central Coast & Newcastle Line".equals(symbol))
|
||||
|
@ -111,9 +104,9 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
if ("NRW".equals(symbol) || (symbol != null && symbol.startsWith("North Western NSW Line")))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "NRW");
|
||||
|
||||
if ("T1".equals(symbol) || "T1 North Shore & Northern Line".equals(symbol) || "T1 North Shore and Northern Line".equals(symbol)
|
||||
|| "T1 Northern Line".equals(symbol) || "T1 Western Line".equals(symbol)
|
||||
|| "T1 North Shore, Northern & Western Line".equals(symbol))
|
||||
if ("T1".equals(symbol) || "T1 North Shore & Northern Line".equals(symbol)
|
||||
|| "T1 North Shore and Northern Line".equals(symbol) || "T1 Northern Line".equals(symbol)
|
||||
|| "T1 Western Line".equals(symbol) || "T1 North Shore, Northern & Western Line".equals(symbol))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "T1");
|
||||
if ("T2".equals(symbol) || "T2 Inner West & South Line".equals(symbol) || "T2 Airport Line".equals(symbol)
|
||||
|| "T2 Airport, Inner West & South Line".equals(symbol))
|
||||
|
@ -129,19 +122,17 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
if ("T7".equals(symbol) || "T7 Olympic Park Line".equals(symbol))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "T7");
|
||||
|
||||
throw new IllegalStateException("cannot normalize mot='" + mot + "' symbol='" + symbol + "' name='" + name + "' long='" + longName
|
||||
+ "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='" + trainName + "'");
|
||||
}
|
||||
else if ("4".equals(mot))
|
||||
{
|
||||
throw new IllegalStateException("cannot normalize mot='" + mot + "' symbol='" + symbol + "' name='" + name
|
||||
+ "' long='" + longName + "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='"
|
||||
+ trainName + "'");
|
||||
} else if ("4".equals(mot)) {
|
||||
if ("L1".equals(symbol) || "L1 Dulwich Hill Line".equals(symbol))
|
||||
return new Line(id, network, Product.TRAM, "L1");
|
||||
|
||||
throw new IllegalStateException("cannot normalize mot='" + mot + "' symbol='" + symbol + "' name='" + name + "' long='" + longName
|
||||
+ "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='" + trainName + "'");
|
||||
}
|
||||
else if ("9".equals(mot))
|
||||
{
|
||||
throw new IllegalStateException("cannot normalize mot='" + mot + "' symbol='" + symbol + "' name='" + name
|
||||
+ "' long='" + longName + "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='"
|
||||
+ trainName + "'");
|
||||
} else if ("9".equals(mot)) {
|
||||
if ("F1".equals(symbol) || "F1 Manly".equals(symbol))
|
||||
return new Line(id, network, Product.FERRY, "F1");
|
||||
if ("F2".equals(symbol) || "F2 Taronga Zoo".equals(symbol))
|
||||
|
@ -156,7 +147,8 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
return new Line(id, network, Product.FERRY, "F6");
|
||||
if ("F7".equals(symbol) || "F7 Eastern Suburbs".equals(symbol))
|
||||
return new Line(id, network, Product.FERRY, "F7");
|
||||
if (("Private ferry servic".equals(trainName) || "Private ferry and fa".equals(trainName)) && symbol != null)
|
||||
if (("Private ferry servic".equals(trainName) || "Private ferry and fa".equals(trainName))
|
||||
&& symbol != null)
|
||||
return new Line(id, network, Product.FERRY, symbol);
|
||||
if ("MFF".equals(symbol) || "Manly Fast Ferry".equals(name))
|
||||
return new Line(id, network, Product.FERRY, "MFF");
|
||||
|
@ -167,8 +159,9 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
if ("Stkn".equals(symbol) || "Stockton Ferry".equals(name))
|
||||
return new Line(id, network, Product.FERRY, "Stkn");
|
||||
|
||||
throw new IllegalStateException("cannot normalize mot='" + mot + "' symbol='" + symbol + "' name='" + name + "' long='" + longName
|
||||
+ "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='" + trainName + "'");
|
||||
throw new IllegalStateException("cannot normalize mot='" + mot + "' symbol='" + symbol + "' name='" + name
|
||||
+ "' long='" + longName + "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='"
|
||||
+ trainName + "'");
|
||||
}
|
||||
|
||||
return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
|
||||
|
@ -176,8 +169,7 @@ public class SydneyProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
STYLES.put("SBMT", new Style(Style.parseColor("#f5a81d"), Style.WHITE));
|
||||
STYLES.put("SCCN", new Style(Style.parseColor("#d11f2f"), Style.WHITE));
|
||||
STYLES.put("SSHL", new Style(Style.parseColor("#843135"), Style.WHITE));
|
||||
|
|
|
@ -27,14 +27,12 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class TfiProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class TfiProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://www.journeyplanner.transportforireland.ie/nta/";
|
||||
|
||||
// http://www.journeyplanner.transportforireland.ie/ultraLite/
|
||||
|
||||
public TfiProvider()
|
||||
{
|
||||
public TfiProvider() {
|
||||
super(NetworkId.TFI, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -42,18 +40,15 @@ public class TfiProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("DART".equals(name))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "DART");
|
||||
if ("Rail".equals(trainName) && trainNum == null)
|
||||
|
|
|
@ -32,8 +32,7 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class TlemProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class TlemProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://www.travelineeastmidlands.co.uk/em/";
|
||||
|
||||
// http://www.travelineeastmidlands.co.uk/em/
|
||||
|
@ -43,8 +42,7 @@ public class TlemProvider extends AbstractEfaProvider
|
|||
// http://www.travelinemidlands.co.uk/wmtis/
|
||||
// http://jp.networkwestmidlands.com/centro/
|
||||
|
||||
public TlemProvider()
|
||||
{
|
||||
public TlemProvider() {
|
||||
super(NetworkId.TLEM, API_BASE);
|
||||
|
||||
setLanguage("en");
|
||||
|
@ -54,8 +52,7 @@ public class TlemProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String normalizeLocationName(final String name)
|
||||
{
|
||||
protected String normalizeLocationName(final String name) {
|
||||
final String normalizedName = super.normalizeLocationName(name);
|
||||
if (normalizedName != null && normalizedName.endsWith(" ()"))
|
||||
return normalizedName.substring(0, normalizedName.length() - 3);
|
||||
|
@ -64,23 +61,18 @@ public class TlemProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("1".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("1".equals(mot)) {
|
||||
if (trainType == null && ("DLR".equals(trainNum) || "Light Railway".equals(trainName)))
|
||||
return new Line(id, network, Product.SUBURBAN_TRAIN, "DLR");
|
||||
}
|
||||
else if ("13".equals(mot))
|
||||
{
|
||||
} else if ("13".equals(mot)) {
|
||||
if ("OO".equals(trainType) || "Ordinary passenger (o.pas.)".equals(trainName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "OO" + Strings.nullToEmpty(trainNum));
|
||||
}
|
||||
|
@ -90,8 +82,7 @@ public class TlemProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// London
|
||||
STYLES.put("UBakerloo", new Style(Style.parseColor("#9D5324"), Style.WHITE));
|
||||
STYLES.put("UCentral", new Style(Style.parseColor("#D52B1E"), Style.WHITE));
|
||||
|
|
|
@ -30,12 +30,10 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VagfrProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VagfrProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "https://efaserver.vag-freiburg.de/vagfr/";
|
||||
|
||||
public VagfrProvider()
|
||||
{
|
||||
public VagfrProvider() {
|
||||
super(NetworkId.VAGFR, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
@ -44,12 +42,10 @@ public class VagfrProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if (("N".equals(trainType) || "Nahverkehrszug".equals(trainName)) && trainNum != null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "N" + trainNum);
|
||||
}
|
||||
|
@ -59,8 +55,7 @@ public class VagfrProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Tram
|
||||
STYLES.put("T1", new Style(Shape.RECT, Style.parseColor("#ed1c24"), Style.WHITE));
|
||||
STYLES.put("T2", new Style(Shape.RECT, Style.parseColor("#33b540"), Style.WHITE));
|
||||
|
|
|
@ -43,15 +43,13 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VaoProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class VaoProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "https://app.verkehrsauskunft.at/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY, null, Product.TRAM,
|
||||
Product.REGIONAL_TRAIN, Product.BUS, Product.BUS, Product.TRAM, Product.FERRY, Product.ON_DEMAND, Product.BUS, Product.REGIONAL_TRAIN,
|
||||
null, null, null };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY,
|
||||
null, Product.TRAM, Product.REGIONAL_TRAIN, Product.BUS, Product.BUS, Product.TRAM, Product.FERRY,
|
||||
Product.ON_DEMAND, Product.BUS, Product.REGIONAL_TRAIN, null, null, null };
|
||||
|
||||
public VaoProvider(final String jsonApiAuthorization)
|
||||
{
|
||||
public VaoProvider(final String jsonApiAuthorization) {
|
||||
super(NetworkId.VAO, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonApiVersion("1.11");
|
||||
|
@ -62,16 +60,14 @@ public class VaoProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
private static final Pattern P_SPLIT_NAME_ONE_COMMA = Pattern.compile("([^,]*), ([^,]{3,64})");
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_ONE_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -80,8 +76,7 @@ public class VaoProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_ONE_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -90,8 +85,7 @@ public class VaoProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -100,9 +94,8 @@ public class VaoProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation())
|
||||
return jsonLocGeoPos(types, location.lat, location.lon);
|
||||
else
|
||||
|
@ -110,29 +103,26 @@ public class VaoProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
return jsonStationBoard(stationId, time, maxDepartures, equivs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return jsonLocMatch(constraint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return jsonTripSearch(from, to, date, dep, products, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
final JsonContext jsonContext = (JsonContext) context;
|
||||
return jsonTripSearch(jsonContext.from, jsonContext.to, jsonContext.date, jsonContext.dep, jsonContext.products,
|
||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||
|
@ -140,8 +130,7 @@ public class VaoProvider extends AbstractHafasProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Salzburg S-Bahn
|
||||
STYLES.put("Salzburg AG|SS1", new Style(Style.parseColor("#b61d33"), Style.WHITE));
|
||||
STYLES.put("Salzburg AG|SS11", new Style(Style.parseColor("#b61d33"), Style.WHITE));
|
||||
|
|
|
@ -30,16 +30,14 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VbbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class VbbProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://fahrinfo.vbb.de/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.FERRY,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.FERRY, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN };
|
||||
private static final Set<Product> ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND = EnumSet
|
||||
.complementOf(EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND));
|
||||
|
||||
public VbbProvider()
|
||||
{
|
||||
public VbbProvider() {
|
||||
super(NetworkId.VBB, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsUseWeight(false);
|
||||
|
@ -52,8 +50,7 @@ public class VbbProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_SPLIT_NAME_BUS = Pattern.compile("(.*?)(\\s+\\[[^\\]]+\\])?");
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(String name)
|
||||
{
|
||||
protected String[] splitStationName(String name) {
|
||||
final Matcher mSu = P_SPLIT_NAME_SU.matcher(name);
|
||||
if (!mSu.matches())
|
||||
throw new IllegalStateException(name);
|
||||
|
@ -76,8 +73,7 @@ public class VbbProvider extends AbstractHafasProvider
|
|||
return super.splitStationName(name);
|
||||
}
|
||||
|
||||
private String normalizePlace(final String place)
|
||||
{
|
||||
private String normalizePlace(final String place) {
|
||||
if ("Bln".equals(place))
|
||||
return "Berlin";
|
||||
else
|
||||
|
@ -85,8 +81,7 @@ public class VbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -95,8 +90,7 @@ public class VbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -105,14 +99,12 @@ public class VbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String lineAndType)
|
||||
{
|
||||
protected Line parseLineAndType(final String lineAndType) {
|
||||
if ("X#".equals(lineAndType))
|
||||
return newLine(Product.HIGH_SPEED_TRAIN, "X", null); // InterConnex
|
||||
else
|
||||
|
|
|
@ -25,24 +25,20 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VblProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VblProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://mobil.vbl.ch/vblmobil/";
|
||||
|
||||
public VblProvider()
|
||||
{
|
||||
public VblProvider() {
|
||||
super(NetworkId.VBL, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("BLS".equals(trainType) && trainNum != null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "BLS" + trainNum);
|
||||
if ("ASM".equals(trainType) && trainNum != null) // Aare Seeland mobil
|
||||
|
|
|
@ -43,18 +43,17 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VbnProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class VbnProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "https://fahrplaner.vbn.de/hafas/";
|
||||
// http://fahrplaner.vsninfo.de/hafas/
|
||||
// http://fahrplan.rsag-online.de/hafas/
|
||||
// http://fahrplanauskunft.verkehrsverbund-warnow.de/bin/
|
||||
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.FERRY,
|
||||
Product.SUBWAY, Product.TRAM, Product.ON_DEMAND };
|
||||
|
||||
public VbnProvider(final String jsonApiAuthorization)
|
||||
{
|
||||
public VbnProvider(final String jsonApiAuthorization) {
|
||||
super(NetworkId.VBN, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonApiVersion("1.10");
|
||||
|
@ -64,13 +63,12 @@ public class VbnProvider extends AbstractHafasProvider
|
|||
setStyles(STYLES);
|
||||
}
|
||||
|
||||
private static final String[] PLACES = { "Bremen", "Bremerhaven", "Oldenburg(Oldb)", "Osnabrück", "Göttingen", "Rostock", "Warnemünde" };
|
||||
private static final String[] PLACES = { "Bremen", "Bremerhaven", "Oldenburg(Oldb)", "Osnabrück", "Göttingen",
|
||||
"Rostock", "Warnemünde" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
for (final String place : PLACES)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
for (final String place : PLACES) {
|
||||
if (name.startsWith(place + " ") || name.startsWith(place + "-"))
|
||||
return new String[] { place, name.substring(place.length() + 1) };
|
||||
}
|
||||
|
@ -79,8 +77,7 @@ public class VbnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -89,15 +86,13 @@ public class VbnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts()
|
||||
{
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation())
|
||||
return jsonLocGeoPos(types, location.lat, location.lon);
|
||||
else
|
||||
|
@ -105,29 +100,26 @@ public class VbnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs)
|
||||
throws IOException
|
||||
{
|
||||
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
|
||||
final int maxDepartures, final boolean equivs) throws IOException {
|
||||
return jsonStationBoard(stationId, time, maxDepartures, equivs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return jsonLocMatch(constraint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep,
|
||||
final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||
return jsonTripSearch(from, to, date, dep, products, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
|
||||
{
|
||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||
final JsonContext jsonContext = (JsonContext) context;
|
||||
return jsonTripSearch(jsonContext.from, jsonContext.to, jsonContext.date, jsonContext.dep, jsonContext.products,
|
||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||
|
@ -135,8 +127,7 @@ public class VbnProvider extends AbstractHafasProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Rostock
|
||||
STYLES.put("DB Regio AG|SS1", new Style(Shape.CIRCLE, Style.parseColor("#009037"), Style.WHITE));
|
||||
STYLES.put("DB Regio AG|SS2", new Style(Shape.CIRCLE, Style.parseColor("#009037"), Style.WHITE));
|
||||
|
|
|
@ -30,23 +30,19 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VgnProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VgnProvider extends AbstractEfaProvider {
|
||||
private static final String DEPARTURE_MONITOR_ENDPOINT = "XML_DM_REQUEST";
|
||||
private static final String TRIP_ENDPOINT = "XML_TRIP_REQUEST2";
|
||||
|
||||
public VgnProvider(final String apiBase)
|
||||
{
|
||||
public VgnProvider(final String apiBase) {
|
||||
super(NetworkId.VGN, apiBase, DEPARTURE_MONITOR_ENDPOINT, TRIP_ENDPOINT, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("R5(z)".equals(trainNum))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "R5(z)");
|
||||
if ("R7(z)".equals(trainNum))
|
||||
|
@ -59,11 +55,11 @@ public class VgnProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date date,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
return super.xsltTripRequestParameters(from, via, to, date, dep, products, optimize, walkSpeed, accessibility, options)
|
||||
+ "&itdLPxx_showTariffLevel=1";
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date date, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
return super.xsltTripRequestParameters(from, via, to, date, dep, products, optimize, walkSpeed, accessibility,
|
||||
options) + "&itdLPxx_showTariffLevel=1";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,23 +29,20 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VgsProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class VgsProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "http://www.saarfahrplan.de/cgi-bin/"; // http://www.vgs-online.de/cgi-bin/
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.CABLECAR, Product.ON_DEMAND,
|
||||
Product.BUS };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM,
|
||||
Product.BUS, Product.CABLECAR, Product.ON_DEMAND, Product.BUS };
|
||||
|
||||
public VgsProvider()
|
||||
{
|
||||
public VgsProvider() {
|
||||
super(NetworkId.VGS, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name)
|
||||
{
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_LAST_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
@ -54,8 +51,7 @@ public class VgsProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -64,8 +60,7 @@ public class VgsProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -74,24 +69,18 @@ public class VgsProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, final int maxDistance,
|
||||
final int maxLocations) throws IOException
|
||||
{
|
||||
if (location.hasLocation())
|
||||
{
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
if (location.hasLocation()) {
|
||||
return nearbyLocationsByCoordinate(types, location.lat, location.lon, maxDistance, maxLocations);
|
||||
}
|
||||
else if (location.type == LocationType.STATION && location.hasId())
|
||||
{
|
||||
} else if (location.type == LocationType.STATION && location.hasId()) {
|
||||
final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
|
||||
uri.append("?near=Anzeigen");
|
||||
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||
uri.append("&input=").append(normalizeStationId(location.id));
|
||||
|
||||
return htmlNearbyStations(uri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,24 +30,22 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VmsProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VmsProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://www.vms.de/vms2/";
|
||||
|
||||
public VmsProvider()
|
||||
{
|
||||
public VmsProvider() {
|
||||
super(NetworkId.VMS, API_BASE);
|
||||
|
||||
setUseLineRestriction(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(
|
||||
super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed, accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
uri.append("&inclMOT_11=on");
|
||||
uri.append("&inclMOT_13=on");
|
||||
|
@ -60,12 +58,10 @@ public class VmsProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("Ilztalbahn".equals(trainName) && trainNum == null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "ITB");
|
||||
if ("Meridian".equals(trainName) && trainNum == null)
|
||||
|
@ -74,7 +70,8 @@ public class VmsProvider extends AbstractEfaProvider
|
|||
return new Line(id, network, Product.REGIONAL_TRAIN, "CB");
|
||||
if ("CityBahn".equals(longName) && "C11".equals(symbol))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, symbol);
|
||||
if ("Zug".equals(longName) && ("C11".equals(symbol) || "C13".equals(symbol) || "C14".equals(symbol) || "C15".equals(symbol)))
|
||||
if ("Zug".equals(longName)
|
||||
&& ("C11".equals(symbol) || "C13".equals(symbol) || "C14".equals(symbol) || "C15".equals(symbol)))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, symbol);
|
||||
|
||||
if ("RE 3".equals(symbol) && "Zug".equals(longName))
|
||||
|
|
|
@ -20,15 +20,13 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VmvProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VmvProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://80.146.180.107/vmv2/";
|
||||
|
||||
// http://80.146.180.107/vmv/
|
||||
// http://80.146.180.107/delfi/
|
||||
|
||||
public VmvProvider()
|
||||
{
|
||||
public VmvProvider() {
|
||||
super(NetworkId.VMV, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
|
|
@ -35,12 +35,10 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VorProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VorProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "https://efa.vor.at/vor/";
|
||||
|
||||
public VorProvider()
|
||||
{
|
||||
public VorProvider() {
|
||||
super(NetworkId.VOR, API_BASE);
|
||||
|
||||
setHttpReferer(API_BASE + DEFAULT_TRIP_ENDPOINT);
|
||||
|
@ -51,17 +49,15 @@ public class VorProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
for (final Product p : products)
|
||||
{
|
||||
if (products != null) {
|
||||
for (final Product p : products) {
|
||||
if (p == Product.BUS)
|
||||
uri.append("&inclMOT_11=on"); // night bus
|
||||
}
|
||||
|
@ -71,17 +67,13 @@ public class VorProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("WLB".equals(trainNum) && trainType == null)
|
||||
return new Line(id, network, Product.TRAM, "WLB");
|
||||
}
|
||||
else if ("1".equals(mot))
|
||||
{
|
||||
} else if ("1".equals(mot)) {
|
||||
if ("LILO".equals(symbol) && "Lokalbahn".equals(trainName))
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "LILO");
|
||||
}
|
||||
|
@ -91,8 +83,7 @@ public class VorProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Wien
|
||||
STYLES.put("SS1", new Style(Style.Shape.ROUNDED, Style.parseColor("#1e5cb3"), Style.WHITE));
|
||||
STYLES.put("SS2", new Style(Style.Shape.ROUNDED, Style.parseColor("#59c594"), Style.WHITE));
|
||||
|
|
|
@ -32,15 +32,13 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VrnProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VrnProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://fahrplanauskunft.vrn.de/vrn/";
|
||||
|
||||
// http://fahrplanauskunft.vrn.de/vrn_mobile/
|
||||
// http://efa9.vrn.de/vrt/
|
||||
|
||||
public VrnProvider()
|
||||
{
|
||||
public VrnProvider() {
|
||||
super(NetworkId.VRN, API_BASE);
|
||||
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
|
@ -48,28 +46,27 @@ public class VrnProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("InterRegio".equals(longName) && symbol == null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, "IR");
|
||||
}
|
||||
|
||||
if (name != null && name.startsWith("RNV Moonliner "))
|
||||
return super.parseLine(id, network, mot, symbol, "M" + name.substring(14), longName, trainType, trainNum, trainName);
|
||||
return super.parseLine(id, network, mot, symbol, "M" + name.substring(14), longName, trainType, trainNum,
|
||||
trainName);
|
||||
else if (name != null && (name.startsWith("RNV ") || name.startsWith("SWK ")))
|
||||
return super.parseLine(id, network, mot, symbol, name.substring(4), longName, trainType, trainNum, trainName);
|
||||
return super.parseLine(id, network, mot, symbol, name.substring(4), longName, trainType, trainNum,
|
||||
trainName);
|
||||
else
|
||||
return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
|
||||
}
|
||||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Straßen- und Stadtbahn Mannheim-Ludwigshafen rnv
|
||||
STYLES.put("T1", new Style(Shape.RECT, Style.parseColor("#f39b9a"), Style.WHITE));
|
||||
STYLES.put("T2", new Style(Shape.RECT, Style.parseColor("#b00346"), Style.WHITE));
|
||||
|
|
|
@ -36,19 +36,16 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VrrProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VrrProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://efa.vrr.de/standard/";
|
||||
|
||||
// http://app.vrr.de/companion-vrr/
|
||||
|
||||
public VrrProvider()
|
||||
{
|
||||
public VrrProvider() {
|
||||
this(API_BASE);
|
||||
}
|
||||
|
||||
public VrrProvider(final String apiBase)
|
||||
{
|
||||
public VrrProvider(final String apiBase) {
|
||||
super(NetworkId.VRR, apiBase);
|
||||
|
||||
setIncludeRegionId(false);
|
||||
|
@ -61,17 +58,15 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
for (final Product p : products)
|
||||
{
|
||||
if (products != null) {
|
||||
for (final Product p : products) {
|
||||
if (p == Product.CABLECAR)
|
||||
uri.append("&inclMOT_11=on"); // Schwebebahn
|
||||
}
|
||||
|
@ -81,12 +76,10 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("Regionalbahn".equals(trainName) && symbol != null)
|
||||
return new Line(id, network, Product.REGIONAL_TRAIN, symbol);
|
||||
if ("NordWestBahn".equals(trainName) && symbol != null)
|
||||
|
@ -94,9 +87,7 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
|
||||
if (trainType == null && "SEV7".equals(trainNum))
|
||||
return new Line(id, network, Product.BUS, trainNum);
|
||||
}
|
||||
else if ("11".equals(mot))
|
||||
{
|
||||
} else if ("11".equals(mot)) {
|
||||
// Wuppertaler Schwebebahn & SkyTrain D'dorf
|
||||
if ("Schwebebahn".equals(trainName) || (longName != null && longName.startsWith("Schwebebahn")))
|
||||
return new Line(id, network, Product.CABLECAR, name);
|
||||
|
@ -111,8 +102,7 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Schnellbusse VRR
|
||||
STYLES.put("vrr|BSB", new Style(Style.parseColor("#00919d"), Style.WHITE));
|
||||
|
||||
|
@ -194,22 +184,22 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
STYLES.put("eva|T106", new Style(Shape.RECT, Style.parseColor("#a695ba"), Style.WHITE));
|
||||
STYLES.put("eva|T108", new Style(Shape.RECT, Style.parseColor("#eca900"), Style.WHITE));
|
||||
STYLES.put("eva|T109", new Style(Shape.RECT, Style.parseColor("#00933a"), Style.WHITE));
|
||||
STYLES.put("eva|BNE1",new Style(Shape.RECT, Style.parseColor("#f7a500"), Style.WHITE));
|
||||
STYLES.put("eva|BNE2",new Style(Shape.RECT, Style.parseColor("#009dcc"), Style.WHITE));
|
||||
STYLES.put("eva|BNE3",new Style(Shape.RECT, Style.parseColor("#534395"), Style.WHITE));
|
||||
STYLES.put("eva|BNE4",new Style(Shape.RECT, Style.parseColor("#f29ec4"), Style.WHITE));
|
||||
STYLES.put("eva|BNE5",new Style(Shape.RECT, Style.parseColor("#00964e"), Style.WHITE));
|
||||
STYLES.put("eva|BNE6",new Style(Shape.RECT, Style.parseColor("#e5007c"), Style.WHITE));
|
||||
STYLES.put("eva|BNE7",new Style(Shape.RECT, Style.parseColor("#6e9ed4"), Style.WHITE));
|
||||
STYLES.put("eva|BNE8",new Style(Shape.RECT, Style.parseColor("#877bb0"), Style.WHITE));
|
||||
STYLES.put("eva|BNE9",new Style(Shape.RECT, Style.parseColor("#ed6da6"), Style.WHITE));
|
||||
STYLES.put("eva|BNE10",new Style(Shape.RECT, Style.parseColor("#ab901c"), Style.WHITE));
|
||||
STYLES.put("eva|BNE11",new Style(Shape.RECT, Style.parseColor("#e3000b"), Style.WHITE));
|
||||
STYLES.put("eva|BNE12",new Style(Shape.RECT, Style.parseColor("#92120a"), Style.WHITE));
|
||||
STYLES.put("eva|BNE13",new Style(Shape.RECT, Style.parseColor("#ffde0c"), Style.BLACK));
|
||||
STYLES.put("eva|BNE14",new Style(Shape.RECT, Style.parseColor("#ee7100"), Style.WHITE));
|
||||
STYLES.put("eva|BNE15",new Style(Shape.RECT, Style.parseColor("#94c11a"), Style.WHITE));
|
||||
STYLES.put("eva|BNE16",new Style(Shape.RECT, Style.parseColor("#004e9e"), Style.WHITE));
|
||||
STYLES.put("eva|BNE1", new Style(Shape.RECT, Style.parseColor("#f7a500"), Style.WHITE));
|
||||
STYLES.put("eva|BNE2", new Style(Shape.RECT, Style.parseColor("#009dcc"), Style.WHITE));
|
||||
STYLES.put("eva|BNE3", new Style(Shape.RECT, Style.parseColor("#534395"), Style.WHITE));
|
||||
STYLES.put("eva|BNE4", new Style(Shape.RECT, Style.parseColor("#f29ec4"), Style.WHITE));
|
||||
STYLES.put("eva|BNE5", new Style(Shape.RECT, Style.parseColor("#00964e"), Style.WHITE));
|
||||
STYLES.put("eva|BNE6", new Style(Shape.RECT, Style.parseColor("#e5007c"), Style.WHITE));
|
||||
STYLES.put("eva|BNE7", new Style(Shape.RECT, Style.parseColor("#6e9ed4"), Style.WHITE));
|
||||
STYLES.put("eva|BNE8", new Style(Shape.RECT, Style.parseColor("#877bb0"), Style.WHITE));
|
||||
STYLES.put("eva|BNE9", new Style(Shape.RECT, Style.parseColor("#ed6da6"), Style.WHITE));
|
||||
STYLES.put("eva|BNE10", new Style(Shape.RECT, Style.parseColor("#ab901c"), Style.WHITE));
|
||||
STYLES.put("eva|BNE11", new Style(Shape.RECT, Style.parseColor("#e3000b"), Style.WHITE));
|
||||
STYLES.put("eva|BNE12", new Style(Shape.RECT, Style.parseColor("#92120a"), Style.WHITE));
|
||||
STYLES.put("eva|BNE13", new Style(Shape.RECT, Style.parseColor("#ffde0c"), Style.BLACK));
|
||||
STYLES.put("eva|BNE14", new Style(Shape.RECT, Style.parseColor("#ee7100"), Style.WHITE));
|
||||
STYLES.put("eva|BNE15", new Style(Shape.RECT, Style.parseColor("#94c11a"), Style.WHITE));
|
||||
STYLES.put("eva|BNE16", new Style(Shape.RECT, Style.parseColor("#004e9e"), Style.WHITE));
|
||||
|
||||
// Duisburg
|
||||
STYLES.put("dvg|B905", new Style(Style.parseColor("#c8242b"), Style.WHITE));
|
||||
|
@ -451,8 +441,8 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Style lineStyle(final @Nullable String network, final @Nullable Product product, final @Nullable String label)
|
||||
{
|
||||
public Style lineStyle(final @Nullable String network, final @Nullable Product product,
|
||||
final @Nullable String label) {
|
||||
if (product == Product.BUS && label != null && label.startsWith("SB"))
|
||||
return super.lineStyle(network, product, "SB");
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -20,12 +20,10 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VvmProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VvmProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://efa.mobilitaetsverbund.de/web/";
|
||||
|
||||
public VvmProvider()
|
||||
{
|
||||
public VvmProvider() {
|
||||
super(NetworkId.VVM, API_BASE);
|
||||
|
||||
setNeedsSpEncId(true);
|
||||
|
|
|
@ -27,29 +27,24 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VvoProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VvoProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://efa.vvo-online.de:8080/dvb/";
|
||||
|
||||
public VvoProvider()
|
||||
{
|
||||
public VvoProvider() {
|
||||
this(API_BASE);
|
||||
}
|
||||
|
||||
public VvoProvider(final String apiBase)
|
||||
{
|
||||
public VvoProvider(final String apiBase) {
|
||||
super(NetworkId.VVO, apiBase);
|
||||
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("Twoje Linie Kolejowe".equals(trainName) && symbol != null)
|
||||
return new Line(id, network, Product.HIGH_SPEED_TRAIN, "TLK" + symbol);
|
||||
|
||||
|
|
|
@ -26,17 +26,14 @@ import de.schildbach.pte.dto.Product;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VvsProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VvsProvider extends AbstractEfaProvider {
|
||||
private static final String API_BASE = "http://www2.vvs.de/vvs/";
|
||||
|
||||
public VvsProvider()
|
||||
{
|
||||
public VvsProvider() {
|
||||
this(API_BASE);
|
||||
}
|
||||
|
||||
public VvsProvider(final String apiBase)
|
||||
{
|
||||
public VvsProvider(final String apiBase) {
|
||||
super(NetworkId.VVS, apiBase);
|
||||
|
||||
setIncludeRegionId(false);
|
||||
|
@ -44,18 +41,15 @@ public class VvsProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Point[] getArea()
|
||||
{
|
||||
public Point[] getArea() {
|
||||
return new Point[] { Point.fromDouble(48.784068, 9.181713) };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot, final @Nullable String symbol,
|
||||
final @Nullable String name, final @Nullable String longName, final @Nullable String trainType, final @Nullable String trainNum,
|
||||
final @Nullable String trainName)
|
||||
{
|
||||
if ("0".equals(mot))
|
||||
{
|
||||
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
|
||||
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
|
||||
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
|
||||
if ("0".equals(mot)) {
|
||||
if ("IC".equals(trainNum))
|
||||
return new Line(id, network, Product.HIGH_SPEED_TRAIN, trainNum);
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@ package de.schildbach.pte;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VvtProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VvtProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://efa.vvt.at/vvtadr/";
|
||||
|
||||
public VvtProvider()
|
||||
{
|
||||
public VvtProvider() {
|
||||
super(NetworkId.VVT, API_BASE);
|
||||
|
||||
setUseRouteIndexAsTripId(false);
|
||||
|
|
|
@ -22,12 +22,10 @@ package de.schildbach.pte;
|
|||
*
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VvvProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class VvvProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://195.30.98.162:8081/vvv2/";
|
||||
|
||||
public VvvProvider()
|
||||
{
|
||||
public VvvProvider() {
|
||||
super(NetworkId.VVV, API_BASE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,10 @@ import de.schildbach.pte.dto.Style;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class WienProvider extends AbstractEfaProvider
|
||||
{
|
||||
public class WienProvider extends AbstractEfaProvider {
|
||||
private final static String API_BASE = "http://www.wienerlinien.at/ogd_routing/";
|
||||
|
||||
public WienProvider()
|
||||
{
|
||||
public WienProvider() {
|
||||
super(NetworkId.WIEN, API_BASE);
|
||||
|
||||
setIncludeRegionId(false);
|
||||
|
@ -48,17 +46,15 @@ public class WienProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to, final Date time,
|
||||
final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products, optimize, walkSpeed,
|
||||
accessibility, options));
|
||||
protected String xsltTripRequestParameters(final Location from, final @Nullable Location via, final Location to,
|
||||
final Date time, final boolean dep, final @Nullable Collection<Product> products,
|
||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) {
|
||||
final StringBuilder uri = new StringBuilder(super.xsltTripRequestParameters(from, via, to, time, dep, products,
|
||||
optimize, walkSpeed, accessibility, options));
|
||||
|
||||
if (products != null)
|
||||
{
|
||||
for (final Product p : products)
|
||||
{
|
||||
if (products != null) {
|
||||
for (final Product p : products) {
|
||||
if (p == Product.BUS)
|
||||
uri.append("&inclMOT_11=on"); // night bus
|
||||
}
|
||||
|
@ -69,8 +65,7 @@ public class WienProvider extends AbstractEfaProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// Wien
|
||||
STYLES.put("SS1", new Style(Style.Shape.ROUNDED, Style.parseColor("#1e5cb3"), Style.WHITE));
|
||||
STYLES.put("SS2", new Style(Style.Shape.ROUNDED, Style.parseColor("#59c594"), Style.WHITE));
|
||||
|
|
|
@ -31,14 +31,13 @@ import de.schildbach.pte.dto.Style.Shape;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class ZvvProvider extends AbstractHafasProvider
|
||||
{
|
||||
public class ZvvProvider extends AbstractHafasProvider {
|
||||
private static final String API_BASE = "https://online.fahrplan.zvv.ch/bin/";
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.FERRY, Product.SUBURBAN_TRAIN, Product.BUS, Product.CABLECAR, Product.SUBWAY, Product.TRAM };
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.FERRY, Product.SUBURBAN_TRAIN, Product.BUS,
|
||||
Product.CABLECAR, Product.SUBWAY, Product.TRAM };
|
||||
|
||||
public ZvvProvider()
|
||||
{
|
||||
public ZvvProvider() {
|
||||
super(NetworkId.ZVV, API_BASE, "dn", PRODUCTS_MAP);
|
||||
|
||||
setJsonGetStopsEncoding(Charsets.UTF_8);
|
||||
|
@ -50,18 +49,14 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
private static final String[] PLACES = { "Zürich", "Winterthur" };
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(String name)
|
||||
{
|
||||
for (final String operator : OPERATORS)
|
||||
{
|
||||
if (name.endsWith(" " + operator))
|
||||
{
|
||||
protected String[] splitStationName(String name) {
|
||||
for (final String operator : OPERATORS) {
|
||||
if (name.endsWith(" " + operator)) {
|
||||
name = name.substring(0, name.length() - operator.length() - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (name.endsWith(" (" + operator + ")"))
|
||||
{
|
||||
if (name.endsWith(" (" + operator + ")")) {
|
||||
name = name.substring(0, name.length() - operator.length() - 3);
|
||||
break;
|
||||
}
|
||||
|
@ -79,8 +74,7 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi)
|
||||
{
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -89,8 +83,7 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address)
|
||||
{
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
@ -99,11 +92,9 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String lineAndType)
|
||||
{
|
||||
protected Line parseLineAndType(final String lineAndType) {
|
||||
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(lineAndType);
|
||||
if (m.matches())
|
||||
{
|
||||
if (m.matches()) {
|
||||
final String number = m.group(1).replaceAll("\\s+", "");
|
||||
final String type = m.group(2);
|
||||
|
||||
|
@ -123,21 +114,20 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
if ("S18".equals(number))
|
||||
return newLine(Product.SUBURBAN_TRAIN, "S18", null);
|
||||
|
||||
if (type.length() > 0)
|
||||
{
|
||||
if (type.length() > 0) {
|
||||
final Product product = normalizeType(type);
|
||||
if (product != null)
|
||||
return newLine(product, number, null);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType);
|
||||
throw new IllegalStateException(
|
||||
"cannot normalize type " + type + " number " + number + " line#type " + lineAndType);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("cannot normalize line#type " + lineAndType);
|
||||
}
|
||||
|
||||
private String stripPrefix(final String str, final String... prefixes)
|
||||
{
|
||||
private String stripPrefix(final String str, final String... prefixes) {
|
||||
for (final String prefix : prefixes)
|
||||
if (str.startsWith(prefix))
|
||||
return str.substring(prefix.length());
|
||||
|
@ -146,8 +136,7 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type)
|
||||
{
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("N".equals(ucType)) // Nachtbus
|
||||
|
@ -174,8 +163,7 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
|
||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// S-Bahn
|
||||
STYLES.put("SS2", new Style(Shape.RECT, Style.parseColor("#70c82c"), Style.WHITE));
|
||||
STYLES.put("SS3", new Style(Shape.RECT, Style.parseColor("#587AC2"), Style.WHITE));
|
||||
|
|
|
@ -35,8 +35,7 @@ import com.google.common.base.Objects;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class Departure implements Serializable
|
||||
{
|
||||
public final class Departure implements Serializable {
|
||||
final public @Nullable Date plannedTime;
|
||||
final public @Nullable Date predictedTime;
|
||||
final public Line line;
|
||||
|
@ -45,9 +44,8 @@ public final class Departure implements Serializable
|
|||
final public @Nullable int[] capacity;
|
||||
final public @Nullable String message;
|
||||
|
||||
public Departure(final Date plannedTime, final Date predictedTime, final Line line, final Position position, final Location destination,
|
||||
final int[] capacity, final String message)
|
||||
{
|
||||
public Departure(final Date plannedTime, final Date predictedTime, final Line line, final Position position,
|
||||
final Location destination, final int[] capacity, final String message) {
|
||||
this.plannedTime = plannedTime;
|
||||
this.predictedTime = predictedTime;
|
||||
checkArgument(plannedTime != null || predictedTime != null);
|
||||
|
@ -58,8 +56,7 @@ public final class Departure implements Serializable
|
|||
this.message = message;
|
||||
}
|
||||
|
||||
public Date getTime()
|
||||
{
|
||||
public Date getTime() {
|
||||
if (predictedTime != null)
|
||||
return predictedTime;
|
||||
else
|
||||
|
@ -67,8 +64,7 @@ public final class Departure implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this);
|
||||
if (plannedTime != null)
|
||||
helper.add("planned", String.format(Locale.US, "%ta %<tR", plannedTime));
|
||||
|
@ -78,8 +74,7 @@ public final class Departure implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Departure))
|
||||
|
@ -97,15 +92,12 @@ public final class Departure implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(plannedTime, predictedTime, line, destination);
|
||||
}
|
||||
|
||||
public static final Comparator<Departure> TIME_COMPARATOR = new Comparator<Departure>()
|
||||
{
|
||||
public int compare(final Departure departure0, final Departure departure1)
|
||||
{
|
||||
public static final Comparator<Departure> TIME_COMPARATOR = new Comparator<Departure>() {
|
||||
public int compare(final Departure departure0, final Departure departure1) {
|
||||
return departure0.getTime().compareTo(departure1.getTime());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -30,10 +30,8 @@ import com.google.common.base.Objects;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Fare implements Serializable
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
public final class Fare implements Serializable {
|
||||
public enum Type {
|
||||
ADULT, CHILD, YOUTH, STUDENT, MILITARY, SENIOR, DISABLED
|
||||
}
|
||||
|
||||
|
@ -46,8 +44,8 @@ public final class Fare implements Serializable
|
|||
public final @Nullable String unitName;
|
||||
public final @Nullable String units;
|
||||
|
||||
public Fare(final String network, final Type type, final Currency currency, final float fare, final String unitName, final String units)
|
||||
{
|
||||
public Fare(final String network, final Type type, final Currency currency, final float fare, final String unitName,
|
||||
final String units) {
|
||||
this.network = checkNotNull(network);
|
||||
this.type = checkNotNull(type);
|
||||
this.currency = checkNotNull(currency);
|
||||
|
@ -57,8 +55,7 @@ public final class Fare implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Fare))
|
||||
|
@ -80,15 +77,13 @@ public final class Fare implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(network, type, currency, fare, unitName, units);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).addValue(network).addValue(type).addValue(currency).addValue(fare).addValue(unitName).addValue(units)
|
||||
.toString();
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).addValue(network).addValue(type).addValue(currency).addValue(fare)
|
||||
.addValue(unitName).addValue(units).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,8 @@ import com.google.common.collect.Ordering;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Line implements Serializable, Comparable<Line>
|
||||
{
|
||||
public enum Attr
|
||||
{
|
||||
public final class Line implements Serializable, Comparable<Line> {
|
||||
public enum Attr {
|
||||
CIRCLE_CLOCKWISE, CIRCLE_ANTICLOCKWISE, SERVICE_REPLACEMENT, LINE_AIRPORT, WHEEL_CHAIR_ACCESS, BICYCLE_CARRIAGE
|
||||
}
|
||||
|
||||
|
@ -53,40 +51,36 @@ public final class Line implements Serializable, Comparable<Line>
|
|||
public static final Line SECURE_CONNECTION = new Line(null, null, null, null);
|
||||
public static final Line DO_NOT_CHANGE = new Line(null, null, null, null);
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label) {
|
||||
this(id, network, product, label, null, null, null, null);
|
||||
}
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style) {
|
||||
this(id, network, product, label, null, style, null, null);
|
||||
}
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label, final String name, final Style style)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label, final String name,
|
||||
final Style style) {
|
||||
this(id, network, product, label, name, style, null, null);
|
||||
}
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style, final String message)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style,
|
||||
final String message) {
|
||||
this(id, network, product, label, null, style, null, message);
|
||||
}
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style, final Set<Attr> attrs)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style,
|
||||
final Set<Attr> attrs) {
|
||||
this(id, network, product, label, null, style, attrs, null);
|
||||
}
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style, final Set<Attr> attrs,
|
||||
final String message)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label, final Style style,
|
||||
final Set<Attr> attrs, final String message) {
|
||||
this(id, network, product, label, null, style, attrs, message);
|
||||
}
|
||||
|
||||
public Line(final String id, final String network, final Product product, final String label, final String name, final Style style,
|
||||
final Set<Attr> attrs, final String message)
|
||||
{
|
||||
public Line(final String id, final String network, final Product product, final String label, final String name,
|
||||
final Style style, final Set<Attr> attrs, final String message) {
|
||||
this.id = id;
|
||||
this.network = network;
|
||||
this.product = product;
|
||||
|
@ -97,21 +91,18 @@ public final class Line implements Serializable, Comparable<Line>
|
|||
this.message = message;
|
||||
}
|
||||
|
||||
public char productCode()
|
||||
{
|
||||
public char productCode() {
|
||||
final Product product = this.product;
|
||||
return product != null ? product.code : Product.UNKNOWN;
|
||||
}
|
||||
|
||||
public boolean hasAttr(final Attr attr)
|
||||
{
|
||||
public boolean hasAttr(final Attr attr) {
|
||||
final Set<Attr> attrs = this.attrs;
|
||||
return attrs != null && attrs.contains(attr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Line))
|
||||
|
@ -127,14 +118,12 @@ public final class Line implements Serializable, Comparable<Line>
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(network, product, label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this) //
|
||||
.addValue(network) //
|
||||
.addValue(product) //
|
||||
|
@ -143,8 +132,7 @@ public final class Line implements Serializable, Comparable<Line>
|
|||
.toString();
|
||||
}
|
||||
|
||||
public int compareTo(final Line other)
|
||||
{
|
||||
public int compareTo(final Line other) {
|
||||
return ComparisonChain.start() //
|
||||
.compare(this.network, other.network, Ordering.natural().nullsLast()) //
|
||||
.compare(this.product, other.product, Ordering.natural().nullsLast()) //
|
||||
|
|
|
@ -30,20 +30,17 @@ import com.google.common.base.Objects;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class LineDestination implements Serializable
|
||||
{
|
||||
public final class LineDestination implements Serializable {
|
||||
final public Line line;
|
||||
final public @Nullable Location destination;
|
||||
|
||||
public LineDestination(final Line line, final Location destination)
|
||||
{
|
||||
public LineDestination(final Line line, final Location destination) {
|
||||
this.line = checkNotNull(line);
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof LineDestination))
|
||||
|
@ -57,14 +54,13 @@ public final class LineDestination implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(line, destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).add("line", line).add("destination", destination).omitNullValues().toString();
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("line", line).add("destination", destination).omitNullValues()
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ import com.google.common.base.Strings;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Location implements Serializable
|
||||
{
|
||||
public final class Location implements Serializable {
|
||||
private static final long serialVersionUID = -2124775933106309127L;
|
||||
|
||||
public final LocationType type;
|
||||
|
@ -45,9 +44,8 @@ public final class Location implements Serializable
|
|||
public final @Nullable String name;
|
||||
public final @Nullable Set<Product> products;
|
||||
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon, final String place, final String name,
|
||||
final Set<Product> products)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon, final String place,
|
||||
final String name, final Set<Product> products) {
|
||||
this.type = checkNotNull(type);
|
||||
this.id = id;
|
||||
this.lat = lat;
|
||||
|
@ -58,85 +56,72 @@ public final class Location implements Serializable
|
|||
|
||||
checkArgument(id == null || id.length() > 0, "ID cannot be the empty string");
|
||||
checkArgument(place == null || name != null, "place '%s' without name cannot exist", place);
|
||||
if (type == LocationType.COORD)
|
||||
{
|
||||
if (type == LocationType.COORD) {
|
||||
checkArgument(hasLocation(), "coordinates missing");
|
||||
checkArgument(place == null && name == null, "coordinates cannot have place or name");
|
||||
}
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon, final String place, final String name)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon, final String place,
|
||||
final String name) {
|
||||
this(type, id, lat, lon, place, name, null);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final Point coord, final String place, final String name, final Set<Product> products)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final Point coord, final String place, final String name,
|
||||
final Set<Product> products) {
|
||||
this(type, id, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0, place, name, products);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final Point coord, final String place, final String name)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final Point coord, final String place,
|
||||
final String name) {
|
||||
this(type, id, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0, place, name);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final String place, final String name)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final String place, final String name) {
|
||||
this(type, id, 0, 0, place, name);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon) {
|
||||
this(type, id, lat, lon, null, null);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final Point coord)
|
||||
{
|
||||
public Location(final LocationType type, final String id, final Point coord) {
|
||||
this(type, id, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id)
|
||||
{
|
||||
public Location(final LocationType type, final String id) {
|
||||
this(type, id, null, null);
|
||||
}
|
||||
|
||||
public static Location coord(final int lat, final int lon)
|
||||
{
|
||||
public static Location coord(final int lat, final int lon) {
|
||||
return new Location(LocationType.COORD, null, lat, lon);
|
||||
}
|
||||
|
||||
public static Location coord(final Point coord)
|
||||
{
|
||||
public static Location coord(final Point coord) {
|
||||
return new Location(LocationType.COORD, null, coord.lat, coord.lon);
|
||||
}
|
||||
|
||||
public final boolean hasId()
|
||||
{
|
||||
public final boolean hasId() {
|
||||
return !Strings.isNullOrEmpty(id);
|
||||
}
|
||||
|
||||
public final boolean hasLocation()
|
||||
{
|
||||
public final boolean hasLocation() {
|
||||
return lat != 0 || lon != 0;
|
||||
}
|
||||
|
||||
public double getLatAsDouble()
|
||||
{
|
||||
public double getLatAsDouble() {
|
||||
return lat / 1E6;
|
||||
}
|
||||
|
||||
public double getLonAsDouble()
|
||||
{
|
||||
public double getLonAsDouble() {
|
||||
return lon / 1E6;
|
||||
}
|
||||
|
||||
public final boolean hasName()
|
||||
{
|
||||
public final boolean hasName() {
|
||||
return name != null;
|
||||
}
|
||||
|
||||
public final boolean isIdentified()
|
||||
{
|
||||
public final boolean isIdentified() {
|
||||
if (type == LocationType.STATION)
|
||||
return hasId();
|
||||
|
||||
|
@ -149,16 +134,14 @@ public final class Location implements Serializable
|
|||
return false;
|
||||
}
|
||||
|
||||
private static final String[] NON_UNIQUE_NAMES = { "Hauptbahnhof", "Hbf", "Bahnhof", "Bf", "Busbahnhof", "ZOB", "Schiffstation", "Schiffst.",
|
||||
"Zentrum", "Dorf", "Kirche", "Nord", "Ost", "Süd", "West" };
|
||||
private static final String[] NON_UNIQUE_NAMES = { "Hauptbahnhof", "Hbf", "Bahnhof", "Bf", "Busbahnhof", "ZOB",
|
||||
"Schiffstation", "Schiffst.", "Zentrum", "Dorf", "Kirche", "Nord", "Ost", "Süd", "West" };
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
Arrays.sort(NON_UNIQUE_NAMES);
|
||||
}
|
||||
|
||||
public final String uniqueShortName()
|
||||
{
|
||||
public final String uniqueShortName() {
|
||||
if (place != null && name != null && Arrays.binarySearch(NON_UNIQUE_NAMES, name) >= 0)
|
||||
return place + ", " + name;
|
||||
else if (name != null)
|
||||
|
@ -170,8 +153,7 @@ public final class Location implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Location))
|
||||
|
@ -193,8 +175,7 @@ public final class Location implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
if (id != null)
|
||||
return Objects.hashCode(type, id);
|
||||
else
|
||||
|
@ -202,8 +183,7 @@ public final class Location implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(type).addValue(id);
|
||||
if (hasLocation())
|
||||
helper.addValue(lat + "/" + lon);
|
||||
|
|
|
@ -20,8 +20,7 @@ package de.schildbach.pte.dto;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public enum LocationType
|
||||
{
|
||||
public enum LocationType {
|
||||
/** Location can represent any of the below. Mainly meant for user input. */
|
||||
ANY,
|
||||
/** Location represents a station or stop. */
|
||||
|
|
|
@ -31,10 +31,8 @@ import com.google.common.base.MoreObjects.ToStringHelper;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class NearbyLocationsResult implements Serializable
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
public final class NearbyLocationsResult implements Serializable {
|
||||
public enum Status {
|
||||
OK, INVALID_ID, SERVICE_DOWN
|
||||
}
|
||||
|
||||
|
@ -42,23 +40,20 @@ public final class NearbyLocationsResult implements Serializable
|
|||
public final Status status;
|
||||
public final List<Location> locations;
|
||||
|
||||
public NearbyLocationsResult(final ResultHeader header, final List<Location> locations)
|
||||
{
|
||||
public NearbyLocationsResult(final ResultHeader header, final List<Location> locations) {
|
||||
this.header = header;
|
||||
this.status = Status.OK;
|
||||
this.locations = checkNotNull(locations);
|
||||
}
|
||||
|
||||
public NearbyLocationsResult(final ResultHeader header, final Status status)
|
||||
{
|
||||
public NearbyLocationsResult(final ResultHeader header, final Status status) {
|
||||
this.header = header;
|
||||
this.status = checkNotNull(status);
|
||||
this.locations = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (locations != null)
|
||||
helper.add("size", locations.size()).add("locations", locations);
|
||||
|
|
|
@ -24,36 +24,30 @@ import com.google.common.base.Objects;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Point implements Serializable
|
||||
{
|
||||
public final class Point implements Serializable {
|
||||
private static final long serialVersionUID = -256077054671402897L;
|
||||
|
||||
public final int lat, lon;
|
||||
|
||||
public Point(final int lat, final int lon)
|
||||
{
|
||||
public Point(final int lat, final int lon) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
}
|
||||
|
||||
public static Point fromDouble(final double lat, final double lon)
|
||||
{
|
||||
public static Point fromDouble(final double lat, final double lon) {
|
||||
return new Point((int) Math.round(lat * 1E6), (int) Math.round(lon * 1E6));
|
||||
}
|
||||
|
||||
public double getLatAsDouble()
|
||||
{
|
||||
public double getLatAsDouble() {
|
||||
return lat / 1E6;
|
||||
}
|
||||
|
||||
public double getLonAsDouble()
|
||||
{
|
||||
public double getLonAsDouble() {
|
||||
return lon / 1E6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Point))
|
||||
|
@ -67,14 +61,12 @@ public final class Point implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(lat, lon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return lat + "/" + lon;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,20 +29,17 @@ import com.google.common.base.Objects;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Position implements Serializable
|
||||
{
|
||||
public final class Position implements Serializable {
|
||||
private static final long serialVersionUID = 5800904192562764917L;
|
||||
|
||||
public final String name;
|
||||
public final @Nullable String section;
|
||||
|
||||
public Position(final String name)
|
||||
{
|
||||
public Position(final String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public Position(final String name, final String section)
|
||||
{
|
||||
public Position(final String name, final String section) {
|
||||
this.name = checkNotNull(name);
|
||||
// checkArgument(name.length() <= 5, "name too long: %s", name);
|
||||
this.section = section;
|
||||
|
@ -50,8 +47,7 @@ public final class Position implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Position))
|
||||
|
@ -65,14 +61,12 @@ public final class Position implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(name, section);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder(name);
|
||||
if (section != null)
|
||||
builder.append(section);
|
||||
|
|
|
@ -23,22 +23,20 @@ import java.util.Set;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public enum Product
|
||||
{
|
||||
HIGH_SPEED_TRAIN('I'), REGIONAL_TRAIN('R'), SUBURBAN_TRAIN('S'), SUBWAY('U'), TRAM('T'), BUS('B'), FERRY('F'), CABLECAR('C'), ON_DEMAND('P');
|
||||
public enum Product {
|
||||
HIGH_SPEED_TRAIN('I'), REGIONAL_TRAIN('R'), SUBURBAN_TRAIN('S'), SUBWAY('U'), TRAM('T'), BUS('B'), FERRY(
|
||||
'F'), CABLECAR('C'), ON_DEMAND('P');
|
||||
|
||||
public static final char UNKNOWN = '?';
|
||||
public static final Set<Product> ALL = EnumSet.allOf(Product.class);
|
||||
|
||||
public final char code;
|
||||
|
||||
private Product(final char code)
|
||||
{
|
||||
private Product(final char code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static Product fromCode(final char code)
|
||||
{
|
||||
public static Product fromCode(final char code) {
|
||||
if (code == HIGH_SPEED_TRAIN.code)
|
||||
return HIGH_SPEED_TRAIN;
|
||||
else if (code == REGIONAL_TRAIN.code)
|
||||
|
@ -61,8 +59,7 @@ public enum Product
|
|||
throw new IllegalArgumentException("unknown code: '" + code + "'");
|
||||
}
|
||||
|
||||
public static Set<Product> fromCodes(final char[] codes)
|
||||
{
|
||||
public static Set<Product> fromCodes(final char[] codes) {
|
||||
if (codes == null)
|
||||
return null;
|
||||
|
||||
|
@ -72,8 +69,7 @@ public enum Product
|
|||
return products;
|
||||
}
|
||||
|
||||
public static char[] toCodes(final Set<Product> products)
|
||||
{
|
||||
public static char[] toCodes(final Set<Product> products) {
|
||||
if (products == null)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -32,10 +32,8 @@ import com.google.common.base.MoreObjects.ToStringHelper;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class QueryDeparturesResult implements Serializable
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
public final class QueryDeparturesResult implements Serializable {
|
||||
public enum Status {
|
||||
OK, INVALID_STATION, SERVICE_DOWN
|
||||
}
|
||||
|
||||
|
@ -43,22 +41,18 @@ public final class QueryDeparturesResult implements Serializable
|
|||
public final Status status;
|
||||
public final List<StationDepartures> stationDepartures = new LinkedList<StationDepartures>();
|
||||
|
||||
public QueryDeparturesResult(final ResultHeader header)
|
||||
{
|
||||
public QueryDeparturesResult(final ResultHeader header) {
|
||||
this.header = header;
|
||||
this.status = Status.OK;
|
||||
}
|
||||
|
||||
public QueryDeparturesResult(final ResultHeader header, final Status status)
|
||||
{
|
||||
public QueryDeparturesResult(final ResultHeader header, final Status status) {
|
||||
this.header = header;
|
||||
this.status = checkNotNull(status);
|
||||
}
|
||||
|
||||
public StationDepartures findStationDepartures(final String stationId)
|
||||
{
|
||||
for (final StationDepartures departures : stationDepartures)
|
||||
{
|
||||
public StationDepartures findStationDepartures(final String stationId) {
|
||||
for (final StationDepartures departures : stationDepartures) {
|
||||
final Location location = departures.location;
|
||||
if (location != null && stationId.equals(location.id))
|
||||
return departures;
|
||||
|
@ -68,8 +62,7 @@ public final class QueryDeparturesResult implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (stationDepartures != null)
|
||||
helper.add("size", stationDepartures.size()).add("stationDepartures", stationDepartures);
|
||||
|
|
|
@ -22,8 +22,7 @@ import java.io.Serializable;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public interface QueryTripsContext extends Serializable
|
||||
{
|
||||
public interface QueryTripsContext extends Serializable {
|
||||
boolean canQueryLater();
|
||||
|
||||
boolean canQueryEarlier();
|
||||
|
|
|
@ -31,10 +31,8 @@ import com.google.common.base.MoreObjects.ToStringHelper;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class QueryTripsResult implements Serializable
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
public final class QueryTripsResult implements Serializable {
|
||||
public enum Status {
|
||||
OK, AMBIGUOUS, TOO_CLOSE, UNKNOWN_FROM, UNKNOWN_VIA, UNKNOWN_TO, UNRESOLVABLE_ADDRESS, NO_TRIPS, INVALID_DATE, SERVICE_DOWN;
|
||||
}
|
||||
|
||||
|
@ -52,9 +50,8 @@ public final class QueryTripsResult implements Serializable
|
|||
public final QueryTripsContext context;
|
||||
public final List<Trip> trips;
|
||||
|
||||
public QueryTripsResult(final ResultHeader header, final String queryUri, final Location from, final Location via, final Location to,
|
||||
final QueryTripsContext context, final List<Trip> trips)
|
||||
{
|
||||
public QueryTripsResult(final ResultHeader header, final String queryUri, final Location from, final Location via,
|
||||
final Location to, final QueryTripsContext context, final List<Trip> trips) {
|
||||
this.header = header;
|
||||
this.status = Status.OK;
|
||||
this.queryUri = queryUri;
|
||||
|
@ -69,9 +66,8 @@ public final class QueryTripsResult implements Serializable
|
|||
this.ambiguousTo = null;
|
||||
}
|
||||
|
||||
public QueryTripsResult(final ResultHeader header, final List<Location> ambiguousFrom, final List<Location> ambiguousVia,
|
||||
final List<Location> ambiguousTo)
|
||||
{
|
||||
public QueryTripsResult(final ResultHeader header, final List<Location> ambiguousFrom,
|
||||
final List<Location> ambiguousVia, final List<Location> ambiguousTo) {
|
||||
this.header = header;
|
||||
this.status = Status.AMBIGUOUS;
|
||||
this.ambiguousFrom = ambiguousFrom;
|
||||
|
@ -86,8 +82,7 @@ public final class QueryTripsResult implements Serializable
|
|||
this.trips = null;
|
||||
}
|
||||
|
||||
public QueryTripsResult(final ResultHeader header, final Status status)
|
||||
{
|
||||
public QueryTripsResult(final ResultHeader header, final Status status) {
|
||||
this.header = header;
|
||||
this.status = checkNotNull(status);
|
||||
|
||||
|
@ -103,16 +98,12 @@ public final class QueryTripsResult implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (status == Status.OK)
|
||||
{
|
||||
if (status == Status.OK) {
|
||||
if (trips != null)
|
||||
helper.add("size", trips.size()).add("trips", trips);
|
||||
}
|
||||
else if (status == Status.AMBIGUOUS)
|
||||
{
|
||||
} else if (status == Status.AMBIGUOUS) {
|
||||
if (ambiguousFrom != null)
|
||||
helper.add("size", ambiguousFrom.size()).add("ambiguousFrom", ambiguousFrom);
|
||||
if (ambiguousVia != null)
|
||||
|
|
|
@ -31,21 +31,19 @@ import de.schildbach.pte.NetworkId;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class ResultHeader implements Serializable
|
||||
{
|
||||
public final class ResultHeader implements Serializable {
|
||||
public final NetworkId network;
|
||||
public final String serverProduct;
|
||||
public final @Nullable String serverVersion;
|
||||
public final long serverTime;
|
||||
public final Object context;
|
||||
|
||||
public ResultHeader(final NetworkId network, final String serverProduct)
|
||||
{
|
||||
public ResultHeader(final NetworkId network, final String serverProduct) {
|
||||
this(network, serverProduct, null, 0, null);
|
||||
}
|
||||
|
||||
public ResultHeader(final NetworkId network, final String serverProduct, final String serverVersion, final long serverTime, final Object context)
|
||||
{
|
||||
public ResultHeader(final NetworkId network, final String serverProduct, final String serverVersion,
|
||||
final long serverTime, final Object context) {
|
||||
this.network = checkNotNull(network);
|
||||
this.serverProduct = checkNotNull(serverProduct);
|
||||
this.serverVersion = serverVersion;
|
||||
|
@ -54,9 +52,8 @@ public final class ResultHeader implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).add("serverProduct", serverProduct).add("serverVersion", serverVersion).add("serverTime", serverTime)
|
||||
.add("context", context).omitNullValues().toString();
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("serverProduct", serverProduct).add("serverVersion", serverVersion)
|
||||
.add("serverTime", serverTime).add("context", context).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,22 +32,20 @@ import com.google.common.base.Objects;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class StationDepartures implements Serializable
|
||||
{
|
||||
public final class StationDepartures implements Serializable {
|
||||
public final Location location;
|
||||
public final List<Departure> departures;
|
||||
public final @Nullable List<LineDestination> lines;
|
||||
|
||||
public StationDepartures(final Location location, final List<Departure> departures, final List<LineDestination> lines)
|
||||
{
|
||||
public StationDepartures(final Location location, final List<Departure> departures,
|
||||
final List<LineDestination> lines) {
|
||||
this.location = checkNotNull(location);
|
||||
this.departures = checkNotNull(departures);
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof StationDepartures))
|
||||
|
@ -63,14 +61,12 @@ public final class StationDepartures implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(location, departures, lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(location);
|
||||
if (departures != null)
|
||||
helper.add("size", departures.size()).add("departures", departures);
|
||||
|
|
|
@ -32,8 +32,7 @@ import com.google.common.base.Objects;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Stop implements Serializable
|
||||
{
|
||||
public final class Stop implements Serializable {
|
||||
private static final long serialVersionUID = 5034616799626145715L;
|
||||
|
||||
public final Location location;
|
||||
|
@ -48,19 +47,20 @@ public final class Stop implements Serializable
|
|||
public final @Nullable Position predictedDeparturePosition;
|
||||
public final boolean departureCancelled;
|
||||
|
||||
public Stop(final Location location, final Date plannedArrivalTime, final Date predictedArrivalTime, final Position plannedArrivalPosition,
|
||||
final Position predictedArrivalPosition, final Date plannedDepartureTime, final Date predictedDepartureTime,
|
||||
final Position plannedDeparturePosition, final Position predictedDeparturePosition)
|
||||
{
|
||||
this(location, plannedArrivalTime, predictedArrivalTime, plannedArrivalPosition, predictedArrivalPosition, false, plannedDepartureTime,
|
||||
predictedDepartureTime, plannedDeparturePosition, predictedDeparturePosition, false);
|
||||
public Stop(final Location location, final Date plannedArrivalTime, final Date predictedArrivalTime,
|
||||
final Position plannedArrivalPosition, final Position predictedArrivalPosition,
|
||||
final Date plannedDepartureTime, final Date predictedDepartureTime, final Position plannedDeparturePosition,
|
||||
final Position predictedDeparturePosition) {
|
||||
this(location, plannedArrivalTime, predictedArrivalTime, plannedArrivalPosition, predictedArrivalPosition,
|
||||
false, plannedDepartureTime, predictedDepartureTime, plannedDeparturePosition,
|
||||
predictedDeparturePosition, false);
|
||||
}
|
||||
|
||||
public Stop(final Location location, final Date plannedArrivalTime, final Date predictedArrivalTime, final Position plannedArrivalPosition,
|
||||
final Position predictedArrivalPosition, final boolean arrivalCancelled, final Date plannedDepartureTime,
|
||||
final Date predictedDepartureTime, final Position plannedDeparturePosition, final Position predictedDeparturePosition,
|
||||
final boolean departureCancelled)
|
||||
{
|
||||
public Stop(final Location location, final Date plannedArrivalTime, final Date predictedArrivalTime,
|
||||
final Position plannedArrivalPosition, final Position predictedArrivalPosition,
|
||||
final boolean arrivalCancelled, final Date plannedDepartureTime, final Date predictedDepartureTime,
|
||||
final Position plannedDeparturePosition, final Position predictedDeparturePosition,
|
||||
final boolean departureCancelled) {
|
||||
this.location = checkNotNull(location);
|
||||
this.plannedArrivalTime = plannedArrivalTime;
|
||||
this.predictedArrivalTime = predictedArrivalTime;
|
||||
|
@ -74,15 +74,13 @@ public final class Stop implements Serializable
|
|||
this.departureCancelled = departureCancelled;
|
||||
}
|
||||
|
||||
public Stop(final Location location, final boolean departure, final Date plannedTime, final Date predictedTime, final Position plannedPosition,
|
||||
final Position predictedPosition)
|
||||
{
|
||||
public Stop(final Location location, final boolean departure, final Date plannedTime, final Date predictedTime,
|
||||
final Position plannedPosition, final Position predictedPosition) {
|
||||
this(location, departure, plannedTime, predictedTime, plannedPosition, predictedPosition, false);
|
||||
}
|
||||
|
||||
public Stop(final Location location, final boolean departure, final Date plannedTime, final Date predictedTime, final Position plannedPosition,
|
||||
final Position predictedPosition, final boolean cancelled)
|
||||
{
|
||||
public Stop(final Location location, final boolean departure, final Date plannedTime, final Date predictedTime,
|
||||
final Position plannedPosition, final Position predictedPosition, final boolean cancelled) {
|
||||
this.location = checkNotNull(location);
|
||||
this.plannedArrivalTime = !departure ? plannedTime : null;
|
||||
this.predictedArrivalTime = !departure ? predictedTime : null;
|
||||
|
@ -96,9 +94,8 @@ public final class Stop implements Serializable
|
|||
this.departureCancelled = departure ? cancelled : false;
|
||||
}
|
||||
|
||||
public Stop(final Location location, final Date plannedArrivalTime, final Position plannedArrivalPosition, final Date plannedDepartureTime,
|
||||
final Position plannedDeparturePosition)
|
||||
{
|
||||
public Stop(final Location location, final Date plannedArrivalTime, final Position plannedArrivalPosition,
|
||||
final Date plannedDepartureTime, final Position plannedDeparturePosition) {
|
||||
this.location = checkNotNull(location);
|
||||
this.plannedArrivalTime = plannedArrivalTime;
|
||||
this.predictedArrivalTime = null;
|
||||
|
@ -112,13 +109,11 @@ public final class Stop implements Serializable
|
|||
this.departureCancelled = false;
|
||||
}
|
||||
|
||||
public Date getArrivalTime()
|
||||
{
|
||||
public Date getArrivalTime() {
|
||||
return getArrivalTime(false);
|
||||
}
|
||||
|
||||
public Date getArrivalTime(final boolean preferPlanTime)
|
||||
{
|
||||
public Date getArrivalTime(final boolean preferPlanTime) {
|
||||
if (preferPlanTime && plannedArrivalTime != null)
|
||||
return plannedArrivalTime;
|
||||
else if (predictedArrivalTime != null)
|
||||
|
@ -129,21 +124,18 @@ public final class Stop implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean isArrivalTimePredicted()
|
||||
{
|
||||
public boolean isArrivalTimePredicted() {
|
||||
return isArrivalTimePredicted(false);
|
||||
}
|
||||
|
||||
public boolean isArrivalTimePredicted(final boolean preferPlanTime)
|
||||
{
|
||||
public boolean isArrivalTimePredicted(final boolean preferPlanTime) {
|
||||
if (preferPlanTime && plannedArrivalTime != null)
|
||||
return false;
|
||||
else
|
||||
return predictedArrivalTime != null;
|
||||
}
|
||||
|
||||
public Long getArrivalDelay()
|
||||
{
|
||||
public Long getArrivalDelay() {
|
||||
final Date plannedArrivalTime = this.plannedArrivalTime;
|
||||
final Date predictedArrivalTime = this.predictedArrivalTime;
|
||||
if (plannedArrivalTime != null && predictedArrivalTime != null)
|
||||
|
@ -152,8 +144,7 @@ public final class Stop implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public Position getArrivalPosition()
|
||||
{
|
||||
public Position getArrivalPosition() {
|
||||
if (predictedArrivalPosition != null)
|
||||
return predictedArrivalPosition;
|
||||
else if (plannedArrivalPosition != null)
|
||||
|
@ -162,18 +153,15 @@ public final class Stop implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean isArrivalPositionPredicted()
|
||||
{
|
||||
public boolean isArrivalPositionPredicted() {
|
||||
return predictedArrivalPosition != null;
|
||||
}
|
||||
|
||||
public Date getDepartureTime()
|
||||
{
|
||||
public Date getDepartureTime() {
|
||||
return getDepartureTime(false);
|
||||
}
|
||||
|
||||
public Date getDepartureTime(final boolean preferPlanTime)
|
||||
{
|
||||
public Date getDepartureTime(final boolean preferPlanTime) {
|
||||
if (preferPlanTime && plannedDepartureTime != null)
|
||||
return plannedDepartureTime;
|
||||
else if (predictedDepartureTime != null)
|
||||
|
@ -184,21 +172,18 @@ public final class Stop implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean isDepartureTimePredicted()
|
||||
{
|
||||
public boolean isDepartureTimePredicted() {
|
||||
return isDepartureTimePredicted(false);
|
||||
}
|
||||
|
||||
public boolean isDepartureTimePredicted(final boolean preferPlanTime)
|
||||
{
|
||||
public boolean isDepartureTimePredicted(final boolean preferPlanTime) {
|
||||
if (preferPlanTime && plannedDepartureTime != null)
|
||||
return false;
|
||||
else
|
||||
return predictedDepartureTime != null;
|
||||
}
|
||||
|
||||
public Long getDepartureDelay()
|
||||
{
|
||||
public Long getDepartureDelay() {
|
||||
final Date plannedDepartureTime = this.plannedDepartureTime;
|
||||
final Date predictedDepartureTime = this.predictedDepartureTime;
|
||||
if (plannedDepartureTime != null && predictedDepartureTime != null)
|
||||
|
@ -207,8 +192,7 @@ public final class Stop implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public Position getDeparturePosition()
|
||||
{
|
||||
public Position getDeparturePosition() {
|
||||
if (predictedDeparturePosition != null)
|
||||
return predictedDeparturePosition;
|
||||
else if (plannedDeparturePosition != null)
|
||||
|
@ -217,32 +201,30 @@ public final class Stop implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean isDeparturePositionPredicted()
|
||||
{
|
||||
public boolean isDeparturePositionPredicted() {
|
||||
return predictedDeparturePosition != null;
|
||||
}
|
||||
|
||||
public Date getMinTime()
|
||||
{
|
||||
public Date getMinTime() {
|
||||
final Date predictedDepartureTime = this.predictedDepartureTime;
|
||||
if (plannedDepartureTime == null || (predictedDepartureTime != null && predictedDepartureTime.before(plannedDepartureTime)))
|
||||
if (plannedDepartureTime == null
|
||||
|| (predictedDepartureTime != null && predictedDepartureTime.before(plannedDepartureTime)))
|
||||
return predictedDepartureTime;
|
||||
else
|
||||
return plannedDepartureTime;
|
||||
}
|
||||
|
||||
public Date getMaxTime()
|
||||
{
|
||||
public Date getMaxTime() {
|
||||
final Date predictedArrivalTime = this.predictedArrivalTime;
|
||||
if (plannedArrivalTime == null || (predictedArrivalTime != null && predictedArrivalTime.after(plannedArrivalTime)))
|
||||
if (plannedArrivalTime == null
|
||||
|| (predictedArrivalTime != null && predictedArrivalTime.after(plannedArrivalTime)))
|
||||
return predictedArrivalTime;
|
||||
else
|
||||
return plannedArrivalTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Stop))
|
||||
|
@ -274,16 +256,14 @@ public final class Stop implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(location, plannedArrivalTime, predictedArrivalTime, plannedArrivalPosition, predictedArrivalPosition,
|
||||
arrivalCancelled, plannedDepartureTime, predictedDepartureTime, plannedDeparturePosition, predictedDeparturePosition,
|
||||
departureCancelled);
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(location, plannedArrivalTime, predictedArrivalTime, plannedArrivalPosition,
|
||||
predictedArrivalPosition, arrivalCancelled, plannedDepartureTime, predictedDepartureTime,
|
||||
plannedDeparturePosition, predictedDeparturePosition, departureCancelled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(location);
|
||||
if (plannedArrivalTime != null)
|
||||
helper.add("plannedArrivalTime", String.format(Locale.US, "%ta %<tR", plannedArrivalTime));
|
||||
|
|
|
@ -25,8 +25,7 @@ import java.io.Serializable;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class Style implements Serializable
|
||||
{
|
||||
public class Style implements Serializable {
|
||||
private static final long serialVersionUID = 7145603493425043304L;
|
||||
|
||||
public final Shape shape;
|
||||
|
@ -34,13 +33,11 @@ public class Style implements Serializable
|
|||
public final int foregroundColor;
|
||||
public final int borderColor;
|
||||
|
||||
public enum Shape
|
||||
{
|
||||
public enum Shape {
|
||||
RECT, ROUNDED, CIRCLE
|
||||
}
|
||||
|
||||
public Style(final int backgroundColor, final int foregroundColor)
|
||||
{
|
||||
public Style(final int backgroundColor, final int foregroundColor) {
|
||||
this.shape = Shape.ROUNDED;
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundColor2 = 0;
|
||||
|
@ -48,8 +45,7 @@ public class Style implements Serializable
|
|||
this.borderColor = 0;
|
||||
}
|
||||
|
||||
public Style(final Shape shape, final int backgroundColor, final int foregroundColor)
|
||||
{
|
||||
public Style(final Shape shape, final int backgroundColor, final int foregroundColor) {
|
||||
this.shape = checkNotNull(shape);
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundColor2 = 0;
|
||||
|
@ -57,8 +53,7 @@ public class Style implements Serializable
|
|||
this.borderColor = 0;
|
||||
}
|
||||
|
||||
public Style(final Shape shape, final int backgroundColor, final int foregroundColor, final int borderColor)
|
||||
{
|
||||
public Style(final Shape shape, final int backgroundColor, final int foregroundColor, final int borderColor) {
|
||||
this.shape = checkNotNull(shape);
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundColor2 = 0;
|
||||
|
@ -66,8 +61,8 @@ public class Style implements Serializable
|
|||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
public Style(final Shape shape, final int backgroundColor, final int backgroundColor2, final int foregroundColor, final int borderColor)
|
||||
{
|
||||
public Style(final Shape shape, final int backgroundColor, final int backgroundColor2, final int foregroundColor,
|
||||
final int borderColor) {
|
||||
this.shape = checkNotNull(shape);
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundColor2 = backgroundColor2;
|
||||
|
@ -75,8 +70,7 @@ public class Style implements Serializable
|
|||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
public Style(final int backgroundColor, final int foregroundColor, final int borderColor)
|
||||
{
|
||||
public Style(final int backgroundColor, final int foregroundColor, final int borderColor) {
|
||||
this.shape = Shape.ROUNDED;
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundColor2 = 0;
|
||||
|
@ -84,8 +78,8 @@ public class Style implements Serializable
|
|||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
public Style(final int backgroundColor, final int backgroundColor2, final int foregroundColor, final int borderColor)
|
||||
{
|
||||
public Style(final int backgroundColor, final int backgroundColor2, final int foregroundColor,
|
||||
final int borderColor) {
|
||||
this.shape = Shape.ROUNDED;
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundColor2 = backgroundColor2;
|
||||
|
@ -93,8 +87,7 @@ public class Style implements Serializable
|
|||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
public final boolean hasBorder()
|
||||
{
|
||||
public final boolean hasBorder() {
|
||||
return borderColor != 0;
|
||||
}
|
||||
|
||||
|
@ -111,52 +104,43 @@ public class Style implements Serializable
|
|||
public static final int MAGENTA = 0xFFFF00FF;
|
||||
public static final int TRANSPARENT = 0;
|
||||
|
||||
public static int parseColor(final String colorStr)
|
||||
{
|
||||
public static int parseColor(final String colorStr) {
|
||||
checkNotNull(colorStr);
|
||||
checkArgument((colorStr.length() == 7 || colorStr.length() == 9) && colorStr.charAt(0) == '#', "Unknown color: %s", colorStr);
|
||||
try
|
||||
{
|
||||
checkArgument((colorStr.length() == 7 || colorStr.length() == 9) && colorStr.charAt(0) == '#',
|
||||
"Unknown color: %s", colorStr);
|
||||
try {
|
||||
// Use a long to avoid rollovers on #ffXXXXXX
|
||||
long color = Long.parseLong(colorStr.substring(1), 16);
|
||||
if (colorStr.length() == 7)
|
||||
color |= 0xff000000; // Amend the alpha value
|
||||
return (int) color;
|
||||
}
|
||||
catch (final NumberFormatException x)
|
||||
{
|
||||
} catch (final NumberFormatException x) {
|
||||
throw new IllegalArgumentException("Not a number: " + colorStr);
|
||||
}
|
||||
}
|
||||
|
||||
public static int rgb(final int red, final int green, final int blue)
|
||||
{
|
||||
public static int rgb(final int red, final int green, final int blue) {
|
||||
return (0xFF << 24) | (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
|
||||
public static int red(final int color)
|
||||
{
|
||||
public static int red(final int color) {
|
||||
return (color >> 16) & 0xff;
|
||||
}
|
||||
|
||||
public static int green(final int color)
|
||||
{
|
||||
public static int green(final int color) {
|
||||
return (color >> 8) & 0xff;
|
||||
}
|
||||
|
||||
public static int blue(final int color)
|
||||
{
|
||||
public static int blue(final int color) {
|
||||
return color & 0xff;
|
||||
}
|
||||
|
||||
public static float perceivedBrightness(final int color)
|
||||
{
|
||||
public static float perceivedBrightness(final int color) {
|
||||
// formula for perceived brightness computation: http://www.w3.org/TR/AERT#color-contrast
|
||||
return (0.299f * Style.red(color) + 0.587f * Style.green(color) + 0.114f * Style.blue(color)) / 256;
|
||||
}
|
||||
|
||||
public static int deriveForegroundColor(final int backgroundColor)
|
||||
{
|
||||
public static int deriveForegroundColor(final int backgroundColor) {
|
||||
// dark colors, white font. Or light colors, black font
|
||||
if (perceivedBrightness(backgroundColor) < 0.5)
|
||||
return WHITE;
|
||||
|
|
|
@ -34,10 +34,8 @@ import com.google.common.base.MoreObjects.ToStringHelper;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class SuggestLocationsResult implements Serializable
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
public final class SuggestLocationsResult implements Serializable {
|
||||
public enum Status {
|
||||
OK, SERVICE_DOWN
|
||||
}
|
||||
|
||||
|
@ -45,23 +43,20 @@ public final class SuggestLocationsResult implements Serializable
|
|||
public final Status status;
|
||||
private final List<SuggestedLocation> suggestedLocations;
|
||||
|
||||
public SuggestLocationsResult(final ResultHeader header, final List<SuggestedLocation> suggestedLocations)
|
||||
{
|
||||
public SuggestLocationsResult(final ResultHeader header, final List<SuggestedLocation> suggestedLocations) {
|
||||
this.header = header;
|
||||
this.status = Status.OK;
|
||||
this.suggestedLocations = new LinkedList<SuggestedLocation>(suggestedLocations);
|
||||
Collections.sort(this.suggestedLocations);
|
||||
}
|
||||
|
||||
public SuggestLocationsResult(final ResultHeader header, final Status status)
|
||||
{
|
||||
public SuggestLocationsResult(final ResultHeader header, final Status status) {
|
||||
this.header = header;
|
||||
this.status = checkNotNull(status);
|
||||
this.suggestedLocations = null;
|
||||
}
|
||||
|
||||
public List<Location> getLocations()
|
||||
{
|
||||
public List<Location> getLocations() {
|
||||
final List<Location> locations = new ArrayList<Location>(suggestedLocations.size());
|
||||
for (final SuggestedLocation location : suggestedLocations)
|
||||
locations.add(location.location);
|
||||
|
@ -70,8 +65,7 @@ public final class SuggestLocationsResult implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(status);
|
||||
if (suggestedLocations != null)
|
||||
helper.add("size", suggestedLocations.size()).add("suggestedLocations", suggestedLocations);
|
||||
|
|
|
@ -27,24 +27,20 @@ import com.google.common.base.Objects;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class SuggestedLocation implements Serializable, Comparable<SuggestedLocation>
|
||||
{
|
||||
public final class SuggestedLocation implements Serializable, Comparable<SuggestedLocation> {
|
||||
public final Location location;
|
||||
public final int priority;
|
||||
|
||||
public SuggestedLocation(final Location location, final int priority)
|
||||
{
|
||||
public SuggestedLocation(final Location location, final int priority) {
|
||||
this.location = checkNotNull(location);
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public SuggestedLocation(final Location location)
|
||||
{
|
||||
public SuggestedLocation(final Location location) {
|
||||
this(location, 0);
|
||||
}
|
||||
|
||||
public int compareTo(final SuggestedLocation other)
|
||||
{
|
||||
public int compareTo(final SuggestedLocation other) {
|
||||
// prefer quality
|
||||
if (this.priority > other.priority)
|
||||
return -1;
|
||||
|
@ -60,8 +56,7 @@ public final class SuggestedLocation implements Serializable, Comparable<Suggest
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof SuggestedLocation))
|
||||
|
@ -71,14 +66,12 @@ public final class SuggestedLocation implements Serializable, Comparable<Suggest
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return priority + ":" + location;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ import com.google.common.base.Objects;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class Trip implements Serializable
|
||||
{
|
||||
public final class Trip implements Serializable {
|
||||
private static final long serialVersionUID = 2508466068307110312L;
|
||||
|
||||
private String id;
|
||||
|
@ -48,9 +47,8 @@ public final class Trip implements Serializable
|
|||
public final int[] capacity;
|
||||
public final Integer numChanges;
|
||||
|
||||
public Trip(final String id, final Location from, final Location to, final List<Leg> legs, final List<Fare> fares, final int[] capacity,
|
||||
final Integer numChanges)
|
||||
{
|
||||
public Trip(final String id, final Location from, final Location to, final List<Leg> legs, final List<Fare> fares,
|
||||
final int[] capacity, final Integer numChanges) {
|
||||
this.id = id;
|
||||
this.from = checkNotNull(from);
|
||||
this.to = checkNotNull(to);
|
||||
|
@ -62,13 +60,11 @@ public final class Trip implements Serializable
|
|||
checkArgument(!legs.isEmpty());
|
||||
}
|
||||
|
||||
public Date getFirstDepartureTime()
|
||||
{
|
||||
public Date getFirstDepartureTime() {
|
||||
return legs.get(0).getDepartureTime();
|
||||
}
|
||||
|
||||
public @Nullable Public getFirstPublicLeg()
|
||||
{
|
||||
public @Nullable Public getFirstPublicLeg() {
|
||||
for (final Leg leg : legs)
|
||||
if (leg instanceof Public)
|
||||
return (Public) leg;
|
||||
|
@ -76,8 +72,7 @@ public final class Trip implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public @Nullable Date getFirstPublicLegDepartureTime()
|
||||
{
|
||||
public @Nullable Date getFirstPublicLegDepartureTime() {
|
||||
final Public firstPublicLeg = getFirstPublicLeg();
|
||||
if (firstPublicLeg != null)
|
||||
return firstPublicLeg.getDepartureTime();
|
||||
|
@ -85,15 +80,12 @@ public final class Trip implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public Date getLastArrivalTime()
|
||||
{
|
||||
public Date getLastArrivalTime() {
|
||||
return legs.get(legs.size() - 1).getArrivalTime();
|
||||
}
|
||||
|
||||
public @Nullable Public getLastPublicLeg()
|
||||
{
|
||||
for (int i = legs.size() - 1; i >= 0; i--)
|
||||
{
|
||||
public @Nullable Public getLastPublicLeg() {
|
||||
for (int i = legs.size() - 1; i >= 0; i--) {
|
||||
final Leg leg = legs.get(i);
|
||||
if (leg instanceof Public)
|
||||
return (Public) leg;
|
||||
|
@ -102,8 +94,7 @@ public final class Trip implements Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public @Nullable Date getLastPublicLegArrivalTime()
|
||||
{
|
||||
public @Nullable Date getLastPublicLegArrivalTime() {
|
||||
final Public lastPublicLeg = getLastPublicLeg();
|
||||
if (lastPublicLeg != null)
|
||||
return lastPublicLeg.getArrivalTime();
|
||||
|
@ -116,21 +107,19 @@ public final class Trip implements Serializable
|
|||
*
|
||||
* @return duration in ms
|
||||
*/
|
||||
public long getDuration()
|
||||
{
|
||||
public long getDuration() {
|
||||
final Date first = getFirstDepartureTime();
|
||||
final Date last = getLastArrivalTime();
|
||||
return last.getTime() - first.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Duration of the public leg part in milliseconds. This includes individual legs between public legs, but excludes
|
||||
* individual legs that lead or trail the trip.
|
||||
* Duration of the public leg part in milliseconds. This includes individual legs between public legs, but
|
||||
* excludes individual legs that lead or trail the trip.
|
||||
*
|
||||
* @return duration in ms, or null if there are no public legs
|
||||
*/
|
||||
public @Nullable Long getPublicDuration()
|
||||
{
|
||||
public @Nullable Long getPublicDuration() {
|
||||
final Date first = getFirstPublicLegDepartureTime();
|
||||
final Date last = getLastPublicLegArrivalTime();
|
||||
if (first != null && last != null)
|
||||
|
@ -140,8 +129,7 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
/** Minimum time occuring in this trip. */
|
||||
public Date getMinTime()
|
||||
{
|
||||
public Date getMinTime() {
|
||||
Date minTime = null;
|
||||
|
||||
for (final Leg leg : legs)
|
||||
|
@ -152,8 +140,7 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
/** Maximum time occuring in this trip. */
|
||||
public Date getMaxTime()
|
||||
{
|
||||
public Date getMaxTime() {
|
||||
Date maxTime = null;
|
||||
|
||||
for (final Leg leg : legs)
|
||||
|
@ -164,12 +151,10 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
/** Returns true if no legs overlap, false otherwise. */
|
||||
public boolean isTravelable()
|
||||
{
|
||||
public boolean isTravelable() {
|
||||
Date time = null;
|
||||
|
||||
for (final Leg leg : legs)
|
||||
{
|
||||
for (final Leg leg : legs) {
|
||||
final Date departureTime = leg.getDepartureTime();
|
||||
if (time != null && departureTime.before(time))
|
||||
return false;
|
||||
|
@ -185,18 +170,15 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
/** If an individual leg overlaps, try to adjust so that it doesn't. */
|
||||
public void adjustUntravelableIndividualLegs()
|
||||
{
|
||||
public void adjustUntravelableIndividualLegs() {
|
||||
final int numLegs = legs.size();
|
||||
if (numLegs < 1)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < numLegs; i++)
|
||||
{
|
||||
for (int i = 1; i < numLegs; i++) {
|
||||
final Trip.Leg leg = legs.get(i);
|
||||
|
||||
if (leg instanceof Trip.Individual)
|
||||
{
|
||||
if (leg instanceof Trip.Individual) {
|
||||
final Trip.Leg previous = legs.get(i - 1);
|
||||
|
||||
if (leg.getDepartureTime().before(previous.getArrivalTime()))
|
||||
|
@ -205,8 +187,7 @@ public final class Trip implements Serializable
|
|||
}
|
||||
}
|
||||
|
||||
public Set<Product> products()
|
||||
{
|
||||
public Set<Product> products() {
|
||||
final Set<Product> products = EnumSet.noneOf(Product.class);
|
||||
|
||||
for (final Leg leg : legs)
|
||||
|
@ -216,29 +197,24 @@ public final class Trip implements Serializable
|
|||
return products;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
public String getId() {
|
||||
if (id == null)
|
||||
id = buildSubstituteId();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
private String buildSubstituteId()
|
||||
{
|
||||
private String buildSubstituteId() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (final Leg leg : legs)
|
||||
{
|
||||
builder.append(leg.departure.hasId() ? leg.departure.id : leg.departure.lat + '/' + leg.departure.lon).append('-');
|
||||
for (final Leg leg : legs) {
|
||||
builder.append(leg.departure.hasId() ? leg.departure.id : leg.departure.lat + '/' + leg.departure.lon)
|
||||
.append('-');
|
||||
builder.append(leg.arrival.hasId() ? leg.arrival.id : leg.arrival.lat + '/' + leg.arrival.lon).append('-');
|
||||
|
||||
if (leg instanceof Individual)
|
||||
{
|
||||
if (leg instanceof Individual) {
|
||||
builder.append(((Individual) leg).min);
|
||||
}
|
||||
else if (leg instanceof Public)
|
||||
{
|
||||
} else if (leg instanceof Public) {
|
||||
final Public publicLeg = (Public) leg;
|
||||
final Date plannedDepartureTime = publicLeg.departureStop.plannedDepartureTime;
|
||||
if (plannedDepartureTime != null)
|
||||
|
@ -260,8 +236,7 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Trip))
|
||||
|
@ -271,33 +246,31 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(getId());
|
||||
final Date firstPublicLegDepartureTime = getFirstPublicLegDepartureTime();
|
||||
final Date lastPublicLegArrivalTime = getLastPublicLegArrivalTime();
|
||||
helper.addValue(firstPublicLegDepartureTime != null ? String.format(Locale.US, "%ta %<tR", firstPublicLegDepartureTime) : "null" + '-'
|
||||
+ lastPublicLegArrivalTime != null ? String.format(Locale.US, "%ta %<tR", lastPublicLegArrivalTime) : "null");
|
||||
helper.addValue(
|
||||
firstPublicLegDepartureTime != null ? String.format(Locale.US, "%ta %<tR", firstPublicLegDepartureTime)
|
||||
: "null" + '-' + lastPublicLegArrivalTime != null
|
||||
? String.format(Locale.US, "%ta %<tR", lastPublicLegArrivalTime) : "null");
|
||||
helper.add("numChanges", numChanges);
|
||||
return helper.toString();
|
||||
}
|
||||
|
||||
public abstract static class Leg implements Serializable
|
||||
{
|
||||
public abstract static class Leg implements Serializable {
|
||||
private static final long serialVersionUID = 8498461220084523265L;
|
||||
|
||||
public final Location departure;
|
||||
public final Location arrival;
|
||||
public List<Point> path;
|
||||
|
||||
public Leg(final Location departure, final Location arrival, final List<Point> path)
|
||||
{
|
||||
public Leg(final Location departure, final Location arrival, final List<Point> path) {
|
||||
this.departure = checkNotNull(departure);
|
||||
this.arrival = checkNotNull(arrival);
|
||||
this.path = path;
|
||||
|
@ -316,8 +289,7 @@ public final class Trip implements Serializable
|
|||
public abstract Date getMaxTime();
|
||||
}
|
||||
|
||||
public final static class Public extends Leg
|
||||
{
|
||||
public final static class Public extends Leg {
|
||||
private static final long serialVersionUID = 1312066446239817422L;
|
||||
|
||||
public final Line line;
|
||||
|
@ -328,8 +300,7 @@ public final class Trip implements Serializable
|
|||
public final @Nullable String message;
|
||||
|
||||
public Public(final Line line, final Location destination, final Stop departureStop, final Stop arrivalStop,
|
||||
final List<Stop> intermediateStops, final List<Point> path, final String message)
|
||||
{
|
||||
final List<Stop> intermediateStops, final List<Point> path, final String message) {
|
||||
super(departureStop.location, arrivalStop.location, path);
|
||||
|
||||
this.line = checkNotNull(line);
|
||||
|
@ -344,91 +315,74 @@ public final class Trip implements Serializable
|
|||
}
|
||||
|
||||
@Override
|
||||
public Date getDepartureTime()
|
||||
{
|
||||
public Date getDepartureTime() {
|
||||
return departureStop.getDepartureTime(false);
|
||||
}
|
||||
|
||||
public Date getDepartureTime(final boolean preferPlanTime)
|
||||
{
|
||||
public Date getDepartureTime(final boolean preferPlanTime) {
|
||||
return departureStop.getDepartureTime(preferPlanTime);
|
||||
}
|
||||
|
||||
public boolean isDepartureTimePredicted()
|
||||
{
|
||||
public boolean isDepartureTimePredicted() {
|
||||
return departureStop.isDepartureTimePredicted(false);
|
||||
}
|
||||
|
||||
public Long getDepartureDelay()
|
||||
{
|
||||
public Long getDepartureDelay() {
|
||||
return departureStop.getDepartureDelay();
|
||||
}
|
||||
|
||||
public Position getDeparturePosition()
|
||||
{
|
||||
public Position getDeparturePosition() {
|
||||
return departureStop.getDeparturePosition();
|
||||
}
|
||||
|
||||
public boolean isDeparturePositionPredicted()
|
||||
{
|
||||
public boolean isDeparturePositionPredicted() {
|
||||
return departureStop.isDeparturePositionPredicted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getArrivalTime()
|
||||
{
|
||||
public Date getArrivalTime() {
|
||||
return arrivalStop.getArrivalTime(false);
|
||||
}
|
||||
|
||||
public Date getArrivalTime(final boolean preferPlanTime)
|
||||
{
|
||||
public Date getArrivalTime(final boolean preferPlanTime) {
|
||||
return arrivalStop.getArrivalTime(preferPlanTime);
|
||||
}
|
||||
|
||||
public boolean isArrivalTimePredicted()
|
||||
{
|
||||
public boolean isArrivalTimePredicted() {
|
||||
return arrivalStop.isArrivalTimePredicted(false);
|
||||
}
|
||||
|
||||
public Long getArrivalDelay()
|
||||
{
|
||||
public Long getArrivalDelay() {
|
||||
return arrivalStop.getArrivalDelay();
|
||||
}
|
||||
|
||||
public Position getArrivalPosition()
|
||||
{
|
||||
public Position getArrivalPosition() {
|
||||
return arrivalStop.getArrivalPosition();
|
||||
}
|
||||
|
||||
public boolean isArrivalPositionPredicted()
|
||||
{
|
||||
public boolean isArrivalPositionPredicted() {
|
||||
return arrivalStop.isArrivalPositionPredicted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getMinTime()
|
||||
{
|
||||
public Date getMinTime() {
|
||||
return departureStop.getMinTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getMaxTime()
|
||||
{
|
||||
public Date getMaxTime() {
|
||||
return arrivalStop.getMaxTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).add("line", line).add("destination", destination).add("departureStop", departureStop)
|
||||
.add("arrivalStop", arrivalStop).omitNullValues().toString();
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("line", line).add("destination", destination)
|
||||
.add("departureStop", departureStop).add("arrivalStop", arrivalStop).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
|
||||
public final static class Individual extends Leg
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
public final static class Individual extends Leg {
|
||||
public enum Type {
|
||||
WALK, BIKE, CAR, TRANSFER
|
||||
}
|
||||
|
||||
|
@ -440,9 +394,8 @@ public final class Trip implements Serializable
|
|||
public final int min;
|
||||
public final int distance;
|
||||
|
||||
public Individual(final Type type, final Location departure, final Date departureTime, final Location arrival, final Date arrivalTime,
|
||||
final List<Point> path, final int distance)
|
||||
{
|
||||
public Individual(final Type type, final Location departure, final Date departureTime, final Location arrival,
|
||||
final Date arrivalTime, final List<Point> path, final int distance) {
|
||||
super(departure, arrival, path);
|
||||
|
||||
this.type = checkNotNull(type);
|
||||
|
@ -452,41 +405,37 @@ public final class Trip implements Serializable
|
|||
this.distance = distance;
|
||||
}
|
||||
|
||||
public Individual movedClone(final Date departureTime)
|
||||
{
|
||||
final Date arrivalTime = new Date(departureTime.getTime() + this.arrivalTime.getTime() - this.departureTime.getTime());
|
||||
return new Trip.Individual(this.type, this.departure, departureTime, this.arrival, arrivalTime, this.path, this.distance);
|
||||
public Individual movedClone(final Date departureTime) {
|
||||
final Date arrivalTime = new Date(
|
||||
departureTime.getTime() + this.arrivalTime.getTime() - this.departureTime.getTime());
|
||||
return new Trip.Individual(this.type, this.departure, departureTime, this.arrival, arrivalTime, this.path,
|
||||
this.distance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDepartureTime()
|
||||
{
|
||||
public Date getDepartureTime() {
|
||||
return departureTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getArrivalTime()
|
||||
{
|
||||
public Date getArrivalTime() {
|
||||
return arrivalTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getMinTime()
|
||||
{
|
||||
public Date getMinTime() {
|
||||
return departureTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getMaxTime()
|
||||
{
|
||||
public Date getMaxTime() {
|
||||
return arrivalTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper(this).addValue(type).add("departure", departure).add("arrival", arrival).add("min", min)
|
||||
.add("distance", distance).omitNullValues().toString();
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).addValue(type).add("departure", departure).add("arrival", arrival)
|
||||
.add("min", min).add("distance", distance).omitNullValues().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,35 +27,29 @@ import de.schildbach.pte.util.HttpClient;
|
|||
* @author Andreas Schildbach
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class AbstractHttpException extends IOException
|
||||
{
|
||||
public abstract class AbstractHttpException extends IOException {
|
||||
private final URL url;
|
||||
private final Reader errorReader;
|
||||
|
||||
public AbstractHttpException(final URL url)
|
||||
{
|
||||
public AbstractHttpException(final URL url) {
|
||||
this(url, null);
|
||||
}
|
||||
|
||||
public AbstractHttpException(final URL url, final Reader errorReader)
|
||||
{
|
||||
public AbstractHttpException(final URL url, final Reader errorReader) {
|
||||
super(url.toString());
|
||||
this.url = url;
|
||||
this.errorReader = errorReader;
|
||||
}
|
||||
|
||||
public URL getUrl()
|
||||
{
|
||||
public URL getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Reader getErrorReader()
|
||||
{
|
||||
public Reader getErrorReader() {
|
||||
return errorReader;
|
||||
}
|
||||
|
||||
public CharSequence scrapeErrorStream() throws IOException
|
||||
{
|
||||
public CharSequence scrapeErrorStream() throws IOException {
|
||||
if (errorReader == null)
|
||||
return null;
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue