again fixed equals/hashCode

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@954 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2012-02-21 00:28:36 +00:00
parent 7fae472aac
commit c43ce463f0

View file

@ -121,11 +121,11 @@ public final class Location implements Serializable
final Location other = (Location) o; final Location other = (Location) o;
if (this.type != other.type) if (this.type != other.type)
return false; return false;
if (this.id != other.id) if (this.id != 0 && this.id == other.id)
return false; return true;
if (this.lat != other.lat || this.lon != other.lon) if (this.lat != 0 && this.lon != 0 && this.lat == other.lat && this.lon == other.lon)
return false; return true;
if (this.id == 0 && !nullSafeEquals(this.name, other.name)) // only discriminate by name if no ids are given if (!nullSafeEquals(this.name, other.name)) // only discriminate by name if no ids are given
return false; return false;
return true; return true;
} }
@ -136,11 +136,16 @@ public final class Location implements Serializable
int hashCode = 0; int hashCode = 0;
hashCode += type.hashCode(); hashCode += type.hashCode();
hashCode *= 29; hashCode *= 29;
hashCode += id; if (id != 0)
hashCode *= 29; {
hashCode += lat; hashCode += id;
hashCode *= 29; }
hashCode += lon; else if (lat != 0 || lon != 0)
{
hashCode += lat;
hashCode *= 29;
hashCode += lon;
}
return hashCode; return hashCode;
} }