@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2014 - 2016 the original author or authors .
* Copyright 2014 - 2017 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -42,6 +42,7 @@ import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
@@ -42,6 +42,7 @@ import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
import org.springframework.data.mongodb.core.geo.Sphere ;
import org.springframework.data.mongodb.core.query.GeoCommand ;
import org.springframework.util.Assert ;
import org.springframework.util.NumberUtils ;
import org.springframework.util.ObjectUtils ;
import com.mongodb.BasicDBList ;
@ -121,10 +122,7 @@ abstract class GeoConverters {
@@ -121,10 +122,7 @@ abstract class GeoConverters {
return DocumentToGeoJsonPointConverter . INSTANCE . convert ( source ) ;
}
Number x = ( Number ) source . get ( "x" ) ;
Number y = ( Number ) source . get ( "y" ) ;
return new Point ( x . doubleValue ( ) , y . doubleValue ( ) ) ;
return new Point ( toPrimitiveDoubleValue ( source . get ( "x" ) ) , toPrimitiveDoubleValue ( source . get ( "y" ) ) ) ;
}
}
@ -258,10 +256,12 @@ abstract class GeoConverters {
@@ -258,10 +256,12 @@ abstract class GeoConverters {
}
Document center = ( Document ) source . get ( "center" ) ;
Number radiusNumber = ( Number ) source . get ( "radius" ) ;
Double radius = radiusNumber . doubleValue ( ) ;
Number radius = ( Number ) source . get ( "radius" ) ;
Assert . notNull ( center , "Center must not be null!" ) ;
Assert . notNull ( radius , "Radius must not be null!" ) ;
Distance distance = new Distance ( radius ) ;
Distance distance = new Distance ( toPrimitiveDoubleValue ( radius ) ) ;
if ( source . containsKey ( "metric" ) ) {
@ -271,9 +271,6 @@ abstract class GeoConverters {
@@ -271,9 +271,6 @@ abstract class GeoConverters {
distance = distance . in ( Metrics . valueOf ( metricString ) ) ;
}
Assert . notNull ( center , "Center must not be null!" ) ;
Assert . notNull ( radius , "Radius must not be null!" ) ;
return new Circle ( DocumentToPointConverter . INSTANCE . convert ( center ) , distance ) ;
}
}
@ -330,11 +327,12 @@ abstract class GeoConverters {
@@ -330,11 +327,12 @@ abstract class GeoConverters {
}
Document center = ( Document ) source . get ( "center" ) ;
Number radiusNumber = ( Number ) source . get ( "radius" ) ;
Double radius = radiusNumber . doubleValue ( ) ;
Number radius = ( Number ) source . get ( "radius" ) ;
Assert . notNull ( center , "Center must not be null!" ) ;
Assert . notNull ( radius , "Radius must not be null!" ) ;
Distance distance = new Distance ( radius ) ;
Distance distance = new Distance ( toPrimitiveDoubleValue ( radius ) ) ;
if ( source . containsKey ( "metric" ) ) {
@ -344,9 +342,6 @@ abstract class GeoConverters {
@@ -344,9 +342,6 @@ abstract class GeoConverters {
distance = distance . in ( Metrics . valueOf ( metricString ) ) ;
}
Assert . notNull ( center , "Center must not be null!" ) ;
Assert . notNull ( radius , "Radius must not be null!" ) ;
return new Sphere ( DocumentToPointConverter . INSTANCE . convert ( center ) , distance ) ;
}
}
@ -606,7 +601,7 @@ abstract class GeoConverters {
@@ -606,7 +601,7 @@ abstract class GeoConverters {
String . format ( "Cannot convert type '%s' to Point." , source . get ( "type" ) ) ) ;
List < Number > dbl = ( List < Number > ) source . get ( "coordinates" ) ;
return new GeoJsonPoint ( dbl . get ( 0 ) . doubleValue ( ) , dbl . get ( 1 ) . doubleValue ( ) ) ;
return new GeoJsonPoint ( toPrimitiveDoubleValue ( dbl . get ( 0 ) ) , toPrimitiveDoubleValue ( dbl . get ( 1 ) ) ) ;
}
}
@ -840,7 +835,8 @@ abstract class GeoConverters {
@@ -840,7 +835,8 @@ abstract class GeoConverters {
List < Number > coordinatesList = ( List < Number > ) point ;
points . add ( new GeoJsonPoint ( coordinatesList . get ( 0 ) . doubleValue ( ) , coordinatesList . get ( 1 ) . doubleValue ( ) ) ) ;
points . add ( new GeoJsonPoint ( toPrimitiveDoubleValue ( coordinatesList . get ( 0 ) ) ,
toPrimitiveDoubleValue ( coordinatesList . get ( 1 ) ) ) ) ;
}
return points ;
}
@ -855,4 +851,10 @@ abstract class GeoConverters {
@@ -855,4 +851,10 @@ abstract class GeoConverters {
static GeoJsonPolygon toGeoJsonPolygon ( List dbList ) {
return new GeoJsonPolygon ( toListOfPoint ( ( List ) dbList . get ( 0 ) ) ) ;
}
private static double toPrimitiveDoubleValue ( Object value ) {
Assert . isInstanceOf ( Number . class , value , "Argument must be a Number." ) ;
return NumberUtils . convertNumberToTargetClass ( ( Number ) value , Double . class ) . doubleValue ( ) ;
}
}