map for connection details

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@507 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-02-27 11:15:19 +00:00
parent 19410bd60f
commit f534dae100
8 changed files with 148 additions and 27 deletions

View file

@ -46,6 +46,7 @@ import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.Point;
import de.schildbach.pte.dto.QueryConnectionsResult;
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
import de.schildbach.pte.dto.QueryDeparturesResult;
@ -1311,19 +1312,28 @@ public abstract class AbstractEfaProvider implements NetworkProvider
{
final int min = (int) (arrivalTime.getTimeInMillis() - departureTime.getTimeInMillis()) / 1000 / 60;
XmlPullUtil.enter(pp, "itdMeansOfTransport");
XmlPullUtil.exit(pp, "itdMeansOfTransport");
if (XmlPullUtil.test(pp, "itdStopSeq"))
XmlPullUtil.next(pp);
List<Point> path = null;
if (XmlPullUtil.test(pp, "itdPathCoordinates"))
path = processItdPathCoordinates(pp);
if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
{
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
if (path != null && lastFootway.path != null)
path.addAll(0, lastFootway.path);
parts.add(new Connection.Footway(lastFootway.min + min, lastFootway.departureId, lastFootway.departure, arrivalId,
arrival));
arrival, path));
}
else
{
parts.add(new Connection.Footway(min, departureId, departure, arrivalId, arrival));
parts.add(new Connection.Footway(min, departureId, departure, arrivalId, arrival, path));
}
XmlPullUtil.enter(pp, "itdMeansOfTransport");
XmlPullUtil.exit(pp, "itdMeansOfTransport");
}
else if ("gesicherter Anschluss".equals(productName) || "nicht umsteigen".equals(productName)) // type97
{
@ -1387,8 +1397,12 @@ public abstract class AbstractEfaProvider implements NetworkProvider
intermediateStops.remove(intermediateStops.size() - 1);
}
List<Point> path = null;
if (XmlPullUtil.test(pp, "itdPathCoordinates"))
path = processItdPathCoordinates(pp);
parts.add(new Connection.Trip(line, destination, departureTime.getTime(), departurePosition, departureId, departure,
arrivalTime.getTime(), arrivalPosition, arrivalId, arrival, intermediateStops));
arrivalTime.getTime(), arrivalPosition, arrivalId, arrival, intermediateStops, path));
}
XmlPullUtil.exit(pp, "itdPartialRoute");
@ -1453,6 +1467,39 @@ public abstract class AbstractEfaProvider implements NetworkProvider
}
}
private List<Point> processItdPathCoordinates(final XmlPullParser pp) throws XmlPullParserException, IOException
{
final List<Point> path = new LinkedList<Point>();
XmlPullUtil.enter(pp, "itdPathCoordinates");
XmlPullUtil.enter(pp, "coordEllipsoid");
final String ellipsoid = pp.getText();
XmlPullUtil.exit(pp, "coordEllipsoid");
if (!"WGS84".equals(ellipsoid))
throw new IllegalStateException("unknown ellipsoid: " + ellipsoid);
XmlPullUtil.enter(pp, "coordType");
final String type = pp.getText();
XmlPullUtil.exit(pp, "coordType");
if (!"GEO_DECIMAL".equals(type))
throw new IllegalStateException("unknown type: " + type);
XmlPullUtil.enter(pp, "itdCoordinateString");
for (final String coordStr : pp.getText().split(" "))
{
final String[] coordsStr = coordStr.split(",");
path.add(new Point(Integer.parseInt(coordsStr[1]), Integer.parseInt(coordsStr[0])));
}
XmlPullUtil.exit(pp, "itdCoordinateString");
XmlPullUtil.exit(pp, "itdPathCoordinates");
return path;
}
private Fare processItdGenericTicketGroup(final XmlPullParser pp, final String net, final Currency currency) throws XmlPullParserException,
IOException
{

View file

@ -448,7 +448,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
if (min == 0 || line != null)
{
parts.add(new Connection.Trip(line, destination, departureTime, departurePos, sectionDeparture.id, sectionDeparture.name,
arrivalTime, arrivalPos, sectionArrival.id, sectionArrival.name, null));
arrivalTime, arrivalPos, sectionArrival.id, sectionArrival.name, null, null));
}
else
{
@ -456,11 +456,12 @@ public abstract class AbstractHafasProvider implements NetworkProvider
{
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
parts.add(new Connection.Footway(lastFootway.min + min, lastFootway.departureId, lastFootway.departure,
sectionArrival.id, sectionArrival.name));
sectionArrival.id, sectionArrival.name, null));
}
else
{
parts.add(new Connection.Footway(min, sectionDeparture.id, sectionDeparture.name, sectionArrival.id, sectionArrival.name));
parts.add(new Connection.Footway(min, sectionDeparture.id, sectionDeparture.name, sectionArrival.id, sectionArrival.name,
null));
}
}

View file

@ -368,7 +368,7 @@ public final class BahnProvider extends AbstractHafasProvider
final Date departureDateTime = ParserUtils.joinDateTime(departureDate, departureTime);
final Date arrivalDateTime = ParserUtils.joinDateTime(arrivalDate, arrivalTime);
lastTrip = new Connection.Trip(line, null, departureDateTime, departurePosition, 0, departure, arrivalDateTime,
arrivalPosition, 0, arrival, null);
arrivalPosition, 0, arrival, null, null);
parts.add(lastTrip);
if (firstDepartureTime == null)
@ -386,11 +386,11 @@ public final class BahnProvider extends AbstractHafasProvider
if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
{
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), 0, lastFootway.departure, 0, arrival));
parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), 0, lastFootway.departure, 0, arrival, null));
}
else
{
parts.add(new Connection.Footway(Integer.parseInt(min), 0, departure, 0, arrival));
parts.add(new Connection.Footway(Integer.parseInt(min), 0, departure, 0, arrival, null));
}
lastArrival = arrival;
@ -399,7 +399,7 @@ public final class BahnProvider extends AbstractHafasProvider
{
final String arrival = ParserUtils.resolveEntities(mDetFine.group(12));
parts.add(new Connection.Footway(0, 0, departure, 0, arrival));
parts.add(new Connection.Footway(0, 0, departure, 0, arrival, null));
}
}
else

View file

@ -525,7 +525,7 @@ public final class BvgProvider extends AbstractHafasProvider
final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
parts.add(new Connection.Trip(line, destination, departureTime, departurePosition, departureId, departure, arrivalTime,
arrivalPosition, arrivalId, arrival, null));
arrivalPosition, arrivalId, arrival, null, null));
if (firstDepartureTime == null)
firstDepartureTime = departureTime;
@ -549,12 +549,12 @@ public final class BvgProvider extends AbstractHafasProvider
{
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), lastFootway.departureId, lastFootway.departure,
arrivalId, arrival, arrivalLat, arrivalLon));
arrivalId, arrival, arrivalLat, arrivalLon, null));
}
else
{
parts.add(new Connection.Footway(Integer.parseInt(min), departureId, departure, arrivalId, arrival, arrivalLat,
arrivalLon));
arrivalLon, null));
}
lastArrival = arrival;

View file

@ -464,14 +464,14 @@ public class OebbProvider extends AbstractHafasProvider
ParserUtils.resolveEntities(mDetFine.group(13))) : null;
final Connection.Trip trip = new Connection.Trip(line, destination, detailsDepartureDateTime, departurePosition,
departureId, departure, detailsArrivalDateTime, arrivalPosition, arrivalId, arrival, null);
departureId, departure, detailsArrivalDateTime, arrivalPosition, arrivalId, arrival, null, null);
connection.parts.add(trip);
}
else
{
final int min = (int) (detailsArrivalDateTime.getTime() - detailsDepartureDateTime.getTime()) / 1000 / 60;
final Connection.Footway footway = new Connection.Footway(min, departureId, departure, arrivalId, arrival);
final Connection.Footway footway = new Connection.Footway(min, departureId, departure, arrivalId, arrival, null);
connection.parts.add(footway);
}
}

View file

@ -372,7 +372,7 @@ public class RmvProvider extends AbstractHafasProvider
final String arrivalPosition = ParserUtils.resolveEntities(mDetFine.group(6));
lastTrip = new Connection.Trip(line, destination, departureTime, departurePosition, 0, departure, arrivalTime,
arrivalPosition, 0, arrival, null);
arrivalPosition, 0, arrival, null, null);
parts.add(lastTrip);
if (firstDepartureTime == null)
@ -385,11 +385,11 @@ public class RmvProvider extends AbstractHafasProvider
if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
{
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), 0, lastFootway.departure, 0, arrival));
parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), 0, lastFootway.departure, 0, arrival, null));
}
else
{
parts.add(new Connection.Footway(Integer.parseInt(min), 0, departure, 0, arrival));
parts.add(new Connection.Footway(Integer.parseInt(min), 0, departure, 0, arrival, null));
}
}
}

View file

@ -77,11 +77,17 @@ public final class Connection implements Serializable
return id.hashCode();
}
public static interface Part extends Serializable
public static class Part implements Serializable
{
public final List<Point> path;
public Part(final List<Point> path)
{
this.path = path;
}
}
public final static class Trip implements Part
public final static class Trip extends Part
{
public final String line;
public final Location destination;
@ -97,8 +103,10 @@ public final class Connection implements Serializable
public Trip(final String line, final Location destination, final Date departureTime, final String departurePosition, final int departureId,
final String departure, final Date arrivalTime, final String arrivalPosition, final int arrivalId, final String arrival,
final List<Stop> intermediateStops)
final List<Stop> intermediateStops, final List<Point> path)
{
super(path);
this.line = line;
this.destination = destination;
this.departureTime = departureTime;
@ -130,7 +138,7 @@ public final class Connection implements Serializable
}
}
public final static class Footway implements Part
public final static class Footway extends Part
{
public final int min;
public final int departureId;
@ -140,8 +148,10 @@ public final class Connection implements Serializable
public final int arrivalLat, arrivalLon;
public Footway(final int min, final int departureId, final String departure, final int arrivalId, final String arrival, final int arrivalLat,
final int arrivalLon)
final int arrivalLon, final List<Point> path)
{
super(path);
this.min = min;
this.departureId = departureId;
this.departure = departure;
@ -151,8 +161,10 @@ public final class Connection implements Serializable
this.arrivalLon = arrivalLon;
}
public Footway(final int min, final int departureId, final String departure, final int arrivalId, final String arrival)
public Footway(final int min, final int departureId, final String departure, final int arrivalId, final String arrival, final List<Point> path)
{
super(path);
this.min = min;
this.departureId = departureId;
this.departure = departure;

View file

@ -0,0 +1,61 @@
/*
* Copyright 2010 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.schildbach.pte.dto;
import java.io.Serializable;
/**
* @author Andreas Schildbach
*/
public final class Point implements Serializable
{
public final int lat, lon;
public Point(final int lat, final int lon)
{
this.lat = lat;
this.lon = lon;
}
@Override
public String toString()
{
return "[" + lat + "/" + lon + "]";
}
@Override
public boolean equals(final Object o)
{
if (o == this)
return true;
if (!(o instanceof Point))
return false;
final Point other = (Point) o;
if (this.lat != other.lat)
return false;
if (this.lon != other.lon)
return false;
return true;
}
@Override
public int hashCode()
{
return lat + 27 * lon;
}
}