summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-11-26 09:44:27 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-11-26 09:44:28 -0800
commitce180c10f702d42b9f443b6a6ba7b0acaa5598ef (patch)
tree5bf66be7748a928b17b6e14625bd6714a2042031 /graphics
parenta722789b4f43dfbc618558e8f273ea58c126339b (diff)
parent9f8af6546deb26d8bddb0c1b23d554fe5380b9d3 (diff)
downloadframeworks_base-ce180c10f702d42b9f443b6a6ba7b0acaa5598ef.zip
frameworks_base-ce180c10f702d42b9f443b6a6ba7b0acaa5598ef.tar.gz
frameworks_base-ce180c10f702d42b9f443b6a6ba7b0acaa5598ef.tar.bz2
Merge "Cleanup: add PointF.toString()/equals()/hashcode()" into jb-mr1.1-dev
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Point.java29
-rw-r--r--graphics/java/android/graphics/PointF.java25
2 files changed, 44 insertions, 10 deletions
diff --git a/graphics/java/android/graphics/Point.java b/graphics/java/android/graphics/Point.java
index 338e880..e0d8ccc 100644
--- a/graphics/java/android/graphics/Point.java
+++ b/graphics/java/android/graphics/Point.java
@@ -70,20 +70,29 @@ public class Point implements Parcelable {
return this.x == x && this.y == y;
}
- @Override public boolean equals(Object o) {
- if (o instanceof Point) {
- Point p = (Point) o;
- return this.x == p.x && this.y == p.y;
- }
- return false;
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Point point = (Point) o;
+
+ if (x != point.x) return false;
+ if (y != point.y) return false;
+
+ return true;
}
- @Override public int hashCode() {
- return x * 32713 + y;
+ @Override
+ public int hashCode() {
+ int result = x;
+ result = 31 * result + y;
+ return result;
}
- @Override public String toString() {
- return "Point(" + x + ", " + y+ ")";
+ @Override
+ public String toString() {
+ return "Point(" + x + ", " + y + ")";
}
/**
diff --git a/graphics/java/android/graphics/PointF.java b/graphics/java/android/graphics/PointF.java
index e00271f..ee38dbb 100644
--- a/graphics/java/android/graphics/PointF.java
+++ b/graphics/java/android/graphics/PointF.java
@@ -73,6 +73,31 @@ public class PointF implements Parcelable {
return this.x == x && this.y == y;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PointF pointF = (PointF) o;
+
+ if (Float.compare(pointF.x, x) != 0) return false;
+ if (Float.compare(pointF.y, y) != 0) return false;
+
+ return true;
+ }
+
+ @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 "PointF(" + x + ", " + y + ")";
+ }
+
/**
* Return the euclidian distance from (0,0) to the point
*/