commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r957930 - in /commons/proper/math/trunk/src/main: java/org/apache/commons/math/exception/ java/org/apache/commons/math/util/ resources/META-INF/localization/
Date Fri, 25 Jun 2010 13:00:42 GMT
Author: erans
Date: Fri Jun 25 13:00:41 2010
New Revision: 957930

URL: http://svn.apache.org/viewvc?rev=957930&view=rev
Log:
MATH-361

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
  (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
  (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotStrictlyPositiveException.java
  (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java
    commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java?rev=957930&r1=957929&r2=957930&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
Fri Jun 25 13:00:41 2010
@@ -24,37 +24,26 @@ import org.apache.commons.math.util.Loca
  * @since 2.2
  * @version $Revision$ $Date$
  */
-public class DimensionMismatchException extends MathIllegalArgumentException {
-    /** First dimension. */
-    private final int dimension1;
-
-    /** Second dimension. */
-    private final int dimension2;
+public class DimensionMismatchException extends MathIllegalNumberException {
+    /** Correct dimension. */
+    private final int dimension;
 
     /**
      * Construct an exception from the mismatched dimensions.
      *
-     * @param dimension1 First dimension.
-     * @param dimension2 Second dimension.
+     * @param wrong Wrong dimension.
+     * @param expected Expected dimension.
      */
-    public DimensionMismatchException(int dimension1,
-                                      int dimension2) {
-        super(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, dimension1, dimension2);
-
-        this.dimension1 = dimension1;
-        this.dimension2 = dimension2;
+    public DimensionMismatchException(int wrong,
+                                      int expected) {
+        super(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, wrong, expected);
+        dimension = expected;
     }
 
     /**
-     * @return the first dimension.
-     */
-    public int getDimension1() {
-        return dimension1;
-    }
-    /**
-     * @return the second dimension.
+     * @return the expected dimension.
      */
-    public int getDimension2() {
-        return dimension2;
+    public int getDimension() {
+        return dimension;
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=957930&r1=957929&r2=957930&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
Fri Jun 25 13:00:41 2010
@@ -17,14 +17,16 @@
 package org.apache.commons.math.exception;
 
 import java.util.Locale;
+import java.util.List;
+import java.util.ArrayList;
 import org.apache.commons.math.util.Localizable;
 
 /**
  * Base class for all preconditions violation exceptions.
- * This class is not intended to be instantiated directly in most case: it
- * should serve as a base class to create all the exceptions that share the
- * semantics of the standard {@link IllegalArgumentException}, but must also
- * provide a localized message.
+ * This class is not intended to be instantiated directly: it should serve
+ * as a base class to create all the exceptions that share the semantics of
+ * the standard {@link IllegalArgumentException}, but must also provide a
+ * localized message.
  *
  * @since 2.2
  * @version $Revision$ $Date$
@@ -41,12 +43,12 @@ public class MathIllegalArgumentExceptio
     
     /**
      * @param pattern Message pattern.
-     * @param arguments Arguments.
+     * @param args Arguments.
      */
     protected MathIllegalArgumentException(Localizable pattern,
-                                           Object ... arguments) {
+                                           Object ... args) {
         this.pattern = pattern;
-        this.arguments = arguments.clone();
+        arguments = flatten(args).toArray();
     }
 
     /** {@inheritDoc} */
@@ -60,4 +62,23 @@ public class MathIllegalArgumentExceptio
     public String getLocalizedMessage() {
         return MessageFactory.buildMessage(Locale.getDefault(), pattern, arguments);
     }
+
+    /**
+     * Transform a multidimensional array into a one-dimensional list.
+     *
+     * @param array Array (possibly multidimensional).
+     * @return a list of all the {@code Object} instances contained in
+     * {@code array}.
+     */
+    private List<Object> flatten(Object[] array) {
+        final List<Object> list = new ArrayList<Object>();
+        for (Object o : array) {
+            if (o instanceof Object[]) {
+                list.addAll(flatten((Object[]) o));
+            } else {
+                list.add(o);
+            }
+        }
+        return list;
+    }
 }

Added: 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=957930&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
(added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
Fri Jun 25 13:00:41 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.Localizable;
+
+/**
+ * Base class for exceptions raised by a wrong number.
+ * This class is not intended to be instantiated directly: it should serve
+ * as a base class to create all the exceptions that are raised because some
+ * precondition is violated by a number argument.
+ *
+ * @since 2.2
+ * @version $Revision$ $Date$
+ */
+public class MathIllegalNumberException extends MathIllegalArgumentException {
+    /** Requested. */
+    private final Number argument;
+
+    /**
+     * Construct an exception.
+     *
+     * @param Localizable pattern.
+     * @param arguments Arguments. The first element must be the requested
+     * value that raised the exception.
+     */
+    protected MathIllegalNumberException(Localizable pattern,
+                                         Number wrong,
+                                         Object ... arguments) {
+        super(pattern, wrong, arguments);
+        argument = wrong;
+    }
+
+    /**
+     * @return the requested value.
+     */
+    public Number getArgument() {
+        return argument;
+    }
+}

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

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java?rev=957930&r1=957929&r2=957930&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
Fri Jun 25 13:00:41 2010
@@ -44,6 +44,7 @@ public class MessageFactory {
     public static String buildMessage(Locale locale,
                                       Localizable pattern,
                                       Object ... arguments) {
-        return new MessageFormat(pattern.getLocalizedString(locale), locale).format(arguments);
+        final String locPattern = pattern.getLocalizedString(locale);
+        return (new MessageFormat(locPattern, locale)).format(arguments);
     }
 }

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java?rev=957930&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
(added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
Fri Jun 25 13:00:41 2010
@@ -0,0 +1,36 @@
+/*
+ * 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 argument is negative.
+ *
+ * @since 2.2
+ * @version $Revision$ $Date$
+ */
+public class NotPositiveException extends MathIllegalNumberException {
+    /**
+     * Construct the exception.
+     *
+     * @param value Argument.
+     */
+    public NotPositiveException(Number value) {
+        super(LocalizedFormats.NOT_POSITIVE, value);
+    }
+}

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

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotStrictlyPositiveException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotStrictlyPositiveException.java?rev=957930&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotStrictlyPositiveException.java
(added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotStrictlyPositiveException.java
Fri Jun 25 13:00:41 2010
@@ -0,0 +1,36 @@
+/*
+ * 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 argument is negative.
+ *
+ * @since 2.2
+ * @version $Revision$ $Date$
+ */
+public class NotStrictlyPositiveException extends MathIllegalNumberException {
+    /**
+     * Construct the exception.
+     *
+     * @param value Argument.
+     */
+    public NotStrictlyPositiveException(Number value) {
+        super(LocalizedFormats.NOT_STRICTLY_POSITIVE, value);
+    }
+}

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

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java?rev=957930&r1=957929&r2=957930&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
Fri Jun 25 13:00:41 2010
@@ -24,37 +24,26 @@ import org.apache.commons.math.util.Loca
  * @since 2.2
  * @version $Revision$ $Date$
  */
-public class OutOfRangeException extends MathIllegalArgumentException {
+public class OutOfRangeException extends MathIllegalNumberException {
     /** Lower bound. */
     private final Number lo;
     /** Higher bound. */
     private final Number hi;
-    /** Requested. */
-    private final Number requested;
 
     /**
      * Construct an exception from the mismatched dimensions.
      *
-     * @param requested Requested value.
+     * @param wrong Requested value.
      * @param lo Lower bound.
      * @param hi Higher bound.
      */
-    public OutOfRangeException(Number requested,
+    public OutOfRangeException(Number wrong,
                                Number lo,
                                Number hi) {
-        super(LocalizedFormats.OUT_OF_RANGE_SIMPLE, requested, lo, hi);
-
-        this.requested = requested;
+        super(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi);
         this.lo = lo;
         this.hi = hi;
     }
-
-    /**
-     * @return the requested value.
-     */
-    public Number getRequested() {
-        return requested;
-    }
     /**
      * @return the lower bound.
      */

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=957930&r1=957929&r2=957930&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
Fri Jun 25 13:00:41 2010
@@ -80,7 +80,7 @@ public enum LocalizedFormats implements 
     DIFFERENT_ROWS_LENGTHS("some rows have length {0} while others have length {1}"),
     DIGEST_NOT_INITIALIZED("digest not initialized"),
     DIMENSIONS_MISMATCH_2x2("dimensions mismatch: got {0}x{1} but expected {2}x{3}"),
-    DIMENSIONS_MISMATCH_SIMPLE("dimensions mismatch {0} != {1}"),
+    DIMENSIONS_MISMATCH_SIMPLE("dimensions mismatch {0} != {1}"), /* keep */
     DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN("Discrete cumulative probability function
returned NaN for argument {0}"),
     DISTRIBUTION_NOT_LOADED("distribution not loaded"),
     DUPLICATED_ABSCISSA("Abscissa {0} is duplicated at both indices {1} and {2}"),
@@ -164,6 +164,8 @@ public enum LocalizedFormats implements 
     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_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 */
     NOT_POSITIVE_ALPHA("alpha must be positive ({0})"),
     NOT_POSITIVE_BETA("beta must be positive ({0})"),
     NOT_POSITIVE_COLUMNDIMENSION("invalid column dimension: {0} (must be positive)"),
@@ -222,7 +224,7 @@ public enum LocalizedFormats implements 
     OUT_OF_BOUND_SIGNIFICANCE_LEVEL("out of bounds significance level {0}, must be between
{1} and {2}"),
     OUT_OF_ORDER_ABSCISSA_ARRAY("the abscissae array must be sorted in a strictly increasing
order, but the {0}-th element is {1} whereas {2}-th is {3}"),
     OUT_OF_RANGE_ROOT_OF_UNITY_INDEX("out of range root of unity index {0} (must be in [{1};{2}])"),
-    OUT_OF_RANGE_SIMPLE("{0} out of [{1}, {2}] range"),
+    OUT_OF_RANGE_SIMPLE("{0} out of [{1}, {2}] range"), /* keep */
     OVERFLOW_IN_FRACTION("overflow in fraction {0}/{1}, cannot negate"),
     PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD("cannot access {0} method in percentile
implementation {1}"),
     PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD("percentile implementation {0} does not
support {1}"),

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=957930&r1=957929&r2=957930&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
Fri Jun 25 13:00:41 2010
@@ -136,6 +136,8 @@ NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS
 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_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
 NOT_POSITIVE_ALPHA = alpha doit \u00eatre positif ({0})
 NOT_POSITIVE_BETA = beta doit \u00eatre positif ({0})
 NOT_POSITIVE_COLUMNDIMENSION = nombre de colonnes invalide : {0} (doit \u00eatre positif)



Mime
View raw message