[JAVA-4098] Polygon constructor that takes var-args of Lists should provide more flexible constructor Created: 08/Apr/21  Updated: 28/Oct/23  Resolved: 17/Jun/21

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 3.12.0, 4.2.0
Fix Version/s: 4.3.0

Type: Improvement Priority: Major - P3
Reporter: Mark Alvaro Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change
Documentation Changes: Not Needed

 Description   

If trying to convert a Polygon object from another library to Mongo's Polygon, there is no good way to construct a List<Position>[] to actually call this constructor:

public Polygon(final List<Position> exterior, final List<Position>... holes);

given the Polygon from the other library will have an arbitrary number of holes. The issue stems from the fact that you are not meant to create arrays of generic types in Java. So the only way this constructor can be used is if you have each of the {{List<Position>}}s on hand when you call this constructor.

The only workarounds I can find require using reflection, but it seems like just providing an alternate constructor that takes a 2-dimensional List or array might be more friendly.

Also note that even the alternate constructor that takes PolygonCoordinates won't work as it ultimately has its own constructor with the same issue.

This also affects MultiPolygon. And while no change is needed for GeometryCollection, this also prevents translating GeometryCollections, because they may contain Polygons or MultiPolygons.



 Comments   
Comment by Mark Alvaro [ 08/Apr/21 ]

Yep I can do that!

Comment by Jeffrey Yemin [ 08/Apr/21 ]

Hi markaalvaro@gmail.com

Thanks for letting us know about the issue you're having. Care to throw up a pull request showing what you think it should look like?

Generated at Thu Feb 08 09:01:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.