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:
andreas.schildbach@gmail.com 2011-02-11 18:06:30 +00:00
parent 240e95d19b
commit 3d14d7da8b
6 changed files with 20 additions and 114 deletions

View file

@ -49,7 +49,6 @@ import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.QueryConnectionsResult;
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
import de.schildbach.pte.dto.QueryDeparturesResult;
import de.schildbach.pte.dto.Station;
import de.schildbach.pte.dto.StationDepartures;
import de.schildbach.pte.dto.Stop;
import de.schildbach.pte.util.Color;
@ -292,10 +291,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if ("identified".equals(nameState))
{
final Location ownLocation = processOdvNameElem(pp, place);
final Station ownStation = ownLocation.type == LocationType.STATION ? new Station(ownLocation.id, ownLocation.place,
ownLocation.name, null, ownLocation.lat, ownLocation.lon) : null;
final Location ownStation = ownLocation.type == LocationType.STATION ? ownLocation : null;
final List<Station> stations = new ArrayList<Station>();
final List<Location> stations = new ArrayList<Location>();
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
{
@ -317,7 +315,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if (!"WGS84".equals(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))
stations.add(newStation);
}
@ -346,19 +345,15 @@ public abstract class AbstractEfaProvider implements NetworkProvider
}
else if ("list".equals(nameState))
{
final List<Station> stations = new ArrayList<Station>();
final List<Location> stations = new ArrayList<Location>();
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
while (XmlPullUtil.test(pp, "odvNameElem"))
{
final Location location = processOdvNameElem(pp, place);
if (location.type == LocationType.STATION)
{
final Station newStation = new Station(location.id, null, null, location.name, location.lat, location.lon);
if (!stations.contains(newStation))
stations.add(newStation);
}
final Location newLocation = processOdvNameElem(pp, place);
if (newLocation.type == LocationType.STATION && !stations.contains(newLocation))
stations.add(newLocation);
}
return new NearbyStationsResult(stations);

View file

@ -43,7 +43,6 @@ import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.QueryConnectionsResult;
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
import de.schildbach.pte.dto.Station;
import de.schildbach.pte.util.Color;
import de.schildbach.pte.util.ParserUtils;
import de.schildbach.pte.util.XmlPullUtil;
@ -759,7 +758,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
if (stationId == null)
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 CharSequence page = ParserUtils.scrape(uri);
@ -793,7 +792,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
}
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
{

View file

@ -37,7 +37,6 @@ import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.QueryConnectionsResult;
import de.schildbach.pte.dto.QueryDeparturesResult;
import de.schildbach.pte.dto.Station;
import de.schildbach.pte.dto.StationDepartures;
import de.schildbach.pte.exception.SessionExpiredException;
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)
throws IOException
{
final List<Station> stations = new ArrayList<Station>();
final List<Location> stations = new ArrayList<Location>();
if (lat == 0 && lon == 0)
{
@ -96,7 +95,7 @@ public final class BahnProvider extends AbstractHafasProvider
final int sId = Integer.parseInt(m.group(1));
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);
}
}
@ -115,7 +114,7 @@ public final class BahnProvider extends AbstractHafasProvider
final int sLat = Integer.parseInt(m.group(2));
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);
}
}

View file

@ -40,7 +40,6 @@ import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.QueryConnectionsResult;
import de.schildbach.pte.dto.QueryDeparturesResult;
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
import de.schildbach.pte.dto.Station;
import de.schildbach.pte.dto.StationDepartures;
import de.schildbach.pte.exception.SessionExpiredException;
import de.schildbach.pte.util.Color;
@ -129,7 +128,7 @@ public final class BvgProvider extends AbstractHafasProvider
if (stationId == null)
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 CharSequence page = ParserUtils.scrape(uri);
@ -164,7 +163,7 @@ public final class BvgProvider extends AbstractHafasProvider
{
final int parsedId = Integer.parseInt(mFineLocation.group(1));
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))
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)"))
{
@ -214,12 +213,8 @@ public final class BvgProvider extends AbstractHafasProvider
place = "Frankfurt (Oder)";
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";

View file

@ -30,9 +30,9 @@ public final class NearbyStationsResult
}
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.stations = stations;

View file

@ -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;
}
}