mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 04:58:46 +00:00
Replace anonymous nested classes with lambdas.
This commit is contained in:
parent
dd96d33afa
commit
0c10251957
4 changed files with 1495 additions and 1564 deletions
|
@ -381,9 +381,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendStopfinderRequestParameters(url, constraint, "XML", types, maxLocations);
|
||||
final AtomicReference<SuggestLocationsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParser pp = parserFactory.newPullParser();
|
||||
pp.setInput(body.charStream());
|
||||
|
@ -443,7 +441,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final XmlPullParserException | ParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpReferer);
|
||||
|
@ -478,9 +475,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
|
||||
final AtomicReference<NearbyLocationsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParser pp = parserFactory.newPullParser();
|
||||
pp.setInput(body.charStream());
|
||||
|
@ -517,12 +512,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
|
||||
// FIXME this is always only one coordinate
|
||||
final List<Point> path = processItdPathCoordinates(pp);
|
||||
final Point coord = path != null ? path.get(0) : null;
|
||||
final Point coord1 = path != null ? path.get(0) : null;
|
||||
|
||||
XmlPullUtil.skipExit(pp, "coordInfoItem");
|
||||
|
||||
if (name != null)
|
||||
locations.add(new Location(locationType, id, coord, place, name));
|
||||
locations.add(new Location(locationType, id, coord1, place, name));
|
||||
}
|
||||
|
||||
XmlPullUtil.skipExit(pp, "coordInfoItemList");
|
||||
|
@ -532,7 +527,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final XmlPullParserException | ParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpReferer);
|
||||
|
@ -546,9 +540,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
|
||||
final AtomicReference<NearbyLocationsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParser pp = parserFactory.newPullParser();
|
||||
pp.setInput(body.charStream());
|
||||
|
@ -582,13 +574,13 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
XmlPullUtil.valueTag(pp, "ds");
|
||||
final String stateless = XmlPullUtil.valueTag(pp, "stateless");
|
||||
final String locationId = locationType == LocationType.STATION ? id : stateless;
|
||||
final Point coord = parseCoord(XmlPullUtil.valueTag(pp, "c"));
|
||||
final Point coord1 = parseCoord(XmlPullUtil.valueTag(pp, "c"));
|
||||
|
||||
final Location location;
|
||||
if (name != null)
|
||||
location = new Location(locationType, locationId, coord, place, name);
|
||||
location = new Location(locationType, locationId, coord1, place, name);
|
||||
else
|
||||
location = new Location(locationType, locationId, coord, null, place);
|
||||
location = new Location(locationType, locationId, coord1, null, place);
|
||||
stations.add(location);
|
||||
|
||||
XmlPullUtil.skipExit(pp, "pi");
|
||||
|
@ -603,7 +595,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final XmlPullParserException | ParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpReferer);
|
||||
|
@ -813,9 +804,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
url.addEncodedQueryParameter("mode", "direct");
|
||||
final AtomicReference<NearbyLocationsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParser pp = parserFactory.newPullParser();
|
||||
pp.setInput(body.charStream());
|
||||
|
@ -826,18 +815,13 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
final AtomicReference<Location> ownStation = new AtomicReference<>();
|
||||
final List<Location> stations = new ArrayList<>();
|
||||
|
||||
final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback() {
|
||||
@Override
|
||||
public void location(final String nameState, final Location location, final int matchQuality) {
|
||||
final String nameState = processItdOdv(pp, "dm", (nameState1, location, matchQuality) -> {
|
||||
if (location.type == LocationType.STATION) {
|
||||
if ("identified".equals(nameState))
|
||||
ownStation.set(location);
|
||||
else if ("assigned".equals(nameState))
|
||||
stations.add(location);
|
||||
if ("identified".equals(nameState1)) ownStation.set(location);
|
||||
else if ("assigned".equals(nameState1)) stations.add(location);
|
||||
} else {
|
||||
throw new IllegalStateException("cannot handle: " + location.type);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ("notidentified".equals(nameState)) {
|
||||
|
@ -855,7 +839,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final XmlPullParserException | ParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpReferer);
|
||||
|
@ -1433,9 +1416,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendDepartureMonitorRequestParameters(url, stationId, time, maxDepartures, equivs);
|
||||
final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParser pp = parserFactory.newPullParser();
|
||||
pp.setInput(body.charStream());
|
||||
|
@ -1446,14 +1427,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
|
||||
XmlPullUtil.optSkipMultiple(pp, "itdMessage");
|
||||
|
||||
final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback() {
|
||||
@Override
|
||||
public void location(final String nameState, final Location location, final int matchQuality) {
|
||||
final String nameState = processItdOdv(pp, "dm", (nameState1, location, matchQuality) -> {
|
||||
if (location.type == LocationType.STATION)
|
||||
if (findStationDepartures(r.stationDepartures, location.id) == null)
|
||||
r.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(),
|
||||
new LinkedList<LineDestination>()));
|
||||
}
|
||||
r.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(), new LinkedList<LineDestination>()));
|
||||
});
|
||||
|
||||
if (!"identified".equals(nameState)) {
|
||||
|
@ -1567,7 +1544,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final XmlPullParserException | ParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpReferer);
|
||||
|
@ -1581,9 +1557,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendDepartureMonitorRequestParameters(url, stationId, time, maxDepartures, equivs);
|
||||
final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParser pp = parserFactory.newPullParser();
|
||||
pp.setInput(body.charStream());
|
||||
|
@ -1660,7 +1634,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final XmlPullParserException | ParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpReferer);
|
||||
|
@ -2040,9 +2013,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendTripRequestParameters(url, from, via, to, date, dep, options);
|
||||
final AtomicReference<QueryTripsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
result.set(queryTrips(url.build(), body.charStream()));
|
||||
} catch (final XmlPullParserException | ParserException x) {
|
||||
|
@ -2050,7 +2021,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final RuntimeException x) {
|
||||
throw new RuntimeException("uncategorized problem while processing " + url, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpRefererTrip);
|
||||
|
@ -2064,9 +2034,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
appendTripRequestParameters(url, from, via, to, date, dep, options);
|
||||
final AtomicReference<QueryTripsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
result.set(queryTripsMobile(url.build(), from, via, to, body.charStream()));
|
||||
} catch (final XmlPullParserException | ParserException x) {
|
||||
|
@ -2074,7 +2042,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final RuntimeException x) {
|
||||
throw new RuntimeException("uncategorized problem while processing " + url, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpRefererTrip);
|
||||
|
@ -2091,9 +2058,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
url.addEncodedQueryParameter("command", later ? "tripNext" : "tripPrev");
|
||||
final AtomicReference<QueryTripsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
result.set(queryTrips(url.build(), body.charStream()));
|
||||
} catch (final XmlPullParserException | ParserException x) {
|
||||
|
@ -2101,7 +2066,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final RuntimeException x) {
|
||||
throw new RuntimeException("uncategorized problem while processing " + url, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpRefererTrip);
|
||||
|
@ -2118,9 +2082,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
url.addEncodedQueryParameter("command", later ? "tripNext" : "tripPrev");
|
||||
final AtomicReference<QueryTripsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
final HttpClient.Callback callback = (bodyPeek, body) -> {
|
||||
try {
|
||||
result.set(queryTripsMobile(url.build(), null, null, null, body.charStream()));
|
||||
} catch (final XmlPullParserException | ParserException x) {
|
||||
|
@ -2128,7 +2090,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
} catch (final RuntimeException x) {
|
||||
throw new RuntimeException("uncategorized problem while processing " + url, x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
httpClient.getInputStream(callback, url.build(), httpRefererTrip);
|
||||
|
@ -2163,12 +2124,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
final String usage = XmlPullUtil.attr(pp, "usage");
|
||||
|
||||
final List<Location> locations = new ArrayList<>();
|
||||
final String nameState = processItdOdv(pp, usage, new ProcessItdOdvCallback() {
|
||||
@Override
|
||||
public void location(final String nameState, final Location location, final int matchQuality) {
|
||||
locations.add(location);
|
||||
}
|
||||
});
|
||||
final String nameState = processItdOdv(pp, usage, (nameState1, location, matchQuality) -> locations.add(location));
|
||||
|
||||
if ("list".equals(nameState)) {
|
||||
if ("origin".equals(usage))
|
||||
|
|
|
@ -440,10 +440,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
final String normalizedStationId = normalizeStationId(stationId);
|
||||
final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>();
|
||||
|
||||
httpClient.getInputStream(new HttpClient.Callback() {
|
||||
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
httpClient.getInputStream((bodyPeek, body) -> {
|
||||
StringReplaceReader reader = null;
|
||||
String firstChars = null;
|
||||
|
||||
|
@ -594,14 +591,14 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
final Set<Attr> attrs = prodLine.attrs;
|
||||
if (attrs != null)
|
||||
line = newLine(administration, product, prodLine.label, null,
|
||||
attrs.toArray(new Line.Attr[0]));
|
||||
attrs.toArray(new Attr[0]));
|
||||
else
|
||||
line = newLine(administration, product, prodLine.label, null);
|
||||
} else {
|
||||
final Set<Attr> attrs = prodLine.attrs;
|
||||
if (attrs != null)
|
||||
line = newLine(administration, prodLine.product, prodLine.label, null,
|
||||
attrs.toArray(new Line.Attr[0]));
|
||||
attrs.toArray(new Attr[0]));
|
||||
else
|
||||
line = newLine(administration, prodLine.product, prodLine.label, null);
|
||||
}
|
||||
|
@ -663,7 +660,6 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||
}
|
||||
}
|
||||
}, url);
|
||||
|
||||
return result.get();
|
||||
|
@ -794,9 +790,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
final HttpUrl endpoint = extXmlEndpoint != null ? extXmlEndpoint
|
||||
: queryEndpoint.newBuilder().addPathSegment(apiLanguage).build();
|
||||
final AtomicReference<QueryTripsResult> result = new AtomicReference<>();
|
||||
httpClient.getInputStream(new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
httpClient.getInputStream((bodyPeek, body) -> {
|
||||
try {
|
||||
final XmlPullParserFactory factory = XmlPullParserFactory
|
||||
.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
|
@ -1184,7 +1178,6 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
} catch (final XmlPullParserException x) {
|
||||
throw new ParserException("cannot parse xml: " + bodyPeek, x);
|
||||
}
|
||||
}
|
||||
}, endpoint, request, "application/xml", null);
|
||||
|
||||
return result.get();
|
||||
|
@ -1432,9 +1425,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
|
||||
final AtomicReference<QueryTripsResult> result = new AtomicReference<>();
|
||||
|
||||
httpClient.getInputStream(new HttpClient.Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
httpClient.getInputStream((HttpClient.Callback) (bodyPeek, body) -> {
|
||||
final CustomBufferedInputStream bis = new CustomBufferedInputStream(
|
||||
new GZIPInputStream(body.byteStream()));
|
||||
|
||||
|
@ -1661,15 +1652,15 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
|
||||
final int legAttrIndex = is.readShortReverse();
|
||||
|
||||
final List<Line.Attr> lineAttrs = new ArrayList<>();
|
||||
final List<Attr> lineAttrs = new ArrayList<>();
|
||||
String lineComment = null;
|
||||
boolean lineOnDemand = false;
|
||||
for (final String comment : comments.read(is)) {
|
||||
if (comment.startsWith("bf ")) {
|
||||
lineAttrs.add(Line.Attr.WHEEL_CHAIR_ACCESS);
|
||||
lineAttrs.add(Attr.WHEEL_CHAIR_ACCESS);
|
||||
} else if (comment.startsWith("FA ") || comment.startsWith("FB ")
|
||||
|| comment.startsWith("FR ")) {
|
||||
lineAttrs.add(Line.Attr.BICYCLE_CARRIAGE);
|
||||
lineAttrs.add(Attr.BICYCLE_CARRIAGE);
|
||||
} else if (comment.startsWith("$R ") || comment.startsWith("ga ")
|
||||
|| comment.startsWith("ja ") || comment.startsWith("Vs ")
|
||||
|| comment.startsWith("mu ") || comment.startsWith("mx ")) {
|
||||
|
@ -1879,7 +1870,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
lineProduct = normalizeType(lineCategory);
|
||||
|
||||
final Line line = newLine(lineNetwork, lineProduct, normalizeLineName(lineName),
|
||||
lineComment, lineAttrs.toArray(new Line.Attr[0]));
|
||||
lineComment, lineAttrs.toArray(new Attr[0]));
|
||||
|
||||
final Location direction;
|
||||
if (directionStr != null) {
|
||||
|
@ -2015,7 +2006,6 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
throw new IllegalStateException("error " + errorCode + " on " + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, url);
|
||||
|
||||
return result.get();
|
||||
|
|
|
@ -96,10 +96,5 @@ public final class Departure implements Serializable {
|
|||
return Objects.hashCode(plannedTime, predictedTime, line, destination);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
};
|
||||
public static final Comparator<Departure> TIME_COMPARATOR = (departure0, departure1) -> departure0.getTime().compareTo(departure1.getTime());
|
||||
}
|
||||
|
|
|
@ -208,12 +208,7 @@ public final class HttpClient {
|
|||
public CharSequence get(final HttpUrl url, final String postRequest, final String requestContentType)
|
||||
throws IOException {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
final Callback callback = new Callback() {
|
||||
@Override
|
||||
public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
|
||||
buffer.append(body.string());
|
||||
}
|
||||
};
|
||||
final Callback callback = (bodyPeek, body) -> buffer.append(body.string());
|
||||
getInputStream(callback, url, postRequest, requestContentType, null);
|
||||
return buffer;
|
||||
}
|
||||
|
@ -382,10 +377,5 @@ 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;
|
||||
}
|
||||
};
|
||||
private static final HostnameVerifier SSL_ACCEPT_ALL_HOSTNAMES = (hostname, session) -> true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue