diff --git a/.classpath b/.classpath index bb16dce..b3366ba 100644 --- a/.classpath +++ b/.classpath @@ -4,6 +4,7 @@ + diff --git a/AndroidManifest.xml b/AndroidManifest.xml index fe7e62f..36b3f3f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="8" + android:versionName="1.0.3" > diff --git a/libs/commons-lang3-3.1.jar b/libs/commons-lang3-3.1.jar new file mode 100644 index 0000000..a85e539 Binary files /dev/null and b/libs/commons-lang3-3.1.jar differ diff --git a/src/com/dougkeen/bart/EtdContentHandler.java b/src/com/dougkeen/bart/EtdContentHandler.java index adde7a8..87dadba 100644 --- a/src/com/dougkeen/bart/EtdContentHandler.java +++ b/src/com/dougkeen/bart/EtdContentHandler.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -53,7 +54,7 @@ public class EtdContentHandler extends DefaultHandler { if (localName.equals("estimate")) { currentDeparture = new Departure(); currentDeparture.setDestination(Station - .getByAbbreviation(currentDestination)); + .getByAbbreviation(currentDestination)); } } @@ -67,17 +68,17 @@ public class EtdContentHandler extends DefaultHandler { } else if (localName.equals("abbreviation")) { currentDestination = currentValue; } else if (localName.equals("minutes")) { - if (currentValue.equalsIgnoreCase("arrived")) { - currentDeparture.setMinutes(0); - } else { + if (StringUtils.isNumeric(currentValue)) { currentDeparture.setMinutes(Integer.parseInt(currentValue)); + } else { + currentDeparture.setMinutes(0); } } else if (localName.equals("platform")) { currentDeparture.setPlatform(currentValue); } else if (localName.equals("direction")) { currentDeparture.setDirection(currentValue); } else if (localName.equals("length")) { - currentDeparture.setTrainLength(Integer.parseInt(currentValue)); + currentDeparture.setTrainLength(currentValue); } else if (localName.equals("color")) { try { if (currentValue.equalsIgnoreCase("WHITE")) { diff --git a/src/com/dougkeen/bart/data/Departure.java b/src/com/dougkeen/bart/data/Departure.java index d0a1da6..8e3224d 100644 --- a/src/com/dougkeen/bart/data/Departure.java +++ b/src/com/dougkeen/bart/data/Departure.java @@ -15,7 +15,7 @@ public class Departure implements Parcelable, Comparable { public Departure(String destinationAbbr, String destinationColor, String platform, String direction, boolean bikeAllowed, - int trainLength, int minutes) { + String trainLength, int minutes) { super(); this.destination = Station.getByAbbreviation(destinationAbbr); this.destinationColor = destinationColor; @@ -36,7 +36,7 @@ public class Departure implements Parcelable, Comparable { private String platform; private String direction; private boolean bikeAllowed; - private int trainLength; + private String trainLength; private boolean requiresTransfer; private int minutes; @@ -104,11 +104,11 @@ public class Departure implements Parcelable, Comparable { this.bikeAllowed = bikeAllowed; } - public int getTrainLength() { + public String getTrainLength() { return trainLength; } - public void setTrainLength(int trainLength) { + public void setTrainLength(String trainLength) { this.trainLength = trainLength; } @@ -185,10 +185,10 @@ public class Departure implements Parcelable, Comparable { return; } - final long newMin = Math - .max(getMinEstimate(), departure.getMinEstimate()); - final long newMax = Math - .min(getMaxEstimate(), departure.getMaxEstimate()); + final long newMin = Math.max(getMinEstimate(), + departure.getMinEstimate()); + final long newMax = Math.min(getMaxEstimate(), + departure.getMaxEstimate()); if (newMax > newMin) { // We can never have 0 or negative uncertainty setMinEstimate(newMin); setMaxEstimate(newMax); @@ -196,8 +196,32 @@ public class Departure implements Parcelable, Comparable { } public int compareTo(Departure another) { - return (this.getMinutes() > another.getMinutes()) ? 1 : ( - (this.getMinutes() == another.getMinutes()) ? 0 : -1); + return (this.getMinutes() > another.getMinutes()) ? 1 : ((this + .getMinutes() == another.getMinutes()) ? 0 : -1); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (bikeAllowed ? 1231 : 1237); + result = prime * result + + ((destination == null) ? 0 : destination.hashCode()); + result = prime + * result + + ((destinationColor == null) ? 0 : destinationColor.hashCode()); + result = prime * result + + ((direction == null) ? 0 : direction.hashCode()); + result = prime * result + ((line == null) ? 0 : line.hashCode()); + result = prime * result + (int) (maxEstimate ^ (maxEstimate >>> 32)); + result = prime * result + (int) (minEstimate ^ (minEstimate >>> 32)); + result = prime * result + minutes; + result = prime * result + + ((platform == null) ? 0 : platform.hashCode()); + result = prime * result + (requiresTransfer ? 1231 : 1237); + result = prime * result + + ((trainLength == null) ? 0 : trainLength.hashCode()); + return result; } @Override @@ -223,16 +247,27 @@ public class Departure implements Parcelable, Comparable { return false; } else if (!direction.equals(other.direction)) return false; + if (line != other.line) + return false; + if (maxEstimate != other.maxEstimate) + return false; + if (minEstimate != other.minEstimate) + return false; + if (minutes != other.minutes) + return false; if (platform == null) { if (other.platform != null) return false; } else if (!platform.equals(other.platform)) return false; - if (trainLength != other.trainLength) + if (requiresTransfer != other.requiresTransfer) return false; - - long delta = (getMinEstimate() - other.getMinEstimate()); - return delta > -60000 && delta < 60000; + if (trainLength == null) { + if (other.trainLength != null) + return false; + } else if (!trainLength.equals(other.trainLength)) + return false; + return true; } public String getCountdownText() { @@ -279,7 +314,7 @@ public class Departure implements Parcelable, Comparable { dest.writeString(platform); dest.writeString(direction); dest.writeByte((byte) (bikeAllowed ? 1 : 0)); - dest.writeInt(trainLength); + dest.writeString(trainLength); dest.writeByte((byte) (requiresTransfer ? 1 : 0)); dest.writeInt(minutes); dest.writeLong(minEstimate); @@ -292,7 +327,7 @@ public class Departure implements Parcelable, Comparable { platform = in.readString(); direction = in.readString(); bikeAllowed = in.readByte() != 0; - trainLength = in.readInt(); + trainLength = in.readString(); requiresTransfer = in.readByte() != 0; minutes = in.readInt(); minEstimate = in.readLong();