-
Notifications
You must be signed in to change notification settings - Fork 184
Add support for point type #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@avinash-anand Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@avinash-anand Thank you for signing the Contributor License Agreement! |
Are you going to add support for other geometric types here too? |
* <p>This implements a version of java.awt.Point, except it uses double to represent the coordinates.</p> | ||
*/ | ||
public class Point { | ||
public double x; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this to be mutable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I referred PGpoint of pgjdbc. there it is mentioned as public. I think that perhaps it represents a 2D-point, hence, instead of adding both getters & setters, this value is made mutable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make it private and generate a getter/setter for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should be rather immutable fields (private final
without setters). Thinking of values as atomic and immutable value types is useful as a single point (and future geo types) cannot be changed partially but each update to a point requires a new value object instance.
double x = Double.parseDouble(coordinatesAsString[0]); | ||
double y = Double.parseDouble(coordinatesAsString[1]); | ||
return new Point(x, y); | ||
} catch (NumberFormatException | NullPointerException | ArrayIndexOutOfBoundsException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't catch NumberFormatException
in Numeric codecs and catching NullPointerException
and ArrayIndexOutOfBoundsException
looks kind of weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually NumberFormatException
was caught in pgjdbc, i thought, the same should be done here as well. Also, these other exceptions were also possible if we receive invalid data, hence caught these exceptions. I can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What @Squiry said. Let's see whether we have a need for handling such cases at all.
Sorry, my bad. I'll do it.
Sure. I'll add this test. In pgjdbc, it was marked as binary, hence i forced binary format.
Yes, I will add for line and polygon as well. Actually, I started with Point as it was small and simple. Also, could you please let me know what steps I need to follow to run |
* @param x integer amount to add on the x axis | ||
* @param y integer amount to add on the y axis | ||
*/ | ||
public void translate(int x, int y) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those mutation-like methods should return a new instance of Point
. Applying mutation to objects always opens up paths for potential bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods were present in original driver, so I added it as it is. Do you think these methods should be part of this class now or should I remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using PGJDBC as a starting point is fine. With the introduction of geo-types to r2dbc-postgressql, we have a chance to improve the actual design. Let's keep these methods in the type but change these to return a new instance.
* @param p Point to move to | ||
* @see java.awt.Point | ||
*/ | ||
public void setLocation(java.awt.Point p) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use AWT at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I was thinking the same. I'll remove this.
There are a few issues, though:
|
I'll try to fix this today.
I'll fix this today. |
@mp911de - I have fixed the test and updated the files with license. Thanks for pointing out the errors. For some reason, in my local machine - Please let me know if anymore changes are needed. |
@mp911de - Please let me know if this PR is eligible for merging or it needs some changes? |
Let me come back by next week to you. |
@mp911de - Let me know if now is a good time to review this PR? |
The code looks good. We will polish up the remaining issues during the merge. Can you please rebase your code, squash all commits into a single commit, and force-push your branch? |
671bade
to
8bd640a
Compare
8bd640a
to
69d1258
Compare
@mp911de - done. |
Thank you for your contribution. That's merged, polished, and backported now. |
Make Point final and reduce PointCodec visibility. Introduce factory method for Point type. Update documentation. [resolves pgjdbc#283][pgjdbc#282]
Make Point final and reduce PointCodec visibility. Introduce factory method for Point type. Update documentation. [resolves pgjdbc#283][pgjdbc#282]
Make sure that:
Issue description
related to issue previously opened support for geometric types - #282
New Public APIs
Additional context