From 4da349339d6ebb415a277eff38985334985f42b9 Mon Sep 17 00:00:00 2001 From: "andreas.schildbach@gmail.com" Date: Sun, 6 Mar 2011 10:40:11 +0000 Subject: [PATCH] separate Line class for lines without destination git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@524 0924bc21-9374-b0fa-ee44-9ff1593b38f0 --- .../schildbach/pte/AbstractEfaProvider.java | 12 ++-- .../schildbach/pte/AbstractHafasProvider.java | 8 ++- src/de/schildbach/pte/BahnProvider.java | 4 +- src/de/schildbach/pte/BvgProvider.java | 4 +- src/de/schildbach/pte/OebbProvider.java | 4 +- src/de/schildbach/pte/RmvProvider.java | 4 +- src/de/schildbach/pte/dto/Connection.java | 8 +-- src/de/schildbach/pte/dto/Line.java | 61 +++++++++++++++++++ 8 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 src/de/schildbach/pte/dto/Line.java diff --git a/src/de/schildbach/pte/AbstractEfaProvider.java b/src/de/schildbach/pte/AbstractEfaProvider.java index 437a8cb2..3786eeb3 100644 --- a/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/src/de/schildbach/pte/AbstractEfaProvider.java @@ -42,6 +42,7 @@ import de.schildbach.pte.dto.Departure; import de.schildbach.pte.dto.Fare; import de.schildbach.pte.dto.Fare.Type; import de.schildbach.pte.dto.GetConnectionDetailsResult; +import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.LineDestination; import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; @@ -903,8 +904,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider { final Location assignedLocation = processItdOdvAssignedStop(pp); if (findStationDepartures(result.stationDepartures, assignedLocation.id) == null) - result.stationDepartures - .add(new StationDepartures(assignedLocation, new LinkedList(), new LinkedList())); + result.stationDepartures.add(new StationDepartures(assignedLocation, new LinkedList(), + new LinkedList())); } XmlPullUtil.exit(pp, "itdOdvAssignedStops"); } @@ -1355,12 +1356,13 @@ public abstract class AbstractEfaProvider implements NetworkProvider final Location destination = destinationIdStr.length() > 0 ? new Location(LocationType.STATION, Integer.parseInt(destinationIdStr), null, destinationName) : new Location(LocationType.ANY, 0, null, destinationName); - String line; + final String lineStr; if ("AST".equals(pp.getAttributeValue(null, "symbol"))) - line = "BAST"; + lineStr = "BAST"; else - line = parseLine(pp.getAttributeValue(null, "motType"), pp.getAttributeValue(null, "shortname"), + lineStr = parseLine(pp.getAttributeValue(null, "motType"), pp.getAttributeValue(null, "shortname"), pp.getAttributeValue(null, "name"), null); + final Line line = new Line(lineStr, lineColors(lineStr)); XmlPullUtil.enter(pp, "itdMeansOfTransport"); XmlPullUtil.exit(pp, "itdMeansOfTransport"); diff --git a/src/de/schildbach/pte/AbstractHafasProvider.java b/src/de/schildbach/pte/AbstractHafasProvider.java index a7896eb0..cc09a420 100644 --- a/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/src/de/schildbach/pte/AbstractHafasProvider.java @@ -38,6 +38,7 @@ import org.xmlpull.v1.XmlPullParserFactory; import de.schildbach.pte.dto.Connection; 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; @@ -365,7 +366,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider XmlPullUtil.exit(pp); // journey - String line = null; + final Line line; Location destination = null; int min = 0; @@ -406,7 +407,8 @@ public abstract class AbstractHafasProvider implements NetworkProvider XmlPullUtil.exit(pp); XmlPullUtil.exit(pp); - line = _normalizeLine(category, name, longCategory); + final String lineStr = _normalizeLine(category, name, longCategory); + line = new Line(lineStr, lineColors(lineStr)); } else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute")) { @@ -416,6 +418,8 @@ public abstract class AbstractHafasProvider implements NetworkProvider min = parseDuration(XmlPullUtil.text(pp).substring(3, 8)); XmlPullUtil.exit(pp); XmlPullUtil.exit(pp); + + line = null; } else { diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index 0eee1452..54e5dd2e 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -32,6 +32,7 @@ import java.util.regex.Pattern; 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; @@ -349,7 +350,8 @@ public final class BahnProvider extends AbstractHafasProvider if (mDetFine.group(2) != null) { - final String line = normalizeLine(ParserUtils.resolveEntities(mDetFine.group(2))); + final String lineStr = normalizeLine(ParserUtils.resolveEntities(mDetFine.group(2))); + final Line line = new Line(lineStr, lineColors(lineStr)); final Date departureTime = ParserUtils.parseTime(mDetFine.group(3)); diff --git a/src/de/schildbach/pte/BvgProvider.java b/src/de/schildbach/pte/BvgProvider.java index a611f128..ddc3e945 100644 --- a/src/de/schildbach/pte/BvgProvider.java +++ b/src/de/schildbach/pte/BvgProvider.java @@ -34,6 +34,7 @@ import java.util.regex.Pattern; 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; @@ -502,7 +503,8 @@ public final class BvgProvider extends AbstractHafasProvider final String departurePosition = mDetFine.group(7); - final String line = normalizeLine(ParserUtils.resolveEntities(mDetFine.group(8))); + final String lineStr = normalizeLine(ParserUtils.resolveEntities(mDetFine.group(8))); + final Line line = new Line(lineStr, lineColors(lineStr)); final String[] destinationPlaceAndName = splitNameAndPlace(ParserUtils.resolveEntities(mDetFine.group(9))); diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index dbb92c47..acfcc35a 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -35,6 +35,7 @@ import org.json.JSONObject; 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.QueryConnectionsResult; @@ -455,7 +456,8 @@ public class OebbProvider extends AbstractHafasProvider final String departurePosition = mDetFine.group(5) != null ? ParserUtils.resolveEntities(mDetFine.group(5)) : null; - final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDetFine.group(7))); + final String lineStr = normalizeLine(lineType, ParserUtils.resolveEntities(mDetFine.group(7))); + final Line line = new Line(lineStr, lineColors(lineStr)); if (arrivalId == 0) throw new IllegalStateException("arrivalId"); diff --git a/src/de/schildbach/pte/RmvProvider.java b/src/de/schildbach/pte/RmvProvider.java index 521905b5..993a66d5 100644 --- a/src/de/schildbach/pte/RmvProvider.java +++ b/src/de/schildbach/pte/RmvProvider.java @@ -33,6 +33,7 @@ import java.util.regex.Pattern; 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.QueryConnectionsResult; @@ -358,7 +359,8 @@ public class RmvProvider extends AbstractHafasProvider final String min = mDetFine.group(7); if (min == null) { - final String line = normalizeLine(ParserUtils.resolveEntities(mDetFine.group(1))); + final String lineStr = normalizeLine(ParserUtils.resolveEntities(mDetFine.group(1))); + final Line line = new Line(lineStr, lineColors(lineStr)); final Location destination = new Location(LocationType.ANY, 0, null, ParserUtils.resolveEntities(mDetFine.group(2))); diff --git a/src/de/schildbach/pte/dto/Connection.java b/src/de/schildbach/pte/dto/Connection.java index 35b39a2b..f0cc295d 100644 --- a/src/de/schildbach/pte/dto/Connection.java +++ b/src/de/schildbach/pte/dto/Connection.java @@ -89,7 +89,7 @@ public final class Connection implements Serializable public final static class Trip extends Part { - public final String line; + public final Line line; public final Location destination; public final Date departureTime; public final String departurePosition; @@ -97,9 +97,9 @@ public final class Connection implements Serializable public final String arrivalPosition; public final List intermediateStops; - public Trip(final String line, final Location destination, final Date departureTime, final String departurePosition, - final Location departure, final Date arrivalTime, final String arrivalPosition, final Location arrival, - final List intermediateStops, final List path) + public Trip(final Line line, final Location destination, final Date departureTime, final String departurePosition, final Location departure, + final Date arrivalTime, final String arrivalPosition, final Location arrival, final List intermediateStops, + final List path) { super(departure, arrival, path); diff --git a/src/de/schildbach/pte/dto/Line.java b/src/de/schildbach/pte/dto/Line.java new file mode 100644 index 00000000..526654e0 --- /dev/null +++ b/src/de/schildbach/pte/dto/Line.java @@ -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 . + */ + +package de.schildbach.pte.dto; + +import java.io.Serializable; + +/** + * @author Andreas Schildbach + */ +public final class Line implements Serializable +{ + final public String label; + final public int[] colors; + + public Line(final String label, final int[] colors) + { + this.label = label; + this.colors = colors; + } + + @Override + public String toString() + { + final StringBuilder builder = new StringBuilder("Line("); + builder.append(label); + 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; + return (this.label.equals(other.label)); + } + + @Override + public int hashCode() + { + return label.hashCode(); + } +}