From 2de9f14e4daaf4b9fefc1c3e62c4816f0db90f6b Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Thu, 24 Nov 2016 13:22:29 +0100 Subject: [PATCH] LineDestination.equals(): Compare all fields of destination location. This works around a rare case of Hafas destinations having IDs of other locations. --- .../schildbach/pte/dto/LineDestination.java | 3 +++ .../src/de/schildbach/pte/dto/Location.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/enabler/src/de/schildbach/pte/dto/LineDestination.java b/enabler/src/de/schildbach/pte/dto/LineDestination.java index 0503d8d3..332f5227 100644 --- a/enabler/src/de/schildbach/pte/dto/LineDestination.java +++ b/enabler/src/de/schildbach/pte/dto/LineDestination.java @@ -50,6 +50,9 @@ public final class LineDestination implements Serializable { return false; if (!Objects.equal(this.destination, other.destination)) return false; + // This workaround is necessary because in rare cases destinations have IDs of other locations. + if (this.destination != null && !this.destination.equalsAllFields(other.destination)) + return false; return true; } diff --git a/enabler/src/de/schildbach/pte/dto/Location.java b/enabler/src/de/schildbach/pte/dto/Location.java index d606db46..08814732 100644 --- a/enabler/src/de/schildbach/pte/dto/Location.java +++ b/enabler/src/de/schildbach/pte/dto/Location.java @@ -169,10 +169,30 @@ public final class Location implements Serializable { return this.lat == other.lat && this.lon == other.lon; // only discriminate by name/place if no ids are given + if (!Objects.equal(this.place, other.place)) + return false; if (!Objects.equal(this.name, other.name)) return false; + return true; + } + + public boolean equalsAllFields(final Location other) { + if (other == this) + return true; + if (other == null) + return false; + if (!Objects.equal(this.type, other.type)) + return false; + if (!Objects.equal(this.id, other.id)) + return false; + if (this.lat != other.lat && this.lon != other.lon) + return false; if (!Objects.equal(this.place, other.place)) return false; + if (!Objects.equal(this.name, other.name)) + return false; + if (!Objects.equal(this.products, other.products)) + return false; return true; }