Skip to content

Commit

Permalink
Implement equals and hashCode for BoundingBox (osmdroid#2002)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Perebner <[email protected]>
  • Loading branch information
Maradox and Martin Perebner authored Jul 6, 2024
1 parent e85b32e commit d27789e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions osmdroid-android/src/main/java/org/osmdroid/util/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ public BoundingBox clone() {
return new BoundingBox(this.mLatNorth, this.mLonEast, this.mLatSouth, this.mLonWest);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

BoundingBox that = (BoundingBox) o;

if (Double.compare(mLatNorth, that.mLatNorth) != 0) return false;
if (Double.compare(mLatSouth, that.mLatSouth) != 0) return false;
if (Double.compare(mLonEast, that.mLonEast) != 0) return false;
return Double.compare(mLonWest, that.mLonWest) == 0;
}

@Override
public int hashCode() {
int result;
long temp;
temp = Double.doubleToLongBits(mLatNorth);
result = (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(mLatSouth);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(mLonEast);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(mLonWest);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}

/**
* @return the BoundingBox enclosing this BoundingBox and bb2 BoundingBox
*/
Expand Down

0 comments on commit d27789e

Please sign in to comment.