diff --git a/src/de/schildbach/pte/AbstractEfaProvider.java b/src/de/schildbach/pte/AbstractEfaProvider.java index 0f6e9b70..20599d1a 100644 --- a/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/src/de/schildbach/pte/AbstractEfaProvider.java @@ -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 stations = new ArrayList(); + final List stations = new ArrayList(); 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 stations = new ArrayList(); + final List stations = new ArrayList(); 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); diff --git a/src/de/schildbach/pte/AbstractHafasProvider.java b/src/de/schildbach/pte/AbstractHafasProvider.java index 022a9ff2..199346f7 100644 --- a/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/src/de/schildbach/pte/AbstractHafasProvider.java @@ -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 stations = new ArrayList(); + final List stations = new ArrayList(); 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 { diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index c6fe867c..4b2b36b3 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -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 stations = new ArrayList(); + final List stations = new ArrayList(); 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); } } diff --git a/src/de/schildbach/pte/BvgProvider.java b/src/de/schildbach/pte/BvgProvider.java index d0a0beb9..f68510c5 100644 --- a/src/de/schildbach/pte/BvgProvider.java +++ b/src/de/schildbach/pte/BvgProvider.java @@ -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 stations = new ArrayList(); + final List stations = new ArrayList(); 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"; diff --git a/src/de/schildbach/pte/dto/NearbyStationsResult.java b/src/de/schildbach/pte/dto/NearbyStationsResult.java index d07a80fa..830cbe8b 100644 --- a/src/de/schildbach/pte/dto/NearbyStationsResult.java +++ b/src/de/schildbach/pte/dto/NearbyStationsResult.java @@ -30,9 +30,9 @@ public final class NearbyStationsResult } public final Status status; - public final List stations; + public final List stations; - public NearbyStationsResult(final List stations) + public NearbyStationsResult(final List stations) { this.status = Status.OK; this.stations = stations; diff --git a/src/de/schildbach/pte/dto/Station.java b/src/de/schildbach/pte/dto/Station.java deleted file mode 100644 index 2d045e40..00000000 --- a/src/de/schildbach/pte/dto/Station.java +++ /dev/null @@ -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 . - */ - -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; - } -}