Skip to content

Relax requirement for GeoJsonMultiPoint construction allowing creation using a single point #3777

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* {@link GeoJsonMultiPoint} is defined as list of {@link Point}s.
*
* @author Christoph Strobl
* @author Ivan Volzhev
* @since 1.7
* @see <a href="https://geojson.org/geojson-spec.html#multipoint">https://geojson.org/geojson-spec.html#multipoint</a>
*/
Expand All @@ -40,12 +41,12 @@ public class GeoJsonMultiPoint implements GeoJson<Iterable<Point>> {
/**
* Creates a new {@link GeoJsonMultiPoint} for the given {@link Point}s.
*
* @param points points must not be {@literal null} and have at least 2 entries.
* @param points points must not be {@literal null} and have at least 1 entry.
*/
public GeoJsonMultiPoint(List<Point> points) {

Assert.notNull(points, "Points must not be null.");
Assert.isTrue(points.size() >= 2, "Minimum of 2 Points required.");
Assert.isTrue(points.size() >= 1, "Minimum of 1 Point required.");

this.points = new ArrayList<Point>(points);
}
Expand All @@ -69,6 +70,19 @@ public GeoJsonMultiPoint(Point first, Point second, Point... others) {
this.points.addAll(Arrays.asList(others));
}

/**
* Creates a new {@link GeoJsonMultiPoint} for the given {@link Point}.
*
* @param point must not be {@literal null}.
*/
public GeoJsonMultiPoint(Point point) {

Assert.notNull(point, "First point must not be null!");

this.points = new ArrayList<Point>();
this.points.add(point);
}

/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.geo.GeoJson#getType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Ivan Volzhev
*/
@ExtendWith({ MongoClientExtension.class, SpringExtension.class })
@ContextConfiguration
Expand Down Expand Up @@ -329,6 +330,21 @@ public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPointTypeCorrectly() {
assertThat(result.geoJsonMultiPoint).isEqualTo(obj.geoJsonMultiPoint);
}

@Test // DATAMONGO-3776
public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPointTypeWithOnePointCorrectly() {

DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonMultiPoint";
obj.geoJsonMultiPoint = new GeoJsonMultiPoint(new Point(0, 0));

template.save(obj);

DocumentWithPropertyUsingGeoJsonType result = template.findOne(query(where("id").is(obj.id)),
DocumentWithPropertyUsingGeoJsonType.class);

assertThat(result.geoJsonMultiPoint).isEqualTo(obj.geoJsonMultiPoint);
}

@Test // DATAMONGO-1137
public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPolygonTypeCorrectly() {

Expand Down