Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractHafasProvider: Added the option to also receive trips with ca… #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions enabler/src/de/schildbach/pte/AbstractHafasProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -1499,15 +1499,27 @@ else if (product == Product.SUBURBAN_TRAIN && name.startsWith("S "))
}

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 @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException
{
return queryTripsBinary(from, via, to, date, dep, products, walkSpeed, accessibility, options);
return queryTripsBinary(from, via, to, date, dep, products, walkSpeed, accessibility, options, false);
}

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, boolean includeTripsWithCancelledLegs) throws IOException
{
return queryTripsBinary(from, via, to, date, dep, products, walkSpeed, accessibility, options, includeTripsWithCancelledLegs);
}

public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException
{
return queryMoreTripsBinary(context, later);
return queryMoreTripsBinary(context, later, false);
}

public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later, boolean includeTripsWithCancelledLegs) throws IOException
{
return queryMoreTripsBinary(context, later, includeTripsWithCancelledLegs);
}

protected final QueryTripsResult queryTripsXml(Location from, @Nullable Location via, Location to, final Date date, final boolean dep,
Expand Down Expand Up @@ -2169,7 +2181,7 @@ protected void appendCommonQueryTripsBinaryParameters(final StringBuilder uri)

protected final QueryTripsResult queryTripsBinary(Location from, @Nullable Location via, Location to, final Date date, final boolean dep,
final @Nullable Set<Product> products, final @Nullable WalkSpeed walkSpeed, final @Nullable Accessibility accessibility,
final @Nullable Set<Option> options) throws IOException
final @Nullable Set<Option> options, boolean includeTripsWithCancelledLegs) throws IOException
{
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);

Expand Down Expand Up @@ -2206,7 +2218,7 @@ protected final QueryTripsResult queryTripsBinary(Location from, @Nullable Locat
final StringBuilder uri = new StringBuilder(queryEndpoint);
appendQueryTripsBinaryParameters(uri, from, via, to, date, dep, products, accessibility, options);

return queryTripsBinary(uri.toString(), from, via, to, QUERY_TRIPS_BINARY_BUFFER_SIZE);
return queryTripsBinary(uri.toString(), from, via, to, QUERY_TRIPS_BINARY_BUFFER_SIZE, includeTripsWithCancelledLegs);
}

protected void appendQueryMoreTripsBinaryParameters(final StringBuilder uri, final QueryTripsBinaryContext context, final boolean later)
Expand All @@ -2220,14 +2232,14 @@ protected void appendQueryMoreTripsBinaryParameters(final StringBuilder uri, fin
appendCommonQueryTripsBinaryParameters(uri);
}

protected QueryTripsResult queryMoreTripsBinary(final QueryTripsContext contextObj, final boolean later) throws IOException
protected QueryTripsResult queryMoreTripsBinary(final QueryTripsContext contextObj, final boolean later, boolean includeTripsWithCancelledLegs) throws IOException
{
final QueryTripsBinaryContext context = (QueryTripsBinaryContext) contextObj;

final StringBuilder uri = new StringBuilder(queryEndpoint);
appendQueryMoreTripsBinaryParameters(uri, context, later);

return queryTripsBinary(uri.toString(), null, null, null, QUERY_TRIPS_BINARY_BUFFER_SIZE + context.usedBufferSize);
return queryTripsBinary(uri.toString(), null, null, null, QUERY_TRIPS_BINARY_BUFFER_SIZE + context.usedBufferSize, includeTripsWithCancelledLegs);
}

private class CustomBufferedInputStream extends BufferedInputStream
Expand All @@ -2244,7 +2256,7 @@ public int getCount()
}

private QueryTripsResult queryTripsBinary(final String uri, final Location from, final @Nullable Location via, final Location to,
final int expectedBufferSize) throws IOException
final int expectedBufferSize, boolean includeTripsWithCancelledLegs) throws IOException
{
/*
* Many thanks to Malte Starostik and Robert, who helped a lot with analyzing this API!
Expand Down Expand Up @@ -2736,7 +2748,7 @@ else if (lineClass != 0)

final Trip trip = new Trip(connectionId, resDeparture, resArrival, legs, null, null, (int) numChanges);

if (realtimeStatus != 2) // Verbindung fällt aus
if (realtimeStatus != 2 || includeTripsWithCancelledLegs) // Verbindung fällt aus
trips.add(trip);
}

Expand Down