File tree Expand file tree Collapse file tree 2 files changed +44
-10
lines changed
graphics/java/android/graphics Expand file tree Collapse file tree 2 files changed +44
-10
lines changed Original file line number Diff line number Diff line change @@ -70,20 +70,29 @@ public final boolean equals(int x, int y) {
7070 return this .x == x && this .y == y ;
7171 }
7272
73- @ Override public boolean equals (Object o ) {
74- if (o instanceof Point ) {
75- Point p = (Point ) o ;
76- return this .x == p .x && this .y == p .y ;
77- }
78- return false ;
73+ @ Override
74+ public boolean equals (Object o ) {
75+ if (this == o ) return true ;
76+ if (o == null || getClass () != o .getClass ()) return false ;
77+
78+ Point point = (Point ) o ;
79+
80+ if (x != point .x ) return false ;
81+ if (y != point .y ) return false ;
82+
83+ return true ;
7984 }
8085
81- @ Override public int hashCode () {
82- return x * 32713 + y ;
86+ @ Override
87+ public int hashCode () {
88+ int result = x ;
89+ result = 31 * result + y ;
90+ return result ;
8391 }
8492
85- @ Override public String toString () {
86- return "Point(" + x + ", " + y + ")" ;
93+ @ Override
94+ public String toString () {
95+ return "Point(" + x + ", " + y + ")" ;
8796 }
8897
8998 /**
Original file line number Diff line number Diff line change @@ -73,6 +73,31 @@ public final boolean equals(float x, float y) {
7373 return this .x == x && this .y == y ;
7474 }
7575
76+ @ Override
77+ public boolean equals (Object o ) {
78+ if (this == o ) return true ;
79+ if (o == null || getClass () != o .getClass ()) return false ;
80+
81+ PointF pointF = (PointF ) o ;
82+
83+ if (Float .compare (pointF .x , x ) != 0 ) return false ;
84+ if (Float .compare (pointF .y , y ) != 0 ) return false ;
85+
86+ return true ;
87+ }
88+
89+ @ Override
90+ public int hashCode () {
91+ int result = (x != +0.0f ? Float .floatToIntBits (x ) : 0 );
92+ result = 31 * result + (y != +0.0f ? Float .floatToIntBits (y ) : 0 );
93+ return result ;
94+ }
95+
96+ @ Override
97+ public String toString () {
98+ return "PointF(" + x + ", " + y + ")" ;
99+ }
100+
76101 /**
77102 * Return the euclidian distance from (0,0) to the point
78103 */
You can’t perform that action at this time.
0 commit comments