sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1542807 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/io/wkt/ main/java/org/apache/sis/referencing/datum/ test/java/org/apache/sis/referencing/datum/
Date Sun, 17 Nov 2013 20:36:12 GMT
Author: desruisseaux
Date: Sun Nov 17 20:36:12 2013
New Revision: 1542807

URL: http://svn.apache.org/r1542807
Log:
Added DefaultGeodeticDatumTest.testToWKT() test case.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1542807&r1=1542806&r2=1542807&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Sun Nov 17 20:36:12 2013
@@ -46,6 +46,7 @@ import org.apache.sis.util.ArgumentCheck
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.AbstractIdentifiedObject;
 
 
 /**
@@ -491,11 +492,9 @@ public class Formatter {
      */
     public void append(final IdentifiedObject object) {
         if (object != null) {
-            if (object instanceof Formattable) {
-                append((Formattable) object);
-            } else {
-                throw unsupported(object);
-            }
+            append((object instanceof Formattable)
+                    ? (Formattable) object
+                    : AbstractIdentifiedObject.castOrCopy(object));
         }
     }
 
@@ -509,23 +508,13 @@ public class Formatter {
             if (transform instanceof Formattable) {
                 append((Formattable) transform);
             } else {
-                throw unsupported(transform);
+                throw new UnformattableObjectException(Errors.format(
+                        Errors.Keys.IllegalClass_2, Formattable.class, transform.getClass()));
             }
         }
     }
 
     /**
-     * Invoked when an object is not a supported implementation.
-     *
-     * @param object The object of unknown type.
-     * @return The exception to be thrown.
-     */
-    private static UnformattableObjectException unsupported(final Object object) {
-        return new UnformattableObjectException(Errors.format(
-                Errors.Keys.IllegalClass_2, Formattable.class, object.getClass()));
-    }
-
-    /**
      * Appends a {@linkplain ParameterValue parameter} in WKT form.
      * If the supplied parameter is actually a {@linkplain ParameterValueGroup parameter
group},
      * all contained parameters will flattened in a single list.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1542807&r1=1542806&r2=1542807&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] Sun Nov 17 20:36:12 2013
@@ -39,6 +39,7 @@ import org.apache.sis.util.logging.Loggi
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.io.wkt.Formattable;
 
 import static org.apache.sis.util.Utilities.deepEquals;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -474,7 +475,9 @@ public class DefaultGeodeticDatum extend
     public String formatTo(final Formatter formatter) {
         // Do NOT invokes the super-class method, because
         // horizontal datum do not write the datum type.
-        formatter.append(ellipsoid);
+        formatter.append((ellipsoid instanceof Formattable)
+                ? (Formattable) ellipsoid
+                : DefaultEllipsoid.castOrCopy(ellipsoid));
         if (bursaWolf != null) {
             for (final BursaWolfParameters candidate : bursaWolf) {
                 if (candidate.isToWGS84()) {

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java?rev=1542807&r1=1542806&r2=1542807&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
[UTF-8] Sun Nov 17 20:36:12 2013
@@ -32,7 +32,7 @@ import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.referencing.Assert.*;
 import static org.apache.sis.test.mock.GeodeticDatumMock.*;
 
 
@@ -44,7 +44,11 @@ import static org.apache.sis.test.mock.G
  * @version 0.4
  * @module
  */
-@DependsOn({DefaultEllipsoidTest.class, BursaWolfParametersTest.class})
+@DependsOn({
+  DefaultPrimeMeridianTest.class,
+  DefaultEllipsoidTest.class,
+  BursaWolfParametersTest.class
+})
 public final strictfp class DefaultGeodeticDatumTest extends TestCase {
     /**
      * Tests the creation and serialization of a {@link DefaultGeodeticDatum}.
@@ -148,4 +152,15 @@ public final strictfp class DefaultGeode
         assertEquals("tY", expected.tY, actual.getElement(1, 3), tolerance);
         assertEquals("tZ", expected.tZ, actual.getElement(2, 3), tolerance);
     }
+
+    /**
+     * Tests {@link DefaultEllipsoid#toWKT()}.
+     */
+    @Test
+    public void testToWKT() {
+        final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(WGS84);
+        assertWktEquals(datum,
+                "DATUM[“WGS84”,\n" +
+                "  SPHEROID[“WGS84”, 6378137.0, 298.257223563]]");
+    }
 }



Mime
View raw message