commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r959634 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/interpolation/ main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/util/ main/resources/META-INF/localization/ test/java/org/...
Date Thu, 01 Jul 2010 12:30:44 GMT
Author: erans
Date: Thu Jul  1 12:30:43 2010
New Revision: 959634

URL: http://svn.apache.org/viewvc?rev=959634&view=rev
Log:
MATH-361
Added new exceptions. Replaced several instances of "IllegalArgumentException"
with a more specific exception.
For not yet released code, removed the checked "DimensionMismatchException"
from the method signature and replaced its instances with the new (unchecked)
version of the exception.
Corrected typos in Javadoc comments.

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
  (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
  (with props)
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NonMonotonousSequenceExceptionTest.java
  (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java
    commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java
Thu Jul  1 12:30:43 2010
@@ -114,8 +114,8 @@ public class BicubicSplineInterpolatingF
             throw new DimensionMismatchException(xLen, d2FdXdY.length);
         }
 
-        MathUtils.checkOrder(x, 1, true);
-        MathUtils.checkOrder(y, 1, true);
+        MathUtils.checkOrder(x);
+        MathUtils.checkOrder(y);
 
         xval = x.clone();
         yval = y.clone();

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java
Thu Jul  1 12:30:43 2010
@@ -46,8 +46,8 @@ public class BicubicSplineInterpolator
             throw new DimensionMismatchException(xval.length, fval.length);
         }
 
-        MathUtils.checkOrder(xval, 1, true);
-        MathUtils.checkOrder(yval, 1, true);
+        MathUtils.checkOrder(xval);
+        MathUtils.checkOrder(yval);
 
         final int xLen = xval.length;
         final int yLen = yval.length;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java
Thu Jul  1 12:30:43 2010
@@ -16,10 +16,9 @@
  */
 package org.apache.commons.math.analysis.interpolation;
 
-import org.apache.commons.math.DimensionMismatchException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.NoDataException;
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.util.LocalizedFormats;
 import org.apache.commons.math.util.MathUtils;
 import org.apache.commons.math.optimization.general.GaussNewtonOptimizer;
 import org.apache.commons.math.optimization.fitting.PolynomialFitter;
@@ -70,9 +69,9 @@ public class SmoothingPolynomialBicubicS
     public BicubicSplineInterpolatingFunction interpolate(final double[] xval,
                                                           final double[] yval,
                                                           final double[][] fval)
-        throws MathException, IllegalArgumentException {
+        throws MathException {
         if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA);
+            throw new NoDataException();
         }
         if (xval.length != fval.length) {
             throw new DimensionMismatchException(xval.length, fval.length);
@@ -87,8 +86,8 @@ public class SmoothingPolynomialBicubicS
             }
         }
 
-        MathUtils.checkOrder(xval, 1, true);
-        MathUtils.checkOrder(yval, 1, true);
+        MathUtils.checkOrder(xval);
+        MathUtils.checkOrder(yval);
 
         // For each line y[j] (0 <= j < yLen), construct a polynomial, with
         // respect to variable x, fitting array fval[][j]

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java
Thu Jul  1 12:30:43 2010
@@ -18,8 +18,9 @@ package org.apache.commons.math.analysis
 
 import org.apache.commons.math.util.LocalizedFormats;
 import org.apache.commons.math.util.MathUtils;
-import org.apache.commons.math.MathRuntimeException;
-import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.exception.NoDataException;
+import org.apache.commons.math.exception.OutOfRangeException;
+import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.analysis.TrivariateRealFunction;
 
 /**
@@ -134,6 +135,7 @@ public class TricubicSplineInterpolating
      * every grid point.
      * @param d3FdXdYdZ Values of the cross partial derivative of function on
      * every grid point.
+     * @throws NoDataException if any of the arrays has zero length.
      * @throws DimensionMismatchException if the various arrays do not contain
      * the expected number of elements.
      * @throws IllegalArgumentException if {@code x}, {@code y} or {@code z}
@@ -149,15 +151,14 @@ public class TricubicSplineInterpolating
                                                double[][][] d2FdXdY,
                                                double[][][] d2FdXdZ,
                                                double[][][] d2FdYdZ,
-                                               double[][][] d3FdXdYdZ)
-        throws DimensionMismatchException {
+                                               double[][][] d3FdXdYdZ) {
         final int xLen = x.length;
         final int yLen = y.length;
         final int zLen = z.length;
 
         if (xLen == 0 || yLen == 0 || z.length == 0
             || f.length == 0 || f[0].length == 0) {
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA);
+            throw new NoDataException();
         }
         if (xLen != f.length) {
             throw new DimensionMismatchException(xLen, f.length);
@@ -184,9 +185,9 @@ public class TricubicSplineInterpolating
             throw new DimensionMismatchException(xLen, d3FdXdYdZ.length);
         }
 
-        MathUtils.checkOrder(x, 1, true);
-        MathUtils.checkOrder(y, 1, true);
-        MathUtils.checkOrder(z, 1, true);
+        MathUtils.checkOrder(x);
+        MathUtils.checkOrder(y);
+        MathUtils.checkOrder(z);
 
         xval = x.clone();
         yval = y.clone();
@@ -308,21 +309,15 @@ public class TricubicSplineInterpolating
     public double value(double x, double y, double z) {
         final int i = searchIndex(x, xval);
         if (i == -1) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-                  x, xval[0], xval[xval.length - 1]);
+            throw new OutOfRangeException(x, xval[0], xval[xval.length - 1]);
         }
         final int j = searchIndex(y, yval);
         if (j == -1) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-                  y, yval[0], yval[yval.length - 1]);
+            throw new OutOfRangeException(y, yval[0], yval[yval.length - 1]);
         }
         final int k = searchIndex(z, zval);
         if (k == -1) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-                  z, zval[0], zval[zval.length - 1]);
+            throw new OutOfRangeException(z, zval[0], zval[zval.length - 1]);
         }
 
         final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]);
@@ -453,16 +448,13 @@ class TricubicSplineFunction
      */
     public double value(double x, double y, double z) {
         if (x < 0 || x > 1) {
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-                                                                      x, 0, 1);
+            throw new OutOfRangeException(x, 0, 1);
         }
         if (y < 0 || y > 1) {
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-                                                                      y, 0, 1);
+            throw new OutOfRangeException(y, 0, 1);
         }
         if (z < 0 || z > 1) {
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-                                                                      z, 0, 1);
+            throw new OutOfRangeException(z, 0, 1);
         }
 
         final double x2 = x * x;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java
Thu Jul  1 12:30:43 2010
@@ -16,10 +16,9 @@
  */
 package org.apache.commons.math.analysis.interpolation;
 
-import org.apache.commons.math.DimensionMismatchException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.NoDataException;
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.util.LocalizedFormats;
 import org.apache.commons.math.util.MathUtils;
 
 /**
@@ -37,17 +36,17 @@ public class TricubicSplineInterpolator
                                                            final double[] yval,
                                                            final double[] zval,
                                                            final double[][][] fval)
-        throws MathException, IllegalArgumentException {
+        throws MathException {
         if (xval.length == 0 || yval.length == 0 || zval.length == 0 || fval.length == 0)
{
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA);
+            throw new NoDataException();
         }
         if (xval.length != fval.length) {
             throw new DimensionMismatchException(xval.length, fval.length);
         }
 
-        MathUtils.checkOrder(xval, 1, true);
-        MathUtils.checkOrder(yval, 1, true);
-        MathUtils.checkOrder(zval, 1, true);
+        MathUtils.checkOrder(xval);
+        MathUtils.checkOrder(yval);
+        MathUtils.checkOrder(zval);
 
         final int xLen = xval.length;
         final int yLen = yval.length;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java
Thu Jul  1 12:30:43 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.analysis.
  * sample points must be specified on a regular grid.
  *
  * @version $Revision$ $Date$
+ * @since 2.2
  */
 public interface TrivariateRealGridInterpolator {
     /**
@@ -37,7 +38,9 @@ public interface TrivariateRealGridInter
      * in increasing order.
      * @param fval the values of the interpolation points on all the grid knots:
      * {@code fval[i][j][k] = f(xval[i], yval[j], zval[k])}.
-     * @return a function which interpolates the data set.
+     * @return a function that interpolates the data set.
+     * @throws NoDataException if any of the arrays has zero length.
+     * @throws DimensionMismatchException if the array lengths are inconsistent.
      * @throws MathException if arguments violate assumptions made by the
      *         interpolation algorithm.
      */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
Thu Jul  1 12:30:43 2010
@@ -34,7 +34,7 @@ public class MathIllegalNumberException 
     /**
      * Construct an exception.
      *
-     * @param Localizable pattern.
+     * @param pattern Localizable pattern.
      * @param arguments Arguments. The first element must be the requested
      * value that raised the exception.
      */

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java?rev=959634&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
(added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
Thu Jul  1 12:30:43 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.exception;
+
+import org.apache.commons.math.util.LocalizedFormats;
+
+/**
+ * Exception to be thrown when the required data is missing.
+ *
+ * @since 2.2
+ * @version $Revision$ $Date$
+ */
+public class NoDataException extends MathIllegalArgumentException {
+    /**
+     * Construct the exception.
+     */
+    public NoDataException() {
+        super(LocalizedFormats.NO_DATA, null);
+    }
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java?rev=959634&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
(added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
Thu Jul  1 12:30:43 2010
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.exception;
+
+import org.apache.commons.math.util.LocalizedFormats;
+import org.apache.commons.math.util.MathUtils;
+
+/**
+ * Exception to be thrown when the a sequence of values is not monotonously
+ * increasing or decreasing.
+ *
+ * @since 2.2
+ * @version $Revision$ $Date$
+ */
+public class NonMonotonousSequenceException extends MathIllegalNumberException {
+    /**
+     * Direction (positive for increasing, negative for decreasing).
+     */
+    private final MathUtils.Order.Direction direction;
+    /**
+     * Whether the sequence must be strictly increasing or decreasing.
+     */
+    private final boolean strict;
+    /**
+     * Index of the wrong value.
+     */
+    private final int index;
+    /**
+     * Previous value.
+     */
+    private final Number previous;
+
+    /**
+     * Construct the exception.
+     * This constructor uses default values assuming that the sequence should
+     * have been strictly increasing.
+     *
+     * @param wrong Value that did not match the requirements.
+     * @param previous Previous value in the sequence.
+     * @param index Index of the value that did not match the requirements.
+     */
+    public NonMonotonousSequenceException(Number wrong,
+                                          Number previous,
+                                          int index) {
+        this(wrong, previous, index, MathUtils.Order.Direction.INCREASING, true);
+    }
+
+    /**
+     * Construct the exception.
+     *
+     * @param wrong Value that did not match the requirements.
+     * @param previous Previous value in the sequence.
+     * @param index Index of the value that did not match the requirements.
+     * @param direction Strictly positive for a sequence required to be
+     * increasing, negative (or zero) for a decreasing sequence.
+     * @param strict Whether the sequence must be strictly increasing or
+     * decreasing.
+     */
+    public NonMonotonousSequenceException(Number wrong,
+                                          Number previous,
+                                          int index,
+                                          MathUtils.Order.Direction direction,
+                                          boolean strict) {
+        super(direction == MathUtils.Order.Direction.INCREASING ?
+              (strict ?
+               LocalizedFormats.NOT_STRICTLY_INCREASING_SEQUENCE :
+               LocalizedFormats.NOT_INCREASING_SEQUENCE) :
+              (strict ?
+               LocalizedFormats.NOT_STRICTLY_DECREASING_SEQUENCE :
+               LocalizedFormats.NOT_DECREASING_SEQUENCE),
+              wrong, previous, index, index - 1);
+
+        this.direction = direction;
+        this.strict = strict;
+        this.index = index;
+        this.previous = previous;
+    }
+
+    /**
+     * @return the order direction.
+     **/
+    public MathUtils.Order.Direction getDirection() {
+        return direction;
+    }
+    /**
+     * @return {@code true} is the sequence should be strictly monotonous.
+     **/
+    public boolean getStrict() {
+        return strict;
+    }
+    /**
+     * Get the index of the wrong value.
+     *
+     * @return the current index.
+     */
+    public int getIndex() {
+        return index;
+    }
+    /**
+     * @return the previous value.
+     */
+    public Number getPrevious() {
+        return previous;
+    }
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java
Thu Jul  1 12:30:43 2010
@@ -160,9 +160,11 @@ public enum LocalizedFormats implements 
     NORMALIZE_NAN("Cannot normalize to NaN"),
     NOT_ADDITION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not addition compatible"),
     NOT_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not decreasing ({2} < {3})"),
+    NOT_DECREASING_SEQUENCE("points {3} and {2} are not decreasing ({1} < {0})"), /* keep
*/
     NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS("not enough data ({0} rows) for this many predictors
({1} predictors)"),
     NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION("spline partition must have at least {0} points,
got {1}"),
     NOT_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not increasing ({2} > {3})"),
+    NOT_INCREASING_SEQUENCE("points {3} and {2} are not increasing ({1} > {0})"), /* keep
*/
     NOT_MULTIPLICATION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not multiplication
compatible"),
     NOT_STRICTLY_POSITIVE("{0} is not strictly positive"), /* keep */
     NOT_POSITIVE("{0} is not positive"), /* keep */
@@ -190,13 +192,15 @@ public enum LocalizedFormats implements 
     NOT_POWER_OF_TWO_CONSIDER_PADDING("{0} is not a power of 2, consider padding for fix"),
     NOT_POWER_OF_TWO_PLUS_ONE("{0} is not a power of 2 plus one"),
     NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not strictly decreasing
({2} <= {3})"),
+    NOT_STRICTLY_DECREASING_SEQUENCE("points {3} and {2} are not strictly decreasing ({1}
<= {0})"), /* keep */
     NOT_STRICTLY_INCREASING_KNOT_VALUES("knot values must be strictly increasing"),
     NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not strictly increasing
({2} >= {3})"),
+    NOT_STRICTLY_INCREASING_SEQUENCE("points {3} and {2} are not strictly increasing ({1}
>= {0})"), /* keep */
     NOT_SUBTRACTION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not subtraction
compatible"),
     NOT_SYMMETRIC_MATRIX("not symmetric matrix"),
     NO_BIN_SELECTED("no bin selected"),
     NO_CONVERGENCE_WITH_ANY_START_POINT("none of the {0} start points lead to convergence"),
-    NO_DATA("no data"),
+    NO_DATA("no data"), /* keep */
     NO_DEGREES_OF_FREEDOM("no degrees of freedom ({0} measurements, {1} parameters)"),
     NO_DENSITY_FOR_THIS_DISTRIBUTION("This distribution does not have a density function
implemented"),
     NO_FEASIBLE_SOLUTION("no feasible solution"),

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Thu
Jul  1 12:30:43 2010
@@ -22,6 +22,7 @@ import java.math.BigInteger;
 import java.util.Arrays;
 
 import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NonMonotonousSequenceException;
 
 /**
  * Some useful additions to the built-in functions in {@link Math}.
@@ -413,7 +414,7 @@ public final class MathUtils {
      * 3.0, the semantics will change in order to comply with IEEE754 where it
      * is specified that {@code NaN != NaN}.
      * New methods have been added for those cases wher the old semantics is
-     * useful (see e.g. {@link equalsIncludingNaN(double,double)
+     * useful (see e.g. {@link #equalsIncludingNaN(double,double)
      * equalsIncludingNaN}.
      */
     public static boolean equals(double x, double y) {
@@ -525,7 +526,7 @@ public final class MathUtils {
      * 3.0, the semantics will change in order to comply with IEEE754 where it
      * is specified that {@code NaN != NaN}.
      * New methods have been added for those cases wher the old semantics is
-     * useful (see e.g. {@link equalsIncludingNaN(double[],double[])
+     * useful (see e.g. {@link #equalsIncludingNaN(double[],double[])
      * equalsIncludingNaN}.
      */
     public static boolean equals(double[] x, double[] y) {
@@ -1866,46 +1867,87 @@ public final class MathUtils {
         return max;
     }
 
+    public static class Order {
+        public static enum Direction {
+                INCREASING,
+                DECREASING
+        };
+    }
+
     /**
      * Checks that the given array is sorted.
      *
-     * @param val Values
-     * @param dir Order direction (-1 for decreasing, 1 for increasing)
-     * @param strict Whether the order should be strict
-     * @throws IllegalArgumentException if the array is not sorted.
+     * @param val Values.
+     * @param dir Order direction.
+     * @param strict Whether the order should be strict.
+     * @throws NonMonotonousSequenceException if the array is not sorted.
      */
-    public static void checkOrder(double[] val, int dir, boolean strict) {
+    public static void checkOrder(double[] val, Order.Direction dir, boolean strict) {
         double previous = val[0];
+        boolean ok = true;
 
         int max = val.length;
         for (int i = 1; i < max; i++) {
-            if (dir > 0) {
+            switch (dir) {
+            case INCREASING:
                 if (strict) {
                     if (val[i] <= previous) {
-                        throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS,
-                                                                                  i - 1,
i, previous, val[i]);
+                        ok = false;
                     }
                 } else {
                     if (val[i] < previous) {
-                        throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_INCREASING_NUMBER_OF_POINTS,
-                                                                                  i - 1,
i, previous, val[i]);
+                        ok = false;
                     }
                 }
-            } else {
+                break;
+            case DECREASING:
                 if (strict) {
                     if (val[i] >= previous) {
-                        throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS,
-                                                                                  i - 1,
i, previous, val[i]);
+                        ok = false;
                     }
                 } else {
                     if (val[i] > previous) {
-                        throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_DECREASING_NUMBER_OF_POINTS,
-                                                                                  i - 1,
i, previous, val[i]);
+                        ok = false;
                     }
                 }
+                break;
+            default:
+                // Should never happen.
+                throw new IllegalArgumentException();
             }
 
+            if (!ok) {
+                throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
+            }
             previous = val[i];
         }
     }
+
+    /**
+     * Checks that the given array is sorted in strictly increasing order.
+     *
+     * @param val Values.
+     * @throws NonMonotonousSequenceException if the array is not sorted.
+     */
+    public static void checkOrder(double[] val) {
+        checkOrder(val, Order.Direction.INCREASING, true);
+    }
+
+    /**
+     * Checks that the given array is sorted.
+     *
+     * @param val Values
+     * @param dir Order direction (-1 for decreasing, 1 for increasing)
+     * @param strict Whether the order should be strict
+     * @throws NonMonotonousSequenceException if the array is not sorted.
+     * @deprecated as of 2.2 (please use the new {@link #checkOrder(double[],Order.Direction,boolean)
+     * checkOrder} method). To be removed in 3.0.
+     */
+    public static void checkOrder(double[] val, int dir, boolean strict) {
+        if (dir > 0) {
+            checkOrder(val, Order.Direction.INCREASING, strict);
+        } else {
+            checkOrder(val, Order.Direction.DECREASING, strict);
+        }
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java
Thu Jul  1 12:30:43 2010
@@ -206,7 +206,7 @@ public class MultidimensionalCounter imp
      * Convert to multidimensional counter.
      *
      * @param index Index in unidimensional counter.
-     * @returns the multidimensional counts.
+     * @return the multidimensional counts.
      * @throws {@link OutOfRangeException} if {@code index} is not between
      * {@code 0} and the value returned by {@link #getSize()} (excluded).
      */

Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
(original)
+++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
Thu Jul  1 12:30:43 2010
@@ -132,9 +132,11 @@ NORMALIZE_INFINITE = impossible de norma
 NORMALIZE_NAN = impossible de normaliser vers NaN
 NOT_ADDITION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour
l''addition matricielle
 NOT_DECREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas d\u00e9croissants ({2}
< {3})
+NOT_DECREASING_SEQUENCE = les points {3} et {2} ne sont pas d\u00e9croissants ({1} < {0})
 NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS = pas assez de donn\u00e9es ({0} lignes) pour {1}
pr\u00e9dicteurs
 NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION = une partiction spline n\u00e9cessite au moins {0}
points, seuls {1} ont \u00e9t\u00e9 fournis
 NOT_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas croissants ({2} >
{3})
+NOT_INCREASING_SEQUENCE = les points {3} et {2} ne sont pas croissants ({1} > {0})
 NOT_MULTIPLICATION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles
pour la multiplication matricielle
 NOT_STRICTLY_POSITIVE = {0} n''est pas strictement positif
 NOT_POSITIVE = {0} n''est pas positif
@@ -162,8 +164,10 @@ NOT_POWER_OF_TWO = {0} n''est pas une pu
 NOT_POWER_OF_TWO_CONSIDER_PADDING = {0} n''est pas une puissance de 2, ajoutez des \u00e9l\u00e9ments
pour corriger
 NOT_POWER_OF_TWO_PLUS_ONE = {0} n''est pas une puissance de 2 plus un
 NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas strictement
d\u00e9croissants ({2} <= {3})
+NOT_STRICTLY_DECREASING_SEQUENCE = les points {3} et {2} ne sont pas strictement d\u00e9croissants
({1} <= {0})
 NOT_STRICTLY_INCREASING_KNOT_VALUES = les n\u0153uds d''interpolation doivent \u00eatre strictement
croissants
 NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas strictement
croissants ({2} >= {3})
+NOT_STRICTLY_INCREASING_SEQUENCE = les points {3} et {2} ne sont pas strictement croissants
({1} >= {0})
 NOT_SUBTRACTION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles
pour la soustraction matricielle
 NOT_SYMMETRIC_MATRIX = matrice non symm\u00e9trique
 NO_BIN_SELECTED = aucun compartiment s\u00e9lectionn\u00e9

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java
Thu Jul  1 12:30:43 2010
@@ -17,7 +17,7 @@
 package org.apache.commons.math.analysis.interpolation;
 
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.analysis.BivariateRealFunction;
 import org.junit.Assert;
 import org.junit.Test;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java
Thu Jul  1 12:30:43 2010
@@ -17,7 +17,7 @@
 package org.apache.commons.math.analysis.interpolation;
 
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.analysis.TrivariateRealFunction;
 import org.junit.Assert;
 import org.junit.Test;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java
Thu Jul  1 12:30:43 2010
@@ -17,7 +17,7 @@
 package org.apache.commons.math.analysis.interpolation;
 
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.analysis.TrivariateRealFunction;
 import org.junit.Assert;
 import org.junit.Test;

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NonMonotonousSequenceExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NonMonotonousSequenceExceptionTest.java?rev=959634&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NonMonotonousSequenceExceptionTest.java
(added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NonMonotonousSequenceExceptionTest.java
Thu Jul  1 12:30:43 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.exception;
+
+import org.apache.commons.math.util.MathUtils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {@link NonMonotonousSequenceException}.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public class NonMonotonousSequenceExceptionTest {
+    @Test
+    public void testAccessors() {
+        NonMonotonousSequenceException e
+            = new NonMonotonousSequenceException(0, -1, 1, MathUtils.Order.Direction.DECREASING,
false);
+        Assert.assertEquals(0, e.getArgument());
+        Assert.assertEquals(-1, e.getPrevious());
+        Assert.assertEquals(1, e.getIndex());
+        Assert.assertTrue(e.getDirection() == MathUtils.Order.Direction.DECREASING);
+        Assert.assertFalse(e.getStrict());
+
+        e = new NonMonotonousSequenceException(-1, 0, 1);
+        Assert.assertEquals(-1, e.getArgument());
+        Assert.assertEquals(0, e.getPrevious());
+        Assert.assertEquals(1, e.getIndex());
+        Assert.assertTrue(e.getDirection() == MathUtils.Order.Direction.INCREASING);
+        Assert.assertTrue(e.getStrict());
+    }
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NonMonotonousSequenceExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=959634&r1=959633&r2=959634&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
Thu Jul  1 12:30:43 2010
@@ -24,6 +24,7 @@ import junit.framework.TestCase;
 
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.random.RandomDataImpl;
+import org.apache.commons.math.exception.NonMonotonousSequenceException;
 
 /**
  * Test cases for the MathUtils class.
@@ -1469,33 +1470,41 @@ public final class MathUtilsTest extends
     }
 
     public void testCheckOrder() {
-        MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 15}, 1, true);
-        MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 2}, 1, false);
-        MathUtils.checkOrder(new double[] {3, -5.5, -11, -27.5}, -1, true);
-        MathUtils.checkOrder(new double[] {3, 0, 0, -5.5, -11, -27.5}, -1, false);
+        MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 15},
+                             MathUtils.Order.Direction.INCREASING, true);
+        MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 2},
+                             MathUtils.Order.Direction.INCREASING, false);
+        MathUtils.checkOrder(new double[] {3, -5.5, -11, -27.5},
+                             MathUtils.Order.Direction.DECREASING, true);
+        MathUtils.checkOrder(new double[] {3, 0, 0, -5.5, -11, -27.5},
+                             MathUtils.Order.Direction.DECREASING, false);
 
         try {
-            MathUtils.checkOrder(new double[] {-15, -5.5, -1, -1, 2, 15}, 1, true);
+            MathUtils.checkOrder(new double[] {-15, -5.5, -1, -1, 2, 15},
+                                 MathUtils.Order.Direction.INCREASING, true);
             fail("an exception should have been thrown");
-        } catch (IllegalArgumentException e) {
+        } catch (NonMonotonousSequenceException e) {
             // Expected
         }
         try {
-            MathUtils.checkOrder(new double[] {-15, -5.5, -1, -2, 2}, 1, false);
+            MathUtils.checkOrder(new double[] {-15, -5.5, -1, -2, 2},
+                                 MathUtils.Order.Direction.INCREASING, false);
             fail("an exception should have been thrown");
-        } catch (IllegalArgumentException e) {
+        } catch (NonMonotonousSequenceException e) {
             // Expected
         }
         try {
-            MathUtils.checkOrder(new double[] {3, 3, -5.5, -11, -27.5}, -1, true);
+            MathUtils.checkOrder(new double[] {3, 3, -5.5, -11, -27.5},
+                                 MathUtils.Order.Direction.DECREASING, true);
             fail("an exception should have been thrown");
-        } catch (IllegalArgumentException e) {
+        } catch (NonMonotonousSequenceException e) {
             // Expected
         }
         try {
-            MathUtils.checkOrder(new double[] {3, -1, 0, -5.5, -11, -27.5}, -1, false);
+            MathUtils.checkOrder(new double[] {3, -1, 0, -5.5, -11, -27.5},
+                                 MathUtils.Order.Direction.DECREASING, false);
             fail("an exception should have been thrown");
-        } catch (IllegalArgumentException e) {
+        } catch (NonMonotonousSequenceException e) {
             // Expected
         }
     }



Mime
View raw message