@@ -67,6 +67,7 @@ private GeoConverters() {}
67
67
*
68
68
* @return
69
69
*/
70
+ @ SuppressWarnings ("unchecked" )
70
71
public static Collection <? extends Object > getConvertersToRegister () {
71
72
return Arrays .asList ( //
72
73
BoxToDbObjectConverter .INSTANCE //
@@ -421,6 +422,7 @@ static enum GeoCommandToDbObjectConverter implements Converter<GeoCommand, DBObj
421
422
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
422
423
*/
423
424
@ Override
425
+ @ SuppressWarnings ("rawtypes" )
424
426
public DBObject convert (GeoCommand source ) {
425
427
426
428
if (source == null ) {
@@ -472,8 +474,13 @@ public DBObject convert(GeoCommand source) {
472
474
*/
473
475
@ SuppressWarnings ("rawtypes" )
474
476
static enum GeoJsonToDbObjectConverter implements Converter <GeoJson , DBObject > {
477
+
475
478
INSTANCE ;
476
479
480
+ /*
481
+ * (non-Javadoc)
482
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
483
+ */
477
484
@ Override
478
485
public DBObject convert (GeoJson source ) {
479
486
@@ -484,11 +491,15 @@ public DBObject convert(GeoJson source) {
484
491
DBObject dbo = new BasicDBObject ("type" , source .getType ());
485
492
486
493
if (source instanceof GeoJsonGeometryCollection ) {
494
+
487
495
BasicDBList dbl = new BasicDBList ();
496
+
488
497
for (GeoJson geometry : ((GeoJsonGeometryCollection ) source ).getCoordinates ()) {
489
498
dbl .add (convert (geometry ));
490
499
}
500
+
491
501
dbo .put ("geometries" , dbl );
502
+
492
503
} else {
493
504
dbo .put ("coordinates" , convertIfNecessarry (source .getCoordinates ()));
494
505
}
@@ -503,10 +514,13 @@ private Object convertIfNecessarry(Object candidate) {
503
514
}
504
515
505
516
if (candidate instanceof Iterable ) {
517
+
506
518
BasicDBList dbl = new BasicDBList ();
519
+
507
520
for (Object element : (Iterable ) candidate ) {
508
521
dbl .add (convertIfNecessarry (element ));
509
522
}
523
+
510
524
return dbl ;
511
525
}
512
526
@@ -523,8 +537,13 @@ private Object convertIfNecessarry(Object candidate) {
523
537
* @since 1.7
524
538
*/
525
539
static enum GeoJsonPointToDbObjectConverter implements Converter <GeoJsonPoint , DBObject > {
540
+
526
541
INSTANCE ;
527
542
543
+ /*
544
+ * (non-Javadoc)
545
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
546
+ */
528
547
@ Override
529
548
public DBObject convert (GeoJsonPoint source ) {
530
549
return GeoJsonToDbObjectConverter .INSTANCE .convert (source );
@@ -536,23 +555,33 @@ public DBObject convert(GeoJsonPoint source) {
536
555
* @since 1.7
537
556
*/
538
557
static enum GeoJsonPolygonToDbObjectConverter implements Converter <GeoJsonPolygon , DBObject > {
558
+
539
559
INSTANCE ;
540
560
561
+ /*
562
+ * (non-Javadoc)
563
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
564
+ */
541
565
@ Override
542
566
public DBObject convert (GeoJsonPolygon source ) {
543
567
return GeoJsonToDbObjectConverter .INSTANCE .convert (source );
544
568
}
545
-
546
569
}
547
570
548
571
/**
549
572
* @author Christoph Strobl
550
573
* @since 1.7
551
574
*/
552
575
static enum DbObjectToGeoJsonPointConverter implements Converter <DBObject , GeoJsonPoint > {
576
+
553
577
INSTANCE ;
554
578
579
+ /*
580
+ * (non-Javadoc)
581
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
582
+ */
555
583
@ Override
584
+ @ SuppressWarnings ("unchecked" )
556
585
public GeoJsonPoint convert (DBObject source ) {
557
586
558
587
if (source == null ) {
@@ -572,9 +601,13 @@ public GeoJsonPoint convert(DBObject source) {
572
601
* @since 1.7
573
602
*/
574
603
static enum DbObjectToGeoJsonPolygonConverter implements Converter <DBObject , GeoJsonPolygon > {
604
+
575
605
INSTANCE ;
576
606
577
- @ SuppressWarnings ("rawtypes" )
607
+ /*
608
+ * (non-Javadoc)
609
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
610
+ */
578
611
@ Override
579
612
public GeoJsonPolygon convert (DBObject source ) {
580
613
@@ -594,8 +627,13 @@ public GeoJsonPolygon convert(DBObject source) {
594
627
* @since 1.7
595
628
*/
596
629
static enum DbObjectToGeoJsonMultiPolygonConverter implements Converter <DBObject , GeoJsonMultiPolygon > {
630
+
597
631
INSTANCE ;
598
632
633
+ /*
634
+ * (non-Javadoc)
635
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
636
+ */
599
637
@ Override
600
638
public GeoJsonMultiPolygon convert (DBObject source ) {
601
639
@@ -608,11 +646,12 @@ public GeoJsonMultiPolygon convert(DBObject source) {
608
646
609
647
BasicDBList dbl = (BasicDBList ) source .get ("coordinates" );
610
648
List <GeoJsonPolygon > polygones = new ArrayList <GeoJsonPolygon >();
649
+
611
650
for (Object polygon : dbl ) {
612
651
polygones .add (toGeoJsonPolygon ((BasicDBList ) polygon ));
613
652
}
614
- return new GeoJsonMultiPolygon (polygones );
615
653
654
+ return new GeoJsonMultiPolygon (polygones );
616
655
}
617
656
}
618
657
@@ -621,8 +660,13 @@ public GeoJsonMultiPolygon convert(DBObject source) {
621
660
* @since 1.7
622
661
*/
623
662
static enum DbObjectToGeoJsonLineStringConverter implements Converter <DBObject , GeoJsonLineString > {
663
+
624
664
INSTANCE ;
625
665
666
+ /*
667
+ * (non-Javadoc)
668
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
669
+ */
626
670
@ Override
627
671
public GeoJsonLineString convert (DBObject source ) {
628
672
@@ -634,6 +678,7 @@ public GeoJsonLineString convert(DBObject source) {
634
678
String .format ("Cannot convert type '%s' to LineString." , source .get ("type" )));
635
679
636
680
BasicDBList cords = (BasicDBList ) source .get ("coordinates" );
681
+
637
682
return new GeoJsonLineString (toListOfPoint (cords ));
638
683
}
639
684
}
@@ -643,8 +688,13 @@ public GeoJsonLineString convert(DBObject source) {
643
688
* @since 1.7
644
689
*/
645
690
static enum DbObjectToGeoJsonMultiPointConverter implements Converter <DBObject , GeoJsonMultiPoint > {
691
+
646
692
INSTANCE ;
647
693
694
+ /*
695
+ * (non-Javadoc)
696
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
697
+ */
648
698
@ Override
649
699
public GeoJsonMultiPoint convert (DBObject source ) {
650
700
@@ -656,6 +706,7 @@ public GeoJsonMultiPoint convert(DBObject source) {
656
706
String .format ("Cannot convert type '%s' to MultiPoint." , source .get ("type" )));
657
707
658
708
BasicDBList cords = (BasicDBList ) source .get ("coordinates" );
709
+
659
710
return new GeoJsonMultiPoint (toListOfPoint (cords ));
660
711
}
661
712
}
@@ -665,8 +716,13 @@ public GeoJsonMultiPoint convert(DBObject source) {
665
716
* @since 1.7
666
717
*/
667
718
static enum DbObjectToGeoJsonMultiLineStringConverter implements Converter <DBObject , GeoJsonMultiLineString > {
719
+
668
720
INSTANCE ;
669
721
722
+ /*
723
+ * (non-Javadoc)
724
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
725
+ */
670
726
@ Override
671
727
public GeoJsonMultiLineString convert (DBObject source ) {
672
728
@@ -679,6 +735,7 @@ public GeoJsonMultiLineString convert(DBObject source) {
679
735
680
736
List <GeoJsonLineString > lines = new ArrayList <GeoJsonLineString >();
681
737
BasicDBList cords = (BasicDBList ) source .get ("coordinates" );
738
+
682
739
for (Object line : cords ) {
683
740
lines .add (new GeoJsonLineString (toListOfPoint ((BasicDBList ) line )));
684
741
}
@@ -691,8 +748,14 @@ public GeoJsonMultiLineString convert(DBObject source) {
691
748
* @since 1.7
692
749
*/
693
750
static enum DbObjectToGeoJsonGeometryCollectionConverter implements Converter <DBObject , GeoJsonGeometryCollection > {
751
+
694
752
INSTANCE ;
695
753
754
+ /*
755
+ * (non-Javadoc)
756
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
757
+ */
758
+ @ SuppressWarnings ("rawtypes" )
696
759
@ Override
697
760
public GeoJsonGeometryCollection convert (DBObject source ) {
698
761
@@ -711,7 +774,7 @@ public GeoJsonGeometryCollection convert(DBObject source) {
711
774
712
775
}
713
776
714
- private GeoJson <?> convertGeometries (DBObject source ) {
777
+ private static GeoJson <?> convertGeometries (DBObject source ) {
715
778
716
779
Object type = source .get ("type" );
717
780
if (ObjectUtils .nullSafeEquals (type , "Point" )) {
@@ -756,11 +819,13 @@ static List<Double> toList(Point point) {
756
819
static List <Point > toListOfPoint (BasicDBList listOfCoordinatePairs ) {
757
820
758
821
List <Point > points = new ArrayList <Point >();
822
+
759
823
for (Object point : listOfCoordinatePairs ) {
760
824
761
825
Assert .isInstanceOf (List .class , point );
762
826
763
827
List <Double > coordinatesList = (List <Double >) point ;
828
+
764
829
points .add (new GeoJsonPoint (coordinatesList .get (0 ).doubleValue (), coordinatesList .get (1 ).doubleValue ()));
765
830
}
766
831
return points ;
@@ -769,14 +834,11 @@ static List<Point> toListOfPoint(BasicDBList listOfCoordinatePairs) {
769
834
/**
770
835
* Converts a coordinate pairs nested in in {@link BasicDBList} into {@link GeoJsonPolygon}.
771
836
*
772
- * @param dbl
837
+ * @param dbList
773
838
* @return
774
839
* @since 1.7
775
840
*/
776
- static GeoJsonPolygon toGeoJsonPolygon (BasicDBList dbl ) {
777
-
778
- List <Point > outer = toListOfPoint ((BasicDBList ) dbl .get (0 ));
779
-
780
- return new GeoJsonPolygon (outer );
841
+ static GeoJsonPolygon toGeoJsonPolygon (BasicDBList dbList ) {
842
+ return new GeoJsonPolygon (toListOfPoint ((BasicDBList ) dbList .get (0 )));
781
843
}
782
844
}
0 commit comments