Browse Source

DATAMONGO-1466 - Polishing.

Remove superfluous static keyword in inner enum declarations. Fix typos in method names.

Original pull request: #561.
pull/585/head
Mark Paluch 8 years ago
parent
commit
6d6201d327
  1. 72
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java
  2. 16
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoJsonTests.java

72
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2017 the original author or authors. * Copyright 2014-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,6 +55,7 @@ import com.mongodb.DBObject;
* @author Oliver Gierke * @author Oliver Gierke
* @author Christoph Strobl * @author Christoph Strobl
* @author Thiago Diniz da Silveira * @author Thiago Diniz da Silveira
* @author Mark Paluch
* @since 1.5 * @since 1.5
*/ */
abstract class GeoConverters { abstract class GeoConverters {
@ -103,7 +104,7 @@ abstract class GeoConverters {
* @since 1.5 * @since 1.5
*/ */
@ReadingConverter @ReadingConverter
static enum DbObjectToPointConverter implements Converter<DBObject, Point> { enum DbObjectToPointConverter implements Converter<DBObject, Point> {
INSTANCE; INSTANCE;
@ -134,7 +135,7 @@ abstract class GeoConverters {
* @author Thomas Darimont * @author Thomas Darimont
* @since 1.5 * @since 1.5
*/ */
static enum PointToDbObjectConverter implements Converter<Point, DBObject> { enum PointToDbObjectConverter implements Converter<Point, DBObject> {
INSTANCE; INSTANCE;
@ -155,7 +156,7 @@ abstract class GeoConverters {
* @since 1.5 * @since 1.5
*/ */
@WritingConverter @WritingConverter
static enum BoxToDbObjectConverter implements Converter<Box, DBObject> { enum BoxToDbObjectConverter implements Converter<Box, DBObject> {
INSTANCE; INSTANCE;
@ -184,7 +185,7 @@ abstract class GeoConverters {
* @since 1.5 * @since 1.5
*/ */
@ReadingConverter @ReadingConverter
static enum DbObjectToBoxConverter implements Converter<DBObject, Box> { enum DbObjectToBoxConverter implements Converter<DBObject, Box> {
INSTANCE; INSTANCE;
@ -212,7 +213,7 @@ abstract class GeoConverters {
* @author Thomas Darimont * @author Thomas Darimont
* @since 1.5 * @since 1.5
*/ */
static enum CircleToDbObjectConverter implements Converter<Circle, DBObject> { enum CircleToDbObjectConverter implements Converter<Circle, DBObject> {
INSTANCE; INSTANCE;
@ -242,7 +243,7 @@ abstract class GeoConverters {
* @since 1.5 * @since 1.5
*/ */
@ReadingConverter @ReadingConverter
static enum DbObjectToCircleConverter implements Converter<DBObject, Circle> { enum DbObjectToCircleConverter implements Converter<DBObject, Circle> {
INSTANCE; INSTANCE;
@ -283,7 +284,7 @@ abstract class GeoConverters {
* @author Thomas Darimont * @author Thomas Darimont
* @since 1.5 * @since 1.5
*/ */
static enum SphereToDbObjectConverter implements Converter<Sphere, DBObject> { enum SphereToDbObjectConverter implements Converter<Sphere, DBObject> {
INSTANCE; INSTANCE;
@ -313,7 +314,7 @@ abstract class GeoConverters {
* @since 1.5 * @since 1.5
*/ */
@ReadingConverter @ReadingConverter
static enum DbObjectToSphereConverter implements Converter<DBObject, Sphere> { enum DbObjectToSphereConverter implements Converter<DBObject, Sphere> {
INSTANCE; INSTANCE;
@ -354,7 +355,7 @@ abstract class GeoConverters {
* @author Thomas Darimont * @author Thomas Darimont
* @since 1.5 * @since 1.5
*/ */
static enum PolygonToDbObjectConverter implements Converter<Polygon, DBObject> { enum PolygonToDbObjectConverter implements Converter<Polygon, DBObject> {
INSTANCE; INSTANCE;
@ -389,7 +390,7 @@ abstract class GeoConverters {
* @since 1.5 * @since 1.5
*/ */
@ReadingConverter @ReadingConverter
static enum DbObjectToPolygonConverter implements Converter<DBObject, Polygon> { enum DbObjectToPolygonConverter implements Converter<DBObject, Polygon> {
INSTANCE; INSTANCE;
@ -424,7 +425,7 @@ abstract class GeoConverters {
* @author Thomas Darimont * @author Thomas Darimont
* @since 1.5 * @since 1.5
*/ */
static enum GeoCommandToDbObjectConverter implements Converter<GeoCommand, DBObject> { enum GeoCommandToDbObjectConverter implements Converter<GeoCommand, DBObject> {
INSTANCE; INSTANCE;
@ -484,7 +485,7 @@ abstract class GeoConverters {
* @since 1.7 * @since 1.7
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
static enum GeoJsonToDbObjectConverter implements Converter<GeoJson, DBObject> { enum GeoJsonToDbObjectConverter implements Converter<GeoJson, DBObject> {
INSTANCE; INSTANCE;
@ -547,7 +548,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum GeoJsonPointToDbObjectConverter implements Converter<GeoJsonPoint, DBObject> { enum GeoJsonPointToDbObjectConverter implements Converter<GeoJsonPoint, DBObject> {
INSTANCE; INSTANCE;
@ -565,7 +566,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum GeoJsonPolygonToDbObjectConverter implements Converter<GeoJsonPolygon, DBObject> { enum GeoJsonPolygonToDbObjectConverter implements Converter<GeoJsonPolygon, DBObject> {
INSTANCE; INSTANCE;
@ -583,7 +584,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum DbObjectToGeoJsonPointConverter implements Converter<DBObject, GeoJsonPoint> { enum DbObjectToGeoJsonPointConverter implements Converter<DBObject, GeoJsonPoint> {
INSTANCE; INSTANCE;
@ -611,7 +612,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum DbObjectToGeoJsonPolygonConverter implements Converter<DBObject, GeoJsonPolygon> { enum DbObjectToGeoJsonPolygonConverter implements Converter<DBObject, GeoJsonPolygon> {
INSTANCE; INSTANCE;
@ -637,7 +638,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum DbObjectToGeoJsonMultiPolygonConverter implements Converter<DBObject, GeoJsonMultiPolygon> { enum DbObjectToGeoJsonMultiPolygonConverter implements Converter<DBObject, GeoJsonMultiPolygon> {
INSTANCE; INSTANCE;
@ -670,7 +671,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum DbObjectToGeoJsonLineStringConverter implements Converter<DBObject, GeoJsonLineString> { enum DbObjectToGeoJsonLineStringConverter implements Converter<DBObject, GeoJsonLineString> {
INSTANCE; INSTANCE;
@ -698,7 +699,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum DbObjectToGeoJsonMultiPointConverter implements Converter<DBObject, GeoJsonMultiPoint> { enum DbObjectToGeoJsonMultiPointConverter implements Converter<DBObject, GeoJsonMultiPoint> {
INSTANCE; INSTANCE;
@ -726,7 +727,7 @@ abstract class GeoConverters {
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.7 * @since 1.7
*/ */
static enum DbObjectToGeoJsonMultiLineStringConverter implements Converter<DBObject, GeoJsonMultiLineString> { enum DbObjectToGeoJsonMultiLineStringConverter implements Converter<DBObject, GeoJsonMultiLineString> {
INSTANCE; INSTANCE;
@ -785,35 +786,6 @@ abstract class GeoConverters {
return new GeoJsonGeometryCollection(geometries); return new GeoJsonGeometryCollection(geometries);
} }
private static GeoJson<?> convertGeometries(DBObject source) {
Object type = source.get("type");
if (ObjectUtils.nullSafeEquals(type, "Point")) {
return DbObjectToGeoJsonPointConverter.INSTANCE.convert(source);
}
if (ObjectUtils.nullSafeEquals(type, "MultiPoint")) {
return DbObjectToGeoJsonMultiPointConverter.INSTANCE.convert(source);
}
if (ObjectUtils.nullSafeEquals(type, "LineString")) {
return DbObjectToGeoJsonLineStringConverter.INSTANCE.convert(source);
}
if (ObjectUtils.nullSafeEquals(type, "MultiLineString")) {
return DbObjectToGeoJsonMultiLineStringConverter.INSTANCE.convert(source);
}
if (ObjectUtils.nullSafeEquals(type, "Polygon")) {
return DbObjectToGeoJsonPolygonConverter.INSTANCE.convert(source);
}
if (ObjectUtils.nullSafeEquals(type, "MultiPolygon")) {
return DbObjectToGeoJsonMultiPolygonConverter.INSTANCE.convert(source);
}
throw new IllegalArgumentException(String.format("Cannot convert unknown GeoJson type %s", type));
}
} }
static List<Double> toList(Point point) { static List<Double> toList(Point point) {

16
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoJsonTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2015-2017 the original author or authors. * Copyright 2015-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -144,7 +144,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonPointTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonPointTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonPoint"; obj.id = "geoJsonPoint";
@ -159,7 +159,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonPolygonTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonPolygonTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonPolygon"; obj.id = "geoJsonPolygon";
@ -175,7 +175,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonLineStringTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonLineStringTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonLineString"; obj.id = "geoJsonLineString";
@ -190,7 +190,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonMultiLineStringTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiLineStringTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonMultiLineString"; obj.id = "geoJsonMultiLineString";
@ -207,7 +207,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonMultiPointTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPointTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonMultiPoint"; obj.id = "geoJsonMultiPoint";
@ -222,7 +222,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonMultiPolygonTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPolygonTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonMultiPolygon"; obj.id = "geoJsonMultiPolygon";
@ -238,7 +238,7 @@ public class GeoJsonTests {
} }
@Test // DATAMONGO-1137 @Test // DATAMONGO-1137
public void shouleSaveAndRetrieveDocumentWithGeoJsonGeometryCollectionTypeCorrectly() { public void shouldSaveAndRetrieveDocumentWithGeoJsonGeometryCollectionTypeCorrectly() {
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType(); DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
obj.id = "geoJsonGeometryCollection"; obj.id = "geoJsonGeometryCollection";

Loading…
Cancel
Save