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