Minor fixes to android.graphics.Matrix

Tweaked equals() and finalize(), introduced trivial hashCode().

(Also picked up a handful of automatic trailing-space removals.)

Bug 9756081

Change-Id: I4639cf1e970a16179fa6c0d24785f4d0dfbe58ed
This commit is contained in:
Andy McFadden
2013-07-09 16:33:18 -07:00
parent 4a9095007d
commit 73b81e75df

View File

@@ -267,13 +267,23 @@ public class Matrix {
native_set(native_instance, src.native_instance);
}
}
/** Returns true iff obj is a Matrix and its values equal our values.
*/
@Override
public boolean equals(Object obj) {
return obj != null &&
obj instanceof Matrix &&
native_equals(native_instance, ((Matrix)obj).native_instance);
//if (obj == this) return true; -- NaN value would mean matrix != itself
if (!(obj instanceof Matrix)) return false;
return native_equals(native_instance, ((Matrix)obj).native_instance);
}
@Override
public int hashCode() {
// This should generate the hash code by performing some arithmetic operation on all
// the matrix elements -- our equals() does an element-by-element comparison, and we
// need to ensure that the hash code for two equal objects is the same. We're not
// really using this at the moment, so we take the easy way out.
return 44;
}
/** Set the matrix to identity */
@@ -512,7 +522,7 @@ public class Matrix {
*/
END (3);
// the native values must match those in SkMatrix.h
// the native values must match those in SkMatrix.h
ScaleToFit(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -535,7 +545,7 @@ public class Matrix {
}
return native_setRectToRect(native_instance, src, dst, stf.nativeInt);
}
// private helper to perform range checks on arrays of "points"
private static void checkPointArrays(float[] src, int srcIndex,
float[] dst, int dstIndex,
@@ -598,7 +608,7 @@ public class Matrix {
native_mapPoints(native_instance, dst, dstIndex, src, srcIndex,
pointCount, true);
}
/**
* Apply this matrix to the array of 2D vectors specified by src, and write
* the transformed vectors into the array of vectors specified by dst. The
@@ -620,7 +630,7 @@ public class Matrix {
native_mapPoints(native_instance, dst, dstIndex, src, srcIndex,
vectorCount, false);
}
/**
* Apply this matrix to the array of 2D points specified by src, and write
* the transformed points into the array of points specified by dst. The
@@ -713,7 +723,7 @@ public class Matrix {
public float mapRadius(float radius) {
return native_mapRadius(native_instance, radius);
}
/** Copy 9 values from the matrix into the array.
*/
public void getValues(float[] values) {
@@ -736,13 +746,14 @@ public class Matrix {
native_setValues(native_instance, values);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(64);
sb.append("Matrix{");
toShortString(sb);
sb.append('}');
return sb.toString();
}
public String toShortString() {
@@ -780,13 +791,18 @@ public class Matrix {
pw.print(values[5]); pw.print("][");
pw.print(values[6]); pw.print(", "); pw.print(values[7]); pw.print(", ");
pw.print(values[8]); pw.print(']');
}
@Override
protected void finalize() throws Throwable {
finalizer(native_instance);
try {
finalizer(native_instance);
} finally {
super.finalize();
}
}
/*package*/ final int ni() {
return native_instance;
}