sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1675720 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
Date Thu, 23 Apr 2015 21:15:30 GMT
Author: desruisseaux
Date: Thu Apr 23 21:15:30 2015
New Revision: 1675720

URL: http://svn.apache.org/r1675720
Log:
Utilities: leverage a little bit more ArgumentChecks.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1675720&r1=1675719&r2=1675720&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] Thu Apr 23 21:15:30 2015
@@ -480,32 +480,12 @@ public final class Matrices extends Stat
     {
         ArgumentChecks.ensureNonNull("srcEnvelope", srcEnvelope);
         ArgumentChecks.ensureNonNull("dstEnvelope", dstEnvelope);
-        ensureDimensionMatch("srcEnvelope", srcEnvelope, srcAxes.length);
-        ensureDimensionMatch("dstEnvelope", dstEnvelope, dstAxes.length);
+        ArgumentChecks.ensureDimensionMatches("srcEnvelope", srcAxes.length, srcEnvelope);
+        ArgumentChecks.ensureDimensionMatches("dstEnvelope", dstAxes.length, dstEnvelope);
         return createTransform(srcEnvelope, srcAxes, dstEnvelope, dstAxes, true);
     }
 
     /**
-     * Convenience method for checking object dimension validity.
-     * This method is invoked for argument checking.
-     *
-     * @param  name      The name of the argument to check.
-     * @param  envelope  The envelope to check.
-     * @param  dimension The expected dimension for the object.
-     * @throws MismatchedDimensionException if the envelope doesn't have the expected dimension.
-     */
-    private static void ensureDimensionMatch(final String name, final Envelope envelope,
-            final int dimension) throws MismatchedDimensionException
-    {
-        ArgumentChecks.ensureNonNull(name, envelope);
-        final int dim = envelope.getDimension();
-        if (dimension != dim) {
-            throw new MismatchedDimensionException(Errors.format(
-                    Errors.Keys.MismatchedDimension_3, name, dimension, dim));
-        }
-    }
-
-    /**
      * Creates a matrix for a transform that keep only a subset of source ordinate values.
      * The matrix size will be ({@code selectedDimensions.length}+1) × ({@code sourceDimensions}+1).
      * The matrix will contain only zero elements, except for the following cells which will
contain 1:

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java?rev=1675720&r1=1675719&r2=1675720&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
[UTF-8] Thu Apr 23 21:15:30 2015
@@ -81,7 +81,7 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.6
  * @module
  */
 public final class ArgumentChecks extends Static {
@@ -593,6 +593,30 @@ public final class ArgumentChecks extend
             }
         }
     }
+
+    /**
+     * Ensures that the given coordinate system, if non-null, has the expected number of
dimensions.
+     * This method does nothing if the given coordinate system is null.
+     *
+     * @param  name     The name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  expected The expected number of dimensions.
+     * @param  cs       The coordinate system to check for its dimension, or {@code null}.
+     * @throws MismatchedDimensionException if the given coordinate system is non-null
+     *         and does not have the expected number of dimensions.
+     *
+     * @since 0.6
+     */
+    public static void ensureDimensionMatches(final String name, final int expected,
+            final CoordinateSystem cs) throws MismatchedDimensionException
+    {
+        if (cs != null) {
+            final int dimension = cs.getDimension();
+            if (dimension != expected) {
+                throw new MismatchedDimensionException(Errors.format(
+                        Errors.Keys.MismatchedDimension_3, name, expected, dimension));
+            }
+        }
+    }
 
     /**
      * Ensures that the given vector, if non-null, has the expected number of dimensions



Mime
View raw message