sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1653363 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/test/java/org/apache/sis/internal/referencing/ sis-utility/src/main/java/org/apache/sis/util/resources/
Date Tue, 20 Jan 2015 20:41:08 GMT
Author: desruisseaux
Date: Tue Jan 20 20:41:08 2015
New Revision: 1653363

URL: http://svn.apache.org/r1653363
Log:
More accurate error message in case of mismatched source/target dimensions.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java?rev=1653363&r1=1653362&r2=1653363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
[UTF-8] Tue Jan 20 20:41:08 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.referencing;
 
+import java.util.Map;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.OperationMethod;
@@ -62,12 +63,13 @@ public final class OperationMethods exte
      *       is taken. Only one non-ignorable step may exist, otherwise we do not try to
select any of them.</li>
      * </ul>
      *
-     * @param  method    The operation method to compare to the math transform.
-     * @param  transform The math transform to compare to the operation method.
+     * @param  method     The operation method to compare to the math transform.
+     * @param  transform  The math transform to compare to the operation method.
+     * @param  properties Properties of the caller object being constructed, used only for
formatting error message.
      * @throws IllegalArgumentException if the number of dimensions are incompatible.
      */
-    public static void checkDimensions(final OperationMethod method, MathTransform transform)
-            throws IllegalArgumentException
+    public static void checkDimensions(final OperationMethod method, MathTransform transform,
+            final Map<String,?> properties) throws IllegalArgumentException
     {
         int actual = transform.getSourceDimensions();
         Integer expected = method.getSourceDimensions();
@@ -96,18 +98,17 @@ public final class OperationMethods exte
          * Now verify if the MathTransform dimensions are equal to the OperationMethod ones,
          * ignoring null java.lang.Integer instances.
          */
-        final String name;
+        byte isTarget = 0; // false: wrong dimension is the source one.
         if (expected == null || actual == expected) {
             actual = transform.getTargetDimensions();
             expected = method.getTargetDimensions();
             if (expected == null || actual == expected) {
                 return;
             }
-            name = "transform.target";
-        } else {
-            name = "transform.source";
+            isTarget = 1; // true: wrong dimension is the target one.
         }
-        throw new IllegalArgumentException(Errors.format(Errors.Keys.MismatchedDimension_3,
name, expected, actual));
+        throw new IllegalArgumentException(Errors.getResources(properties).getString(
+                Errors.Keys.MismatchedTransformDimension_3, isTarget, expected, actual));
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java?rev=1653363&r1=1653362&r2=1653363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
[UTF-8] Tue Jan 20 20:41:08 2015
@@ -17,6 +17,8 @@
 package org.apache.sis.internal.referencing;
 
 import java.util.Collections;
+import java.util.Locale;
+import java.util.Map;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.OperationMethod;
@@ -58,16 +60,23 @@ public final strictfp class OperationMet
      */
     @Test
     public void testCheckDimensions() {
+        final Map<String,?> properties = Collections.singletonMap("locale", Locale.ENGLISH);
         final MathTransform tr = MathTransformsTest.createConcatenateAndPassThrough();
-        OperationMethods.checkDimensions(createOperationMethod(3, 3), tr);
-        OperationMethods.checkDimensions(createOperationMethod(1, 1), tr);
+        OperationMethods.checkDimensions(createOperationMethod(3, 3), tr, properties);
+        OperationMethods.checkDimensions(createOperationMethod(1, 1), tr, properties);
         try {
-            OperationMethods.checkDimensions(createOperationMethod(2, 2), tr);
-            fail("OperationMethod of dimension 2 shall be considered incompatible.");
+            OperationMethods.checkDimensions(createOperationMethod(2, 2), tr, properties);
+            fail("MathTransform.sourceDimension == 3 shall be considered incompatible.");
         } catch (IllegalArgumentException e) {
             // This is the expected exception.
-            final String message = e.getMessage();
-            assertTrue(message, message.contains("transform.source"));
+            assertEquals(e.getMessage(), "The transform has 1 source dimension, while 2 was
expected.");
+        }
+        try {
+            OperationMethods.checkDimensions(createOperationMethod(3, 1), tr, properties);
+            fail("MathTransform.targetDimension == 3 shall be considered incompatible.");
+        } catch (IllegalArgumentException e) {
+            // This is the expected exception.
+            assertEquals(e.getMessage(), "The transform has 3 target dimensions, while 1
was expected.");
         }
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1653363&r1=1653362&r2=1653363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Tue Jan 20 20:41:08 2015
@@ -489,6 +489,12 @@ public final class Errors extends Indexe
         public static final short MismatchedPropertyType_1 = 154;
 
         /**
+         * The transform has {2} {0,choice,0#source|1#target} dimension{2,choice,1#|2#s},
while {1} was
+         * expected.
+         */
+        public static final short MismatchedTransformDimension_3 = 178;
+
+        /**
          * Class of “{0}” values is ‘{2}’, but the requested type is ‘{1}’.
          */
         public static final short MismatchedValueClass_3 = 157;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1653363&r1=1653362&r2=1653363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Tue Jan 20 20:41:08 2015
@@ -108,6 +108,7 @@ MismatchedDimension_3             = Argu
 MismatchedMatrixSize_4            = Mismatched matrix sizes: expected {0}\u00d7{1} but got
{2}\u00d7{3}.
 MismatchedParameterDescriptor_1   = Mismatched descriptor for \u201c{0}\u201d parameter.
 MismatchedPropertyType_1          = Mismatched type for \u201c{0}\u201d property.
+MismatchedTransformDimension_3    = The transform has {2} {0,choice,0#source|1#target} dimension{2,choice,1#|2#s},
while {1} was expected.
 MismatchedValueClass_3            = Class of \u201c{0}\u201d values is \u2018{2}\u2019, but
the requested type is \u2018{1}\u2019.
 MissingAuthority_1                = No authority was specified for code \u201c{0}\u201d.
The expected syntax is \u201cAUTHORITY:CODE\u201d.
 MissingNamespace_1                = \u201c{0}\u201d has no namespace.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1653363&r1=1653362&r2=1653363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Tue Jan 20 20:41:08 2015
@@ -98,6 +98,7 @@ MismatchedDimension_3             = L\u2
 MismatchedMatrixSize_4            = Une matrice de taille de {0}\u00d7{1} \u00e9tait attendue
mais la matrice donn\u00e9es est de taille {2}\u00d7{3}.
 MismatchedParameterDescriptor_1   = Le descripteur du param\u00e8tre \u00ab\u202f{0}\u202f\u00bb
ne correspond pas.
 MismatchedPropertyType_1          = Le type de la propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb
ne correspond pas.
+MismatchedTransformDimension_3    = La {0,choice,0#source|1#destination} de la transformation
a {2} dimension{2,choice,1#|2#s}, alors qu\u2019on en attendait {1}.
 MismatchedValueClass_3            = Les valeurs de \u00ab\u202f{0}\u202f\u00bb sont de la
classe \u2018{2}\u2019, alors que le type demand\u00e9 \u00e9tait \u2018{1}\u2019.
 MissingAuthority_1                = Aucune autorit\u00e9 n\u2019a \u00e9t\u00e9 sp\u00e9cifi\u00e9e
pour le code \u00ab\u202f{0}\u202f\u00bb. Le format attendu est \u00ab\u202fAUTORIT\u00c9:CODE\u202f\u00bb.
 MissingNamespace_1                = \u201c{0}\u201d est d\u00e9fini sans espace de noms.



Mime
View raw message