mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-17 11:29:49 +00:00
live departures for Austria
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@136 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
dc50e0c403
commit
03324ce2e3
2 changed files with 69 additions and 21 deletions
|
@ -24,17 +24,31 @@ import java.util.Date;
|
|||
*/
|
||||
public final class Departure
|
||||
{
|
||||
final public Date time;
|
||||
final public Date plannedTime;
|
||||
final public Date predictedTime;
|
||||
final public String line;
|
||||
final public int[] lineColors;
|
||||
final public String position;
|
||||
final public int destinationId;
|
||||
final public String destination;
|
||||
|
||||
public Departure(final Date time, final String line, final int[] lineColors, final String position, final int destinationId,
|
||||
public Departure(final Date plannedTime, final Date predictedTime, final String line, final int[] lineColors, final String position,
|
||||
final int destinationId, final String destination)
|
||||
{
|
||||
this.plannedTime = plannedTime;
|
||||
this.predictedTime = predictedTime;
|
||||
this.line = line;
|
||||
this.lineColors = lineColors;
|
||||
this.position = position;
|
||||
this.destinationId = destinationId;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public Departure(final Date plannedTime, final String line, final int[] lineColors, final String position, final int destinationId,
|
||||
final String destination)
|
||||
{
|
||||
this.time = time;
|
||||
this.plannedTime = plannedTime;
|
||||
this.predictedTime = null;
|
||||
this.line = line;
|
||||
this.lineColors = lineColors;
|
||||
this.position = position;
|
||||
|
@ -46,7 +60,9 @@ public final class Departure
|
|||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder("Departure(");
|
||||
builder.append(time != null ? time : "null");
|
||||
builder.append(plannedTime != null ? plannedTime : "null");
|
||||
builder.append(",");
|
||||
builder.append(predictedTime != null ? predictedTime : "null");
|
||||
builder.append(",");
|
||||
builder.append(line != null ? line : "null");
|
||||
builder.append(",");
|
||||
|
@ -60,20 +76,18 @@ public final class Departure
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Departure))
|
||||
return false;
|
||||
final Departure other = (Departure) o;
|
||||
if (!this.time.equals(other.time))
|
||||
if (!nullSafeEquals(this.plannedTime, other.plannedTime))
|
||||
return false;
|
||||
if (this.line == null && other.line != null)
|
||||
if (!nullSafeEquals(this.predictedTime, other.predictedTime))
|
||||
return false;
|
||||
if (other.line == null && this.line != null)
|
||||
return false;
|
||||
if (this.line != null && !this.line.equals(other.line))
|
||||
if (!nullSafeEquals(this.line, other.line))
|
||||
return false;
|
||||
if (this.destinationId != other.destinationId)
|
||||
return false;
|
||||
|
@ -85,14 +99,32 @@ public final class Departure
|
|||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hashCode = time.hashCode();
|
||||
int hashCode = 0;
|
||||
hashCode += nullSafeHashCode(plannedTime);
|
||||
hashCode *= 29;
|
||||
if (line != null)
|
||||
hashCode += line.hashCode();
|
||||
hashCode += nullSafeHashCode(predictedTime);
|
||||
hashCode *= 29;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -403,7 +403,10 @@ public class OebbProvider implements NetworkProvider
|
|||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"depboard-\\w*\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
||||
+ "<td class=\"[\\w ]*\">(\\d{1,2}:\\d{2})</td>.*?" // time
|
||||
+ "<td class=\"[\\w ]*\">(\\d{1,2}:\\d{2})</td>\n" // plannedTime
|
||||
+ "(?:<td class=\"[\\w ]*prognosis[\\w ]*\">\n" //
|
||||
+ "(?: |<span class=\"rtLimit\\d\">(pünktlich|\\d{1,2}:\\d{2})</span>)\n</td>\n" // predictedTime
|
||||
+ ")?.*?" //
|
||||
+ "<img src=\"/img/vs_oebb/(\\w+)_pic\\.gif\"\\s+alt=\".*?\">\\s*(.*?)\\s*</.*?" // type, line
|
||||
+ "<span class=\"bold\">\n" //
|
||||
+ "<a href=\"http://fahrplan\\.oebb\\.at/bin/stboard\\.exe/dn\\?ld=web25&input=[^%]*?(?:%23(\\d+))?&.*?\">" // destinationId
|
||||
|
@ -454,18 +457,31 @@ public class OebbProvider implements NetworkProvider
|
|||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
final String lineType = mDepFine.group(2);
|
||||
final Date plannedTime = parsed.getTime();
|
||||
|
||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(3)));
|
||||
Date predictedTime = null;
|
||||
final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
|
||||
System.out.println("===" + prognosis);
|
||||
if (prognosis != null)
|
||||
{
|
||||
if (prognosis.equals("pünktlich"))
|
||||
predictedTime = plannedTime;
|
||||
else
|
||||
predictedTime = ParserUtils.joinDateTime(currentTime, ParserUtils.parseTime(prognosis));
|
||||
}
|
||||
|
||||
final int destinationId = mDepFine.group(4) != null ? Integer.parseInt(mDepFine.group(4)) : 0;
|
||||
final String lineType = mDepFine.group(3);
|
||||
|
||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(5));
|
||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
||||
|
||||
final String position = mDepFine.group(6) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(6)) : null;
|
||||
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
||||
|
||||
final Departure dep = new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, position,
|
||||
destinationId, destination);
|
||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(6));
|
||||
|
||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
||||
|
||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
|
||||
position, destinationId, destination);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue