Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4098

Polygon constructor that takes var-args of Lists should provide more flexible constructor

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.0
    • Affects Version/s: 3.12.0, 4.2.0
    • Component/s: None
    • None
    • Minor Change
    • Not Needed

      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.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            markaalvaro@gmail.com Mark Alvaro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: