diff --git a/src/de/schildbach/pte/AbstractEfaProvider.java b/src/de/schildbach/pte/AbstractEfaProvider.java index fad6ffd3..081f952e 100644 --- a/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/src/de/schildbach/pte/AbstractEfaProvider.java @@ -40,6 +40,7 @@ import org.xmlpull.v1.XmlPullParserFactory; import de.schildbach.pte.dto.Connection; import de.schildbach.pte.dto.Departure; import de.schildbach.pte.dto.GetConnectionDetailsResult; +import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.NearbyStationsResult; @@ -678,9 +679,35 @@ public abstract class AbstractEfaProvider implements NetworkProvider final Calendar departureTime = new GregorianCalendar(); departureTime.setTimeZone(timeZone()); + + final List lines = new ArrayList(4); + + XmlPullUtil.jumpToStartTag(pp, null, "itdServingLines"); + if (!pp.isEmptyElementTag()) + { + XmlPullUtil.enter(pp); + while (XmlPullUtil.test(pp, "itdServingLine")) + { + final String line = parseLine(pp.getAttributeValue(null, "motType"), pp.getAttributeValue(null, "number"), pp + .getAttributeValue(null, "number")); + final String destination = normalizeLocationName(pp.getAttributeValue(null, "direction")); + final String destinationIdStr = pp.getAttributeValue(null, "destID"); + final int destinationId = destinationIdStr.length() > 0 ? Integer.parseInt(destinationIdStr) : 0; + lines.add(new Line(line, lineColors(line), destinationId, destination)); + + XmlPullUtil.enter(pp); + XmlPullUtil.exit(pp); + } + XmlPullUtil.exit(pp); + } + else + { + XmlPullUtil.next(pp); + } + final List departures = new ArrayList(8); - XmlPullUtil.jumpToStartTag(pp, null, "itdDepartureList"); + XmlPullUtil.require(pp, "itdDepartureList"); while (XmlPullUtil.nextStartTagInsideTree(pp, null, "itdDeparture")) { if (Integer.parseInt(pp.getAttributeValue(null, "stopID")) == locationId) @@ -707,7 +734,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider XmlPullUtil.skipRestOfTree(pp); } - return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures, lines); } else if ("notidentified".equals(nameState)) { diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index 681259ee..a6f177c4 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -504,7 +504,7 @@ public final class BahnProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, null), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, null), departures, null); } @Override diff --git a/src/de/schildbach/pte/BvgProvider.java b/src/de/schildbach/pte/BvgProvider.java index 3416862f..02c42aa5 100644 --- a/src/de/schildbach/pte/BvgProvider.java +++ b/src/de/schildbach/pte/BvgProvider.java @@ -531,7 +531,7 @@ public final class BvgProvider implements NetworkProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures, null); } else { diff --git a/src/de/schildbach/pte/NasaProvider.java b/src/de/schildbach/pte/NasaProvider.java index bb9572f3..d1b542ca 100644 --- a/src/de/schildbach/pte/NasaProvider.java +++ b/src/de/schildbach/pte/NasaProvider.java @@ -207,7 +207,7 @@ public class NasaProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures, null); } else { diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index 835ef7bb..db1b1c9f 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -535,7 +535,7 @@ public class OebbProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures, null); } catch (final JSONException x) { diff --git a/src/de/schildbach/pte/RmvProvider.java b/src/de/schildbach/pte/RmvProvider.java index 476edba1..b97a6deb 100644 --- a/src/de/schildbach/pte/RmvProvider.java +++ b/src/de/schildbach/pte/RmvProvider.java @@ -520,7 +520,7 @@ public class RmvProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures, null); } else { diff --git a/src/de/schildbach/pte/SbbProvider.java b/src/de/schildbach/pte/SbbProvider.java index 8f43cbe5..7666478e 100644 --- a/src/de/schildbach/pte/SbbProvider.java +++ b/src/de/schildbach/pte/SbbProvider.java @@ -172,7 +172,7 @@ public class SbbProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, locationId, 0, 0, location), departures, null); } else { diff --git a/src/de/schildbach/pte/SncbProvider.java b/src/de/schildbach/pte/SncbProvider.java index 62e8b651..9e7fe046 100644 --- a/src/de/schildbach/pte/SncbProvider.java +++ b/src/de/schildbach/pte/SncbProvider.java @@ -156,7 +156,7 @@ public class SncbProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures, null); } else { diff --git a/src/de/schildbach/pte/VgsProvider.java b/src/de/schildbach/pte/VgsProvider.java index 80b13798..a2cee360 100644 --- a/src/de/schildbach/pte/VgsProvider.java +++ b/src/de/schildbach/pte/VgsProvider.java @@ -207,7 +207,7 @@ public class VgsProvider extends AbstractHafasProvider } } - return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures); + return new QueryDeparturesResult(new Location(LocationType.STATION, Integer.parseInt(stationId), 0, 0, location), departures, null); } else { diff --git a/src/de/schildbach/pte/dto/Line.java b/src/de/schildbach/pte/dto/Line.java new file mode 100644 index 00000000..0e9b6e5d --- /dev/null +++ b/src/de/schildbach/pte/dto/Line.java @@ -0,0 +1,95 @@ +/* + * 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 Line +{ + final public String line; + final public int[] lineColors; + final public int destinationId; + final public String destination; + + public Line(final String line, final int[] lineColors, final int destinationId, final String destination) + { + this.line = line; + this.lineColors = lineColors; + this.destinationId = destinationId; + this.destination = destination; + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder("Line("); + builder.append(line != null ? line : "null"); + builder.append(","); + builder.append(destinationId); + builder.append(","); + builder.append(destination != null ? destination : "null"); + builder.append(")"); + return builder.toString(); + } + + @Override + public boolean equals(final Object o) + { + if (o == this) + return true; + if (!(o instanceof Line)) + return false; + final Line other = (Line) o; + if (!nullSafeEquals(this.line, other.line)) + return false; + if (this.destinationId != other.destinationId) + return false; + if (!this.destination.equals(other.destination)) + return false; + return true; + } + + @Override + public int hashCode() + { + int hashCode = 0; + hashCode += nullSafeHashCode(line); + hashCode *= 29; + hashCode += destinationId; + hashCode *= 29; + hashCode += destination.hashCode(); + return hashCode; + } + + private boolean nullSafeEquals(final Object o1, final Object o2) + { + if (o1 == null && o2 == null) + return true; + if (o1 != null && o1.equals(o2)) + return true; + return false; + } + + private int nullSafeHashCode(final Object o) + { + if (o == null) + return 0; + return o.hashCode(); + } +} diff --git a/src/de/schildbach/pte/dto/QueryDeparturesResult.java b/src/de/schildbach/pte/dto/QueryDeparturesResult.java index 3fc30fef..ed7559b2 100644 --- a/src/de/schildbach/pte/dto/QueryDeparturesResult.java +++ b/src/de/schildbach/pte/dto/QueryDeparturesResult.java @@ -32,12 +32,14 @@ public final class QueryDeparturesResult public final Status status; public final Location location; public final List departures; + public final List lines; - public QueryDeparturesResult(final Location location, final List departures) + public QueryDeparturesResult(final Location location, final List departures, final List lines) { this.status = Status.OK; this.location = location; this.departures = departures; + this.lines = lines; } public QueryDeparturesResult(final Status status, final int locationId) @@ -45,5 +47,6 @@ public final class QueryDeparturesResult this.status = status; this.location = new Location(LocationType.STATION, locationId, 0, 0, null); this.departures = null; + this.lines = null; } }