Switch to Java 7.

Notes regarding Android compatibility:
- The 'try-with-resources' language feature needs API level 19, so don't use it.
  All other language features can be used back to API level 8.
- The JDK 1.7 API still isn't fully implemented, so better stick with 1.6 for now.
This commit is contained in:
Andreas Schildbach 2016-09-20 23:14:33 +02:00
parent 1c2f21ac9f
commit 4c64746e75
15 changed files with 66 additions and 5 deletions

View file

@ -1,4 +1,4 @@
# configuration for https://travis-ci.org/schildbach/public-transport-enabler
sudo: false
language: java
jdk: openjdk6
jdk: openjdk7

View file

@ -23,8 +23,8 @@ sourceSets {
}
compileJava {
sourceCompatibility '1.5'
targetCompatibility '1.5'
sourceCompatibility '1.7'
targetCompatibility '1.7'
}
test {

View file

@ -125,10 +125,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
this.context = context;
}
@Override
public boolean canQueryLater() {
return context != null;
}
@Override
public boolean canQueryEarlier() {
return false; // TODO enable earlier querying
}
@ -373,6 +375,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
XmlPullUtil.enter(pp, "itdStopFinderRequest");
processItdOdv(pp, "sf", new ProcessItdOdvCallback() {
@Override
public void location(final String nameState, final Location location, final int matchQuality) {
locations.add(new SuggestedLocation(location, matchQuality));
}
@ -649,6 +652,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
}
}
@Override
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
return jsonStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()));
}
@ -824,6 +828,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
return null;
}
@Override
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
final int maxDistance, final int maxLocations) throws IOException {
if (location.hasLocation())
@ -873,6 +878,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
final List<Location> stations = new ArrayList<Location>();
final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback() {
@Override
public void location(final String nameState, final Location location, final int matchQuality) {
if (location.type == LocationType.STATION) {
if ("identified".equals(nameState))
@ -1391,6 +1397,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
+ "' trainType='" + trainType + "' trainNum='" + trainNum + "' trainName='" + trainName + "'");
}
@Override
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
final int maxDepartures, final boolean equivs) throws IOException {
checkNotNull(Strings.emptyToNull(stationId));
@ -1458,6 +1465,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
XmlPullUtil.optSkip(pp, "itdMessage");
final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback() {
@Override
public void location(final String nameState, final Location location, final int matchQuality) {
if (location.type == LocationType.STATION)
if (findStationDepartures(result.stationDepartures, location.id) == null)
@ -2016,6 +2024,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
uri.append("&coordListOutputFormat=STRING");
}
@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,
@ -2076,6 +2085,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
}
}
@Override
public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException {
final Context context = (Context) contextObj;
final String commandUri = context.context;
@ -2156,6 +2166,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
final List<Location> locations = new ArrayList<Location>();
final String nameState = processItdOdv(pp, usage, new ProcessItdOdvCallback() {
@Override
public void location(final String nameState, final Location location, final int matchQuality) {
locations.add(location);
}

View file

@ -132,10 +132,12 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
this.sequence = sequence;
}
@Override
public boolean canQueryLater() {
return laterContext != null;
}
@Override
public boolean canQueryEarlier() {
return earlierContext != null;
}
@ -160,10 +162,12 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
this.earlierContext = earlierContext;
}
@Override
public boolean canQueryLater() {
return laterContext != null;
}
@Override
public boolean canQueryEarlier() {
return earlierContext != null;
}
@ -186,10 +190,12 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
this.canQueryMore = canQueryMore;
}
@Override
public boolean canQueryLater() {
return canQueryMore;
}
@Override
public boolean canQueryEarlier() {
return canQueryMore;
}
@ -418,6 +424,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
return parsePosition(platformText);
}
@Override
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
final StringBuilder uri = new StringBuilder(getStopEndpoint);
appendJsonGetStopsParameters(uri, checkNotNull(constraint), 0);
@ -510,6 +517,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
}
}
@Override
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
final int maxDepartures, final boolean equivs) throws IOException {
checkNotNull(Strings.emptyToNull(stationId));
@ -1352,6 +1360,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
return lines;
}
@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,
@ -1359,6 +1368,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
return queryTripsBinary(from, via, to, date, dep, products, walkSpeed, accessibility, options);
}
@Override
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
return queryMoreTripsBinary(context, later);
}
@ -2785,6 +2795,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
return parsePosition(m.group(1));
}
@Override
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
final int maxDistance, final int maxLocations) throws IOException {
if (location.hasLocation())

View file

@ -107,10 +107,12 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
this.nextQueryUri = nextQueryUri;
}
@Override
public boolean canQueryLater() {
return (from != null && to != null && nextQueryUri != null);
}
@Override
public boolean canQueryEarlier() {
return (from != null && to != null && prevQueryUri != null);
}
@ -661,6 +663,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
return false;
}
@Override
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
int maxDistance, final int maxLocations) throws IOException {
final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, 0, null);
@ -729,6 +732,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
}
}
@Override
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
final int maxDepartures, final boolean equivs) throws IOException {
checkNotNull(Strings.emptyToNull(stationId));
@ -831,6 +835,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
}
}
@Override
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
final String nameCstr = constraint.toString();
@ -863,6 +868,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
}
}
@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,
@ -1032,6 +1038,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
}
}
@Override
public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException {
final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, 0, null);

View file

@ -53,10 +53,12 @@ public abstract class AbstractNetworkProvider implements NetworkProvider {
this.network = network;
}
@Override
public final NetworkId id() {
return network;
}
@Override
public final boolean hasCapabilities(final Capability... capabilities) {
for (final Capability capability : capabilities)
if (!hasCapability(capability))
@ -67,6 +69,7 @@ public abstract class AbstractNetworkProvider implements NetworkProvider {
protected abstract boolean hasCapability(Capability capability);
@Override
public Set<Product> defaultProducts() {
return ALL_EXCEPT_HIGHSPEED;
}
@ -93,6 +96,7 @@ public abstract class AbstractNetworkProvider implements NetworkProvider {
private static final char STYLES_SEP = '|';
@Override
public Style lineStyle(final @Nullable String network, final @Nullable Product product,
final @Nullable String label) {
final Map<String, Style> styles = this.styles;
@ -139,6 +143,7 @@ public abstract class AbstractNetworkProvider implements NetworkProvider {
return Standard.STYLES.get(product);
}
@Override
public Point[] getArea() throws IOException {
return null;
}

View file

@ -84,10 +84,12 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider {
this.walkSpeed = walkSpeed;
}
@Override
public boolean canQueryEarlier() {
return true;
}
@Override
public boolean canQueryLater() {
return true;
}
@ -186,6 +188,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider {
return true;
}
@Override
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
final StringBuilder parameters = buildCommonRequestParams("SearchTripPoint", "json");
parameters.append("&MaxItems=").append(50); // XXX good value?
@ -541,15 +544,18 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider {
return new Location(locType, id, Point.fromDouble(lat, lon), place, name);
}
@Override
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
final int maxDepartures, final boolean equivs) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
return ((Context) context).queryMore(this, later);
}
@Override
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
final int maxDistance, final int maxLocations) throws IOException {
Location queryLocation = location;
@ -565,6 +571,7 @@ public abstract class AbstractTsiProvider extends AbstractNetworkProvider {
return jsonCoordRequest(location.lat, location.lon, maxDistance, maxLocations);
}
@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,

View file

@ -170,6 +170,7 @@ 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.
@Override
public NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance,
int maxStations) throws IOException {
final StringBuilder uri = apiUri("stops_area");
@ -252,6 +253,7 @@ public class HslProvider extends AbstractNetworkProvider {
}
// Get departures at a given station, probably live
@Override
public QueryDeparturesResult queryDepartures(String stationId, @Nullable Date queryDate, int maxDepartures,
boolean equivs) throws IOException {
final StringBuilder uri = apiUri("stop");
@ -334,6 +336,7 @@ public class HslProvider extends AbstractNetworkProvider {
* @return location suggestions
* @throws IOException
*/
@Override
public SuggestLocationsResult suggestLocations(CharSequence constraint) throws IOException {
final StringBuilder uri = apiUri("geocode");
@ -424,10 +427,12 @@ public class HslProvider extends AbstractNetworkProvider {
this.trips = new ArrayList<Trip>();
}
@Override
public boolean canQueryLater() {
return true;
}
@Override
public boolean canQueryEarlier() {
return true;
}
@ -435,6 +440,7 @@ public class HslProvider extends AbstractNetworkProvider {
// Query trips, asking for any ambiguousnesses
// NOTE: HSL ignores accessibility
@Override
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 {
@ -513,6 +519,7 @@ public class HslProvider extends AbstractNetworkProvider {
* @return result object that contains possible trips
* @throws IOException
*/
@Override
public QueryTripsResult queryMoreTrips(QueryTripsContext contextObj, boolean later) throws IOException {
final QueryTripsHslContext context = (QueryTripsHslContext) contextObj;

View file

@ -91,10 +91,12 @@ public class VrsProvider extends AbstractNetworkProvider {
private Context() {
}
@Override
public boolean canQueryLater() {
return this.canQueryLater;
}
@Override
public boolean canQueryEarlier() {
return this.canQueryEarlier;
}
@ -347,6 +349,7 @@ public class VrsProvider extends AbstractNetworkProvider {
}
// only stations supported
@Override
public NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types /* only STATION supported */,
Location location, int maxDistance, int maxLocations) throws IOException {
// g=p means group by product; not used here
@ -410,6 +413,7 @@ public class VrsProvider extends AbstractNetworkProvider {
// VRS does not show LongDistanceTrains departures. Parameter p for product
// filter is supported, but LongDistanceTrains filter seems to be ignored.
// TODO equivs not supported; JSON result would support multiple timetables
@Override
public QueryDeparturesResult queryDepartures(final String stationId, @Nullable Date time, int maxDepartures,
boolean equivs) throws IOException {
checkNotNull(Strings.emptyToNull(stationId));
@ -551,11 +555,13 @@ public class VrsProvider extends AbstractNetworkProvider {
}
private static class LineDestinationComparator implements Comparator<LineDestination> {
@Override
public int compare(LineDestination o1, LineDestination o2) {
return o1.line.compareTo(o2.line);
}
}
@Override
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
// sc = station count
final int sc = 10;
@ -631,6 +637,7 @@ public class VrsProvider extends AbstractNetworkProvider {
// walkSpeed not supported.
// accessibility not supported.
// options not supported.
@Override
public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, Date date,
boolean dep, final @Nullable Set<Product> products, final @Nullable Optimize optimize,
final @Nullable WalkSpeed walkSpeed, final @Nullable Accessibility accessibility,
@ -916,6 +923,7 @@ public class VrsProvider extends AbstractNetworkProvider {
}
}
@Override
public QueryTripsResult queryMoreTrips(QueryTripsContext context, boolean later) throws IOException {
Context ctx = (Context) context;
if (later) {

View file

@ -97,6 +97,7 @@ public final class Departure implements Serializable {
}
public static final Comparator<Departure> TIME_COMPARATOR = new Comparator<Departure>() {
@Override
public int compare(final Departure departure0, final Departure departure1) {
return departure0.getTime().compareTo(departure1.getTime());
}

View file

@ -132,6 +132,7 @@ public final class Line implements Serializable, Comparable<Line> {
.toString();
}
@Override
public int compareTo(final Line other) {
return ComparisonChain.start() //
.compare(this.network, other.network, Ordering.natural().nullsLast()) //

View file

@ -40,6 +40,7 @@ public final class SuggestedLocation implements Serializable, Comparable<Suggest
this(location, 0);
}
@Override
public int compareTo(final SuggestedLocation other) {
// prefer quality
if (this.priority > other.priority)

View file

@ -330,6 +330,7 @@ public final class HttpClient {
}
private static final HostnameVerifier SSL_ACCEPT_ALL_HOSTNAMES = new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}

View file

@ -511,6 +511,7 @@ public class VrsProviderLiveTest extends AbstractProviderLiveTest {
}
private static class LocationComparator implements Comparator<Location> {
@Override
public int compare(Location o1, Location o2) {
return ComparisonChain.start().compare(o1.name, o2.name).result();
}

View file

@ -8,6 +8,6 @@ dependencies {
}
compileJava {
sourceCompatibility '1.6'
targetCompatibility '1.6'
sourceCompatibility '1.7'
targetCompatibility '1.7'
}