|
1 | 1 | /*
|
2 |
| - * Copyright 2017-2020 the original author or authors. |
| 2 | + * Copyright 2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package io.r2dbc.postgresql.codec;
|
18 | 18 |
|
19 | 19 | /**
|
20 |
| - * <p>It maps to the point datatype in org.postgresql.</p> |
21 |
| - * |
22 |
| - * <p> It uses double to represent the coordinates.</p> |
| 20 | + * Value object that maps to the {@code point} datatype in Postgres. |
| 21 | + * <p> |
| 22 | + * Uses {@code double} to represent the coordinates. |
23 | 23 | */
|
24 |
| -public class Point { |
| 24 | +public final class Point { |
25 | 25 |
|
26 | 26 | private final double x;
|
27 | 27 |
|
28 | 28 | private final double y;
|
29 | 29 |
|
30 |
| - /** |
31 |
| - * @param x coordinate |
32 |
| - * @param y coordinate |
33 |
| - */ |
34 |
| - public Point(double x, double y) { |
| 30 | + private Point(double x, double y) { |
35 | 31 | this.x = x;
|
36 | 32 | this.y = y;
|
37 | 33 | }
|
38 | 34 |
|
| 35 | + /** |
| 36 | + * Create a new {@link Point} given {@code x} and {@code y} coordinates. |
| 37 | + * |
| 38 | + * @param x the x axis coordinate |
| 39 | + * @param y the y axis coordinate |
| 40 | + * @return the new {@link Point} object |
| 41 | + */ |
| 42 | + public static Point of(double x, double y) { |
| 43 | + return new Point(x, y); |
| 44 | + } |
| 45 | + |
39 | 46 | public double getX() {
|
40 |
| - return x; |
| 47 | + return this.x; |
41 | 48 | }
|
42 | 49 |
|
43 | 50 | public double getY() {
|
44 |
| - return y; |
| 51 | + return this.y; |
45 | 52 | }
|
46 | 53 |
|
47 | 54 | /**
|
48 |
| - * Translate the point by the supplied amount. |
| 55 | + * Translate the point by the supplied amount by adding {@code x} and {@code y} offsets. |
49 | 56 | *
|
50 | 57 | * @param x integer amount to add on the x axis
|
51 | 58 | * @param y integer amount to add on the y axis
|
52 |
| - * @return - new point with translated values |
| 59 | + * @return new {@link Point} with translated values |
53 | 60 | */
|
54 | 61 | public Point translate(int x, int y) {
|
55 | 62 | return translate((double) x, (double) y);
|
56 | 63 | }
|
57 | 64 |
|
58 | 65 | /**
|
59 |
| - * Translate the point by the supplied amount. |
| 66 | + * Translate the point by the supplied amount by adding {@code x} and {@code y} offsets. |
60 | 67 | *
|
61 | 68 | * @param x double amount to add on the x axis
|
62 | 69 | * @param y double amount to add on the y axis
|
63 |
| - * @return - new point with translated values |
| 70 | + * @return new {@link Point} with translated values |
64 | 71 | */
|
65 | 72 | public Point translate(double x, double y) {
|
66 | 73 | return new Point(this.x + x, this.y + y);
|
67 | 74 | }
|
68 | 75 |
|
69 |
| - /** |
70 |
| - * Moves the point to the supplied coordinates. |
71 |
| - * |
72 |
| - * @param x integer coordinate |
73 |
| - * @param y integer coordinate |
74 |
| - */ |
75 |
| - public Point move(int x, int y) { |
76 |
| - return setLocation(x, y); |
77 |
| - } |
78 |
| - |
79 |
| - /** |
80 |
| - * Moves the point to the supplied coordinates. |
81 |
| - * |
82 |
| - * @param x double coordinate |
83 |
| - * @param y double coordinate |
84 |
| - * @return - new point with provided coordinates |
85 |
| - */ |
86 |
| - public Point move(double x, double y) { |
87 |
| - return new Point(x, y); |
88 |
| - } |
89 |
| - |
90 |
| - /** |
91 |
| - * Moves the point to the supplied coordinates. |
92 |
| - * |
93 |
| - * @param x integer coordinate |
94 |
| - * @param y integer coordinate |
95 |
| - * @return - return new Point with these coordinates |
96 |
| - */ |
97 |
| - public Point setLocation(int x, int y) { |
98 |
| - return move((double) x, (double) y); |
99 |
| - } |
100 |
| - |
| 76 | + @Override |
101 | 77 | public boolean equals(Object obj) {
|
102 | 78 | if (obj instanceof Point) {
|
103 | 79 | Point p = (Point) obj;
|
104 |
| - return x == p.x && y == p.y; |
| 80 | + return this.x == p.x && this.y == p.y; |
105 | 81 | }
|
106 | 82 | return false;
|
107 | 83 | }
|
108 | 84 |
|
| 85 | + @Override |
109 | 86 | public int hashCode() {
|
110 |
| - long v1 = Double.doubleToLongBits(x); |
111 |
| - long v2 = Double.doubleToLongBits(y); |
| 87 | + long v1 = Double.doubleToLongBits(this.x); |
| 88 | + long v2 = Double.doubleToLongBits(this.y); |
112 | 89 | return (int) (v1 ^ v2 ^ (v1 >>> 32) ^ (v2 >>> 32));
|
113 | 90 | }
|
114 | 91 |
|
| 92 | + @Override |
115 | 93 | public String toString() {
|
116 |
| - return "(" + x + "," + y + ")"; |
| 94 | + return "(" + this.x + "," + this.y + ")"; |
117 | 95 | }
|
118 | 96 |
|
119 | 97 | }
|
0 commit comments