1 package com.xtremelabs.robolectric.shadows; 2 3 import android.graphics.Point; 4 import android.graphics.PointF; 5 import com.xtremelabs.robolectric.internal.Implementation; 6 import com.xtremelabs.robolectric.internal.Implements; 7 import com.xtremelabs.robolectric.internal.RealObject; 8 9 import static com.xtremelabs.robolectric.Robolectric.shadowOf_; 10 11 /** 12 * Shadow implementation of {@code Point} 13 */ 14 @SuppressWarnings({"UnusedDeclaration"}) 15 @Implements(PointF.class) 16 public class ShadowPointF { 17 @RealObject private PointF realPointF; 18 __constructor__(float x, float y)19 public void __constructor__(float x, float y) { 20 realPointF.x = x; 21 realPointF.y = y; 22 } 23 __constructor__(Point src)24 public void __constructor__(Point src) { 25 realPointF.x = src.x; 26 realPointF.y = src.y; 27 } 28 29 @Implementation set(float x, float y)30 public void set(float x, float y) { 31 realPointF.x = x; 32 realPointF.y = y; 33 } 34 35 @Implementation negate()36 public final void negate() { 37 realPointF.x = -realPointF.x; 38 realPointF.y = -realPointF.y; 39 } 40 41 @Implementation offset(float dx, float dy)42 public final void offset(float dx, float dy) { 43 realPointF.x += dx; 44 realPointF.y += dy; 45 } 46 47 @Override @Implementation equals(Object object)48 public boolean equals(Object object) { 49 if (object == null) return false; 50 Object o = shadowOf_(object); 51 if (o == null) return false; 52 if (this == o) return true; 53 if (getClass() != o.getClass()) return false; 54 55 ShadowPointF that = (ShadowPointF) o; 56 if (this.realPointF.x == that.realPointF.x && this.realPointF.y == that.realPointF.y) return true; 57 58 return false; 59 } 60 61 @Override @Implementation hashCode()62 public int hashCode() { 63 return (int) (realPointF.x * 32713 + realPointF.y); 64 } 65 66 @Override @Implementation toString()67 public String toString() { 68 return "Point(" + realPointF.x + ", " + realPointF.y + ")"; 69 } 70 71 /** 72 * Non-Android utility method for comparing a point to a well-known value 73 * 74 * @param x x 75 * @param y y 76 * @return this.x == x && this.y == y 77 */ 78 @Implementation equals(float x, float y)79 public final boolean equals(float x, float y) { 80 return realPointF.x == x && realPointF.y == y; 81 } 82 } 83