diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2018-10-12 11:16:32 +0200 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2018-10-12 13:19:10 +0200 |
commit | aae614b23c34123d6e95e7bdc1db213460ef4592 (patch) | |
tree | eb3c17225932721b8df4eee5b08e09fc66244aad | |
parent | 9e7694cb38982cf0434be64b8894c1628236d0d9 (diff) | |
download | qtlocation-mapboxgl-upstream/tvn-cameraupdate-equals.tar.gz |
[android] - add equals, hashcode and toString to camera update types from CameraUpdateFactoryupstream/tvn-cameraupdate-equals
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java index 8ef0d5b523..aba1b13ecd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java @@ -13,6 +13,7 @@ import com.mapbox.mapboxsdk.maps.UiSettings; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; /** * Factory for creating CameraUpdate objects. @@ -212,6 +213,53 @@ public final class CameraUpdateFactory { } return new CameraPosition.Builder(this).build(); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + CameraPositionUpdate that = (CameraPositionUpdate) o; + + if (Double.compare(that.bearing, bearing) != 0) { + return false; + } + if (Double.compare(that.tilt, tilt) != 0) { + return false; + } + if (Double.compare(that.zoom, zoom) != 0) { + return false; + } + return target != null ? target.equals(that.target) : that.target == null; + } + + @Override + public int hashCode() { + int result; + long temp; + temp = Double.doubleToLongBits(bearing); + result = (int) (temp ^ (temp >>> 32)); + result = 31 * result + (target != null ? target.hashCode() : 0); + temp = Double.doubleToLongBits(tilt); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(zoom); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public String toString() { + return "CameraPositionUpdate{" + + "bearing=" + bearing + + ", target=" + target + + ", tilt=" + tilt + + ", zoom=" + zoom + + '}'; + } } static final class CameraBoundsUpdate implements CameraUpdate { @@ -240,6 +288,38 @@ public final class CameraUpdateFactory { public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) { return mapboxMap.getCameraForLatLngBounds(bounds, padding); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + CameraBoundsUpdate that = (CameraBoundsUpdate) o; + + if (!bounds.equals(that.bounds)) { + return false; + } + return Arrays.equals(padding, that.padding); + } + + @Override + public int hashCode() { + int result = bounds.hashCode(); + result = 31 * result + Arrays.hashCode(padding); + return result; + } + + @Override + public String toString() { + return "CameraBoundsUpdate{" + + "bounds=" + bounds + + ", padding=" + Arrays.toString(padding) + + '}'; + } } static final class CameraMoveUpdate implements CameraUpdate { @@ -273,6 +353,38 @@ public final class CameraUpdateFactory { .bearing(previousPosition.bearing) .build(); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + CameraMoveUpdate that = (CameraMoveUpdate) o; + + if (Float.compare(that.x, x) != 0) { + return false; + } + return Float.compare(that.y, y) == 0; + } + + @Override + public int hashCode() { + int result = (x != +0.0f ? Float.floatToIntBits(x) : 0); + result = 31 * result + (y != +0.0f ? Float.floatToIntBits(y) : 0); + return result; + } + + @Override + public String toString() { + return "CameraMoveUpdate{" + + "x=" + x + + ", y=" + y + + '}'; + } } static final class ZoomUpdate implements CameraUpdate { @@ -366,5 +478,50 @@ public final class CameraUpdateFactory { .build(); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ZoomUpdate that = (ZoomUpdate) o; + + if (type != that.type) { + return false; + } + if (Double.compare(that.zoom, zoom) != 0) { + return false; + } + if (Float.compare(that.x, x) != 0) { + return false; + } + return Float.compare(that.y, y) == 0; + } + + @Override + public int hashCode() { + int result; + long temp; + result = type; + temp = Double.doubleToLongBits(zoom); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + result = 31 * result + (x != +0.0f ? Float.floatToIntBits(x) : 0); + result = 31 * result + (y != +0.0f ? Float.floatToIntBits(y) : 0); + return result; + } + + @Override + public String toString() { + return "ZoomUpdate{" + + "type=" + type + + ", zoom=" + zoom + + ", x=" + x + + ", y=" + y + + '}'; + } } } |