Fixed some problems in the point class
authorn.hoffmann <n.hoffmann@localhost>
Wed, 15 Dec 2010 17:25:13 +0000 (17:25 +0000)
committern.hoffmann <n.hoffmann@localhost>
Wed, 15 Dec 2010 17:25:13 +0000 (17:25 +0000)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/Point.java
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/location/PointTest.java

index 5d623c76aea5a34722d7ac3ca838831d826f9d46..47bf4bda4357e1d343880c8232112daea597d3c6 100644 (file)
@@ -315,6 +315,9 @@ public class Point implements Cloneable, Serializable {
                }
                
                public static Sexagesimal valueOf(Double decimal, boolean isLatitude, boolean nullSecondsToNull, boolean nullMinutesToNull){
+                       if(decimal == null){
+                               return null;
+                       }
                        Sexagesimal sexagesimal = new Sexagesimal(); 
                        Double decimalDegree = decimal;
                        if (isLatitude) {
@@ -422,7 +425,7 @@ public class Point implements Cloneable, Serializable {
        public static Double parseLatitude(String string) throws ParseException{
                CoordinateConverter converter = new CoordinateConverter();
                ConversionResults result = converter.tryConvert(string);
-               if (! result.conversionSuccessful || result.isLongitude  ){
+               if (! result.conversionSuccessful || (result.isLongitude != null  && result.isLongitude)  ){
                        throw new ParseException("Latitude could not be parsed", 0);
                }else{
                        return result.convertedCoord;
@@ -432,7 +435,7 @@ public class Point implements Cloneable, Serializable {
        public static Double parseLongitude(String string) throws ParseException{
                CoordinateConverter converter = new CoordinateConverter();
                ConversionResults result = converter.tryConvert(string);
-               if (! result.conversionSuccessful || ! result.isLongitude){
+               if (! result.conversionSuccessful || (result.isLongitude != null  && ! result.isLongitude)){
                        throw new ParseException("Longitude could not be parsed", 0);
                }else{
                        return result.convertedCoord;
index f31d8dded8abe2cfad283cc07ef1c4e16b62aae2..afee0ab543a60a8ddfb56abcdd8a1a9f00fc4213 100644 (file)
@@ -82,9 +82,13 @@ public class PointTest {
                Assert.assertNotNull("Point1 must not be null", point1);\r
                Assert.assertNotNull("Point2 must not be null", point2);\r
                Assert.assertEquals("", longitude1, point1.getLongitude());\r
+\r
                Assert.assertEquals("", latitude1, point1.getLatitude());\r
                Assert.assertEquals("", errorRadius, point1.getErrorRadius());\r
                Assert.assertEquals("", referenceSystem, point1.getReferenceSystem());\r
+               \r
+               Assert.assertNull("LongitudeSexagesimal should be null", point2.getLongitudeSexagesimal());\r
+               Assert.assertNull("LatitudeSexagesimal should be null", point2.getLatitudeSexagesimal());\r
        }\r
 \r
        @Test\r
@@ -170,6 +174,7 @@ public class PointTest {
                        Assert.assertTrue("Longitude can not be S", true);\r
                }\r
 \r
+\r
                \r
                \r
 //             Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0);\r
@@ -197,8 +202,16 @@ public class PointTest {
 \r
        }\r
        \r
-       \r
-       \r
+       @Test\r
+       public void testStaticParsing(){\r
+               try{\r
+                       Point.parseLatitude("1");\r
+               }catch (NullPointerException e){\r
+                       Assert.fail("No NullPointerException should occur");\r
+               } catch (ParseException e) {\r
+                       Assert.fail("No parsing error should occur");\r
+               }\r
+       }\r
        \r
        \r
        \r