mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-17 13:59:50 +00:00
merge Station dto into Location dto
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@492 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
240e95d19b
commit
3d14d7da8b
6 changed files with 20 additions and 114 deletions
|
@ -49,7 +49,6 @@ import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
|
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.Station;
|
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.dto.Stop;
|
import de.schildbach.pte.dto.Stop;
|
||||||
import de.schildbach.pte.util.Color;
|
import de.schildbach.pte.util.Color;
|
||||||
|
@ -292,10 +291,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
if ("identified".equals(nameState))
|
if ("identified".equals(nameState))
|
||||||
{
|
{
|
||||||
final Location ownLocation = processOdvNameElem(pp, place);
|
final Location ownLocation = processOdvNameElem(pp, place);
|
||||||
final Station ownStation = ownLocation.type == LocationType.STATION ? new Station(ownLocation.id, ownLocation.place,
|
final Location ownStation = ownLocation.type == LocationType.STATION ? ownLocation : null;
|
||||||
ownLocation.name, null, ownLocation.lat, ownLocation.lon) : null;
|
|
||||||
|
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Location> stations = new ArrayList<Location>();
|
||||||
|
|
||||||
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
|
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
|
||||||
{
|
{
|
||||||
|
@ -317,7 +315,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
if (!"WGS84".equals(parsedMapName))
|
if (!"WGS84".equals(parsedMapName))
|
||||||
throw new IllegalStateException("unknown mapName: " + parsedMapName);
|
throw new IllegalStateException("unknown mapName: " + parsedMapName);
|
||||||
|
|
||||||
final Station newStation = new Station(parsedLocationId, parsedPlace, parsedName, parsedLongName, parsedLat, parsedLon);
|
final Location newStation = new Location(LocationType.STATION, parsedLocationId, parsedLat, parsedLon, parsedPlace,
|
||||||
|
parsedName);
|
||||||
if (!stations.contains(newStation))
|
if (!stations.contains(newStation))
|
||||||
stations.add(newStation);
|
stations.add(newStation);
|
||||||
}
|
}
|
||||||
|
@ -346,19 +345,15 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
else if ("list".equals(nameState))
|
else if ("list".equals(nameState))
|
||||||
{
|
{
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Location> stations = new ArrayList<Location>();
|
||||||
|
|
||||||
if (XmlPullUtil.test(pp, "itdMessage"))
|
if (XmlPullUtil.test(pp, "itdMessage"))
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
while (XmlPullUtil.test(pp, "odvNameElem"))
|
while (XmlPullUtil.test(pp, "odvNameElem"))
|
||||||
{
|
{
|
||||||
final Location location = processOdvNameElem(pp, place);
|
final Location newLocation = processOdvNameElem(pp, place);
|
||||||
if (location.type == LocationType.STATION)
|
if (newLocation.type == LocationType.STATION && !stations.contains(newLocation))
|
||||||
{
|
stations.add(newLocation);
|
||||||
final Station newStation = new Station(location.id, null, null, location.name, location.lat, location.lon);
|
|
||||||
if (!stations.contains(newStation))
|
|
||||||
stations.add(newStation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NearbyStationsResult(stations);
|
return new NearbyStationsResult(stations);
|
||||||
|
|
|
@ -43,7 +43,6 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
|
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
|
||||||
import de.schildbach.pte.dto.Station;
|
|
||||||
import de.schildbach.pte.util.Color;
|
import de.schildbach.pte.util.Color;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
import de.schildbach.pte.util.XmlPullUtil;
|
import de.schildbach.pte.util.XmlPullUtil;
|
||||||
|
@ -759,7 +758,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
if (stationId == null)
|
if (stationId == null)
|
||||||
throw new IllegalArgumentException("stationId must be given");
|
throw new IllegalArgumentException("stationId must be given");
|
||||||
|
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Location> stations = new ArrayList<Location>();
|
||||||
|
|
||||||
final String uri = nearbyStationUri(stationId);
|
final String uri = nearbyStationUri(stationId);
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
|
@ -793,7 +792,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] nameAndPlace = splitNameAndPlace(parsedName);
|
final String[] nameAndPlace = splitNameAndPlace(parsedName);
|
||||||
stations.add(new Station(parsedId, nameAndPlace[0], nameAndPlace[1], parsedName, parsedLat, parsedLon));
|
stations.add(new Location(LocationType.STATION, parsedId, parsedLat, parsedLon, nameAndPlace[0], nameAndPlace[1]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,7 +37,6 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.Station;
|
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.exception.SessionExpiredException;
|
import de.schildbach.pte.exception.SessionExpiredException;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
@ -83,7 +82,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
public NearbyStationsResult nearbyStations(final String stationId, final int lat, final int lon, final int maxDistance, final int maxStations)
|
public NearbyStationsResult nearbyStations(final String stationId, final int lat, final int lon, final int maxDistance, final int maxStations)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Location> stations = new ArrayList<Location>();
|
||||||
|
|
||||||
if (lat == 0 && lon == 0)
|
if (lat == 0 && lon == 0)
|
||||||
{
|
{
|
||||||
|
@ -96,7 +95,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
final int sId = Integer.parseInt(m.group(1));
|
final int sId = Integer.parseInt(m.group(1));
|
||||||
final String sName = ParserUtils.resolveEntities(m.group(2).trim());
|
final String sName = ParserUtils.resolveEntities(m.group(2).trim());
|
||||||
|
|
||||||
final Station station = new Station(sId, null, sName, null, 0, 0);
|
final Location station = new Location(LocationType.STATION, sId, null, sName);
|
||||||
stations.add(station);
|
stations.add(station);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +114,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
final int sLat = Integer.parseInt(m.group(2));
|
final int sLat = Integer.parseInt(m.group(2));
|
||||||
final String sName = ParserUtils.resolveEntities(m.group(5).trim());
|
final String sName = ParserUtils.resolveEntities(m.group(5).trim());
|
||||||
|
|
||||||
final Station station = new Station(sId, null, sName, null, sLat, sLon);
|
final Location station = new Location(LocationType.STATION, sId, sLat, sLon, null, sName);
|
||||||
stations.add(station);
|
stations.add(station);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
import de.schildbach.pte.dto.Station;
|
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.exception.SessionExpiredException;
|
import de.schildbach.pte.exception.SessionExpiredException;
|
||||||
import de.schildbach.pte.util.Color;
|
import de.schildbach.pte.util.Color;
|
||||||
|
@ -129,7 +128,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
if (stationId == null)
|
if (stationId == null)
|
||||||
throw new IllegalArgumentException("stationId must be given");
|
throw new IllegalArgumentException("stationId must be given");
|
||||||
|
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Location> stations = new ArrayList<Location>();
|
||||||
|
|
||||||
final String uri = nearbyStationUri(stationId);
|
final String uri = nearbyStationUri(stationId);
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
|
@ -164,7 +163,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
{
|
{
|
||||||
final int parsedId = Integer.parseInt(mFineLocation.group(1));
|
final int parsedId = Integer.parseInt(mFineLocation.group(1));
|
||||||
final String parsedName = ParserUtils.resolveEntities(mFineLocation.group(2));
|
final String parsedName = ParserUtils.resolveEntities(mFineLocation.group(2));
|
||||||
final Station station = newStation(parsedId, parsedName, 0, 0);
|
final Location station = newStation(parsedId, parsedName, 0, 0);
|
||||||
if (!stations.contains(station))
|
if (!stations.contains(station))
|
||||||
stations.add(station);
|
stations.add(station);
|
||||||
}
|
}
|
||||||
|
@ -185,9 +184,9 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Station newStation(final int id, final String parsedName, final int lat, final int lon)
|
private Location newStation(final int id, final String parsedName, final int lat, final int lon)
|
||||||
{
|
{
|
||||||
String place = null, name = null, longName = null;
|
String place = null, name = null;
|
||||||
|
|
||||||
if (parsedName.endsWith(" (Berlin)"))
|
if (parsedName.endsWith(" (Berlin)"))
|
||||||
{
|
{
|
||||||
|
@ -214,12 +213,8 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
place = "Frankfurt (Oder)";
|
place = "Frankfurt (Oder)";
|
||||||
name = parsedName.substring(18);
|
name = parsedName.substring(18);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
longName = parsedName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Station(id, place, name, longName, lat, lon);
|
return new Location(LocationType.STATION, id, lat, lon, place, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String STATION_URL_CONNECTION = "http://mobil.bvg.de/Fahrinfo/bin/query.bin/dox";
|
public static final String STATION_URL_CONNECTION = "http://mobil.bvg.de/Fahrinfo/bin/query.bin/dox";
|
||||||
|
|
|
@ -30,9 +30,9 @@ public final class NearbyStationsResult
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Status status;
|
public final Status status;
|
||||||
public final List<Station> stations;
|
public final List<Location> stations;
|
||||||
|
|
||||||
public NearbyStationsResult(final List<Station> stations)
|
public NearbyStationsResult(final List<Location> stations)
|
||||||
{
|
{
|
||||||
this.status = Status.OK;
|
this.status = Status.OK;
|
||||||
this.stations = stations;
|
this.stations = stations;
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andreas Schildbach
|
|
||||||
*/
|
|
||||||
public final class Station
|
|
||||||
{
|
|
||||||
// data
|
|
||||||
public final int id;
|
|
||||||
public final String place;
|
|
||||||
public final String name;
|
|
||||||
public final String longName;
|
|
||||||
public final int latitude, longitude;
|
|
||||||
|
|
||||||
public Station(final int id, final String place, final String name, final String longName, final int latitude, final int longitude)
|
|
||||||
{
|
|
||||||
this.id = id;
|
|
||||||
this.place = place;
|
|
||||||
this.name = name;
|
|
||||||
this.longName = longName;
|
|
||||||
this.latitude = latitude;
|
|
||||||
this.longitude = longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean hasLocation()
|
|
||||||
{
|
|
||||||
return latitude != 0 || longitude != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
StringBuilder builder = new StringBuilder("Station(");
|
|
||||||
builder.append(id);
|
|
||||||
builder.append("|");
|
|
||||||
builder.append(place);
|
|
||||||
builder.append("|");
|
|
||||||
builder.append(name);
|
|
||||||
builder.append("|");
|
|
||||||
builder.append(longName);
|
|
||||||
builder.append("|");
|
|
||||||
builder.append(latitude);
|
|
||||||
builder.append(",");
|
|
||||||
builder.append(longitude);
|
|
||||||
builder.append(")");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (o == this)
|
|
||||||
return true;
|
|
||||||
if (!(o instanceof Station))
|
|
||||||
return false;
|
|
||||||
final Station other = (Station) o;
|
|
||||||
return this.id == other.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue