From 7db1140624d57b160f5d352b13783c5da11d458b Mon Sep 17 00:00:00 2001 From: "andreas.schildbach@gmail.com" Date: Thu, 6 Oct 2011 15:10:24 +0000 Subject: [PATCH] fixed NPE git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@812 0924bc21-9374-b0fa-ee44-9ff1593b38f0 --- src/de/schildbach/pte/dto/Line.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/de/schildbach/pte/dto/Line.java b/src/de/schildbach/pte/dto/Line.java index aa4f370e..d049a797 100644 --- a/src/de/schildbach/pte/dto/Line.java +++ b/src/de/schildbach/pte/dto/Line.java @@ -77,13 +77,13 @@ public final class Line implements Serializable, Comparable if (!(o instanceof Line)) return false; final Line other = (Line) o; - return (this.label.equals(other.label)); + return nullSafeEquals(this.label, other.label); } @Override public int hashCode() { - return label.hashCode(); + return nullSafeHashCode(label); } public int compareTo(final Line other) @@ -96,6 +96,22 @@ public final class Line implements Serializable, Comparable if (compareProduct != 0) return compareProduct; - return label.compareTo(other.label); + 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) + return 0; + return o.hashCode(); } }