diff --git a/enabler/src/de/schildbach/pte/dto/Departure.java b/enabler/src/de/schildbach/pte/dto/Departure.java index fbe74a65..7ff3bf94 100644 --- a/enabler/src/de/schildbach/pte/dto/Departure.java +++ b/enabler/src/de/schildbach/pte/dto/Departure.java @@ -21,6 +21,8 @@ import java.io.Serializable; import java.util.Comparator; import java.util.Date; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -81,13 +83,13 @@ public final class Departure implements Serializable if (!(o instanceof Departure)) return false; final Departure other = (Departure) o; - if (!nullSafeEquals(this.plannedTime, other.plannedTime)) + if (!Objects.equal(this.plannedTime, other.plannedTime)) return false; - if (!nullSafeEquals(this.predictedTime, other.predictedTime)) + if (!Objects.equal(this.predictedTime, other.predictedTime)) return false; - if (!nullSafeEquals(this.line, other.line)) + if (!Objects.equal(this.line, other.line)) return false; - if (!nullSafeEquals(this.destination, other.destination)) + if (!Objects.equal(this.destination, other.destination)) return false; return true; } @@ -106,15 +108,6 @@ public final class Departure implements Serializable 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) diff --git a/enabler/src/de/schildbach/pte/dto/Fare.java b/enabler/src/de/schildbach/pte/dto/Fare.java index 21f468d7..5f25ccbb 100644 --- a/enabler/src/de/schildbach/pte/dto/Fare.java +++ b/enabler/src/de/schildbach/pte/dto/Fare.java @@ -20,6 +20,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; import java.util.Currency; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -46,4 +48,27 @@ public final class Fare implements Serializable this.unitName = unitName; this.units = units; } + + @Override + public boolean equals(final Object o) + { + if (o == this) + return true; + if (!(o instanceof Fare)) + return false; + final Fare other = (Fare) o; + if (!Objects.equal(this.network, other.network)) + return false; + if (!Objects.equal(this.type, other.type)) + return false; + if (!Objects.equal(this.currency, other.currency)) + return false; + if (this.fare != other.fare) + return false; + if (!Objects.equal(this.unitName, other.unitName)) + return false; + if (!Objects.equal(this.units, other.units)) + return false; + return true; + } } diff --git a/enabler/src/de/schildbach/pte/dto/Line.java b/enabler/src/de/schildbach/pte/dto/Line.java index fb804ff2..20f79903 100644 --- a/enabler/src/de/schildbach/pte/dto/Line.java +++ b/enabler/src/de/schildbach/pte/dto/Line.java @@ -20,6 +20,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; import java.util.Set; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -94,7 +96,7 @@ public final class Line implements Serializable, Comparable if (!(o instanceof Line)) return false; final Line other = (Line) o; - return nullSafeEquals(this.label, other.label); + return Objects.equal(this.label, other.label); } @Override @@ -116,15 +118,6 @@ public final class Line implements Serializable, Comparable return this.label.compareTo(other.label); } - 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) diff --git a/enabler/src/de/schildbach/pte/dto/LineDestination.java b/enabler/src/de/schildbach/pte/dto/LineDestination.java index 102a8f4a..16c3d234 100644 --- a/enabler/src/de/schildbach/pte/dto/LineDestination.java +++ b/enabler/src/de/schildbach/pte/dto/LineDestination.java @@ -19,6 +19,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -52,9 +54,9 @@ public final class LineDestination implements Serializable if (!(o instanceof LineDestination)) return false; final LineDestination other = (LineDestination) o; - if (!nullSafeEquals(this.line, other.line)) + if (!Objects.equal(this.line, other.line)) return false; - if (!nullSafeEquals(this.destination, other.destination)) + if (!Objects.equal(this.destination, other.destination)) return false; return true; } @@ -69,15 +71,6 @@ public final class LineDestination implements Serializable 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) diff --git a/enabler/src/de/schildbach/pte/dto/Location.java b/enabler/src/de/schildbach/pte/dto/Location.java index 51d93293..f3490854 100644 --- a/enabler/src/de/schildbach/pte/dto/Location.java +++ b/enabler/src/de/schildbach/pte/dto/Location.java @@ -20,6 +20,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; import java.util.Arrays; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -165,17 +167,17 @@ public final class Location implements Serializable if (!(o instanceof Location)) return false; final Location other = (Location) o; - if (this.type != other.type) + if (!Objects.equal(this.type, other.type)) return false; if (this.id != null) - return this.id.equals(other.id); + return Objects.equal(this.id, other.id); if (this.lat != 0 && this.lon != 0) return this.lat == other.lat && this.lon == other.lon; // only discriminate by name/place if no ids are given - if (!nullSafeEquals(this.name, other.name)) + if (!Objects.equal(this.name, other.name)) return false; - if (!nullSafeEquals(this.place, other.place)) + if (!Objects.equal(this.place, other.place)) return false; return true; } @@ -199,15 +201,6 @@ public final class Location implements Serializable 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) diff --git a/enabler/src/de/schildbach/pte/dto/Position.java b/enabler/src/de/schildbach/pte/dto/Position.java index 0a1397c1..a49d6f0b 100644 --- a/enabler/src/de/schildbach/pte/dto/Position.java +++ b/enabler/src/de/schildbach/pte/dto/Position.java @@ -19,6 +19,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -46,15 +48,6 @@ public final class Position implements Serializable this.section = section; } - @Override - public String toString() - { - final StringBuilder builder = new StringBuilder(name); - if (section != null) - builder.append(section); - return builder.toString(); - } - @Override public boolean equals(final Object o) { @@ -63,13 +56,22 @@ public final class Position implements Serializable if (!(o instanceof Position)) return false; final Position other = (Position) o; - if (!this.name.equals(other.name)) + if (!Objects.equal(this.name, other.name)) return false; - if (!nullSafeEquals(this.section, other.section)) + if (!Objects.equal(this.section, other.section)) return false; return true; } + @Override + public String toString() + { + final StringBuilder builder = new StringBuilder(name); + if (section != null) + builder.append(section); + return builder.toString(); + } + @Override public int hashCode() { @@ -79,15 +81,6 @@ public final class Position implements Serializable 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) diff --git a/enabler/src/de/schildbach/pte/dto/StationDepartures.java b/enabler/src/de/schildbach/pte/dto/StationDepartures.java index e94ca080..06202d68 100644 --- a/enabler/src/de/schildbach/pte/dto/StationDepartures.java +++ b/enabler/src/de/schildbach/pte/dto/StationDepartures.java @@ -20,6 +20,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; import java.util.List; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -48,4 +50,21 @@ public final class StationDepartures implements Serializable builder.append("]"); return builder.toString(); } + + @Override + public boolean equals(final Object o) + { + if (o == this) + return true; + if (!(o instanceof StationDepartures)) + return false; + final StationDepartures other = (StationDepartures) o; + if (!Objects.equal(this.location, other.location)) + return false; + if (!Objects.equal(this.departures, other.departures)) + return false; + if (!Objects.equal(this.lines, other.lines)) + return false; + return true; + } } diff --git a/enabler/src/de/schildbach/pte/dto/Stop.java b/enabler/src/de/schildbach/pte/dto/Stop.java index 325905fa..9fc01f4c 100644 --- a/enabler/src/de/schildbach/pte/dto/Stop.java +++ b/enabler/src/de/schildbach/pte/dto/Stop.java @@ -20,6 +20,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; import java.util.Date; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -217,4 +219,37 @@ public final class Stop implements Serializable builder.append(")"); return builder.toString(); } + + @Override + public boolean equals(final Object o) + { + if (o == this) + return true; + if (!(o instanceof Stop)) + return false; + final Stop other = (Stop) o; + if (!Objects.equal(this.location, other.location)) + return false; + if (!Objects.equal(this.plannedArrivalTime, other.plannedArrivalTime)) + return false; + if (!Objects.equal(this.predictedArrivalTime, other.predictedArrivalTime)) + return false; + if (!Objects.equal(this.plannedArrivalPosition, other.plannedArrivalPosition)) + return false; + if (!Objects.equal(this.predictedArrivalPosition, other.predictedArrivalPosition)) + return false; + if (this.arrivalCancelled != other.arrivalCancelled) + return false; + if (!Objects.equal(this.plannedDepartureTime, other.plannedDepartureTime)) + return false; + if (!Objects.equal(this.predictedDepartureTime, other.predictedDepartureTime)) + return false; + if (!Objects.equal(this.plannedDeparturePosition, other.plannedDeparturePosition)) + return false; + if (!Objects.equal(this.predictedDeparturePosition, other.predictedDeparturePosition)) + return false; + if (this.departureCancelled != other.departureCancelled) + return false; + return true; + } } diff --git a/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java b/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java index e4a09370..93690aac 100644 --- a/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java +++ b/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java @@ -19,6 +19,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -62,7 +64,7 @@ public final class SuggestedLocation implements Serializable, Comparable