diff --git a/enabler/src/de/schildbach/pte/dto/Departure.java b/enabler/src/de/schildbach/pte/dto/Departure.java index 7ff3bf94..b3d56f88 100644 --- a/enabler/src/de/schildbach/pte/dto/Departure.java +++ b/enabler/src/de/schildbach/pte/dto/Departure.java @@ -97,22 +97,7 @@ public final class Departure implements Serializable @Override public int hashCode() { - int hashCode = 0; - hashCode += nullSafeHashCode(plannedTime); - hashCode *= 29; - hashCode += nullSafeHashCode(predictedTime); - hashCode *= 29; - hashCode += nullSafeHashCode(line); - hashCode *= 29; - hashCode += nullSafeHashCode(destination); - return hashCode; - } - - private int nullSafeHashCode(final Object o) - { - if (o == null) - return 0; - return o.hashCode(); + return Objects.hashCode(plannedTime, predictedTime, line, destination); } public static final Comparator TIME_COMPARATOR = new Comparator() diff --git a/enabler/src/de/schildbach/pte/dto/Fare.java b/enabler/src/de/schildbach/pte/dto/Fare.java index 5f25ccbb..a43c1f00 100644 --- a/enabler/src/de/schildbach/pte/dto/Fare.java +++ b/enabler/src/de/schildbach/pte/dto/Fare.java @@ -71,4 +71,10 @@ public final class Fare implements Serializable return false; return true; } + + @Override + public int hashCode() + { + return Objects.hashCode(network, type, currency, fare, unitName, units); + } } diff --git a/enabler/src/de/schildbach/pte/dto/Line.java b/enabler/src/de/schildbach/pte/dto/Line.java index 20f79903..45808a96 100644 --- a/enabler/src/de/schildbach/pte/dto/Line.java +++ b/enabler/src/de/schildbach/pte/dto/Line.java @@ -102,7 +102,7 @@ public final class Line implements Serializable, Comparable @Override public int hashCode() { - return nullSafeHashCode(label); + return Objects.hashCode(label); } public int compareTo(final Line other) @@ -117,11 +117,4 @@ public final class Line implements Serializable, Comparable return this.label.compareTo(other.label); } - - private int nullSafeHashCode(final Object o) - { - if (o == null) - return 0; - return o.hashCode(); - } } diff --git a/enabler/src/de/schildbach/pte/dto/LineDestination.java b/enabler/src/de/schildbach/pte/dto/LineDestination.java index 16c3d234..4dd888e1 100644 --- a/enabler/src/de/schildbach/pte/dto/LineDestination.java +++ b/enabler/src/de/schildbach/pte/dto/LineDestination.java @@ -64,17 +64,6 @@ public final class LineDestination implements Serializable @Override public int hashCode() { - int hashCode = 0; - hashCode += nullSafeHashCode(line); - hashCode *= 29; - hashCode += nullSafeHashCode(destination); - return hashCode; - } - - private int nullSafeHashCode(final Object o) - { - if (o == null) - return 0; - return o.hashCode(); + return Objects.hashCode(line, destination); } } diff --git a/enabler/src/de/schildbach/pte/dto/Location.java b/enabler/src/de/schildbach/pte/dto/Location.java index f3490854..4f1f0983 100644 --- a/enabler/src/de/schildbach/pte/dto/Location.java +++ b/enabler/src/de/schildbach/pte/dto/Location.java @@ -185,26 +185,9 @@ public final class Location implements Serializable @Override public int hashCode() { - int hashCode = 0; - hashCode += type.hashCode(); - hashCode *= 29; if (id != null) - { - hashCode += id.hashCode(); - } - else if (lat != 0 || lon != 0) - { - hashCode += lat; - hashCode *= 29; - hashCode += lon; - } - return hashCode; - } - - private int nullSafeHashCode(final Object o) - { - if (o == null) - return 0; - return o.hashCode(); + return Objects.hashCode(type, id); + else + return Objects.hashCode(type, lat, lon); } } diff --git a/enabler/src/de/schildbach/pte/dto/Point.java b/enabler/src/de/schildbach/pte/dto/Point.java index bf8fc2ca..7a1fdd17 100644 --- a/enabler/src/de/schildbach/pte/dto/Point.java +++ b/enabler/src/de/schildbach/pte/dto/Point.java @@ -19,6 +19,8 @@ package de.schildbach.pte.dto; import java.io.Serializable; +import com.google.common.base.Objects; + /** * @author Andreas Schildbach */ @@ -61,6 +63,6 @@ public final class Point implements Serializable @Override public int hashCode() { - return lat + 27 * lon; + return Objects.hashCode(lat, lon); } } diff --git a/enabler/src/de/schildbach/pte/dto/Position.java b/enabler/src/de/schildbach/pte/dto/Position.java index a49d6f0b..f70bb684 100644 --- a/enabler/src/de/schildbach/pte/dto/Position.java +++ b/enabler/src/de/schildbach/pte/dto/Position.java @@ -63,6 +63,12 @@ public final class Position implements Serializable return true; } + @Override + public int hashCode() + { + return Objects.hashCode(name, section); + } + @Override public String toString() { @@ -71,20 +77,4 @@ public final class Position implements Serializable builder.append(section); return builder.toString(); } - - @Override - public int hashCode() - { - int hashCode = 0; - hashCode += name.hashCode(); - hashCode += nullSafeHashCode(section); - return hashCode; - } - - private int nullSafeHashCode(final Object o) - { - if (o == null) - return 0; - return o.hashCode(); - } } diff --git a/enabler/src/de/schildbach/pte/dto/StationDepartures.java b/enabler/src/de/schildbach/pte/dto/StationDepartures.java index 06202d68..f9b415ce 100644 --- a/enabler/src/de/schildbach/pte/dto/StationDepartures.java +++ b/enabler/src/de/schildbach/pte/dto/StationDepartures.java @@ -67,4 +67,10 @@ public final class StationDepartures implements Serializable return false; return true; } + + @Override + public int hashCode() + { + return Objects.hashCode(location, departures, lines); + } } diff --git a/enabler/src/de/schildbach/pte/dto/Stop.java b/enabler/src/de/schildbach/pte/dto/Stop.java index 9fc01f4c..1a0aa7ad 100644 --- a/enabler/src/de/schildbach/pte/dto/Stop.java +++ b/enabler/src/de/schildbach/pte/dto/Stop.java @@ -252,4 +252,12 @@ public final class Stop implements Serializable return false; return true; } + + @Override + public int hashCode() + { + return Objects.hashCode(location, plannedArrivalTime, predictedArrivalTime, plannedArrivalPosition, predictedArrivalPosition, + arrivalCancelled, plannedDepartureTime, predictedDepartureTime, plannedDeparturePosition, predictedDeparturePosition, + departureCancelled); + } } diff --git a/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java b/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java index 93690aac..532d1615 100644 --- a/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java +++ b/enabler/src/de/schildbach/pte/dto/SuggestedLocation.java @@ -70,7 +70,7 @@ public final class SuggestedLocation implements Serializable, Comparable