Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 81491 invoked from network); 6 Aug 2010 13:30:36 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 6 Aug 2010 13:30:36 -0000 Received: (qmail 51960 invoked by uid 500); 6 Aug 2010 13:30:36 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 51574 invoked by uid 500); 6 Aug 2010 13:30:32 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 51441 invoked by uid 99); 6 Aug 2010 13:30:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Aug 2010 13:30:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Aug 2010 13:30:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0AC2923889ED; Fri, 6 Aug 2010 13:29:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r982950 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/integration/ main/java/org/apache/commons/math/analysis/solvers/ main/java/org/apache/commons/math/complex/ main/java/org/apache/commons/math/exception/... Date: Fri, 06 Aug 2010 13:29:02 -0000 To: commits@commons.apache.org From: erans@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100806132903.0AC2923889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: erans Date: Fri Aug 6 13:29:01 2010 New Revision: 982950 URL: http://svn.apache.org/viewvc?rev=982950&view=rev Log: MATH-401 Created "NullArgumentException" (subclass of "MathIllegalArgumentException"). Changed all occurrences of "createIllegalArgumentException" (in "MathRuntime") to throw the new exception whenever a "null" is not allowed. Added a few checks for null in "BigFraction.java". Simplified "LocalizedFormats" enum. Changed "ZeroNotAllowedException" to "ZeroException". Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java - copied, changed from r982914, commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java Removed: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/site/xdoc/userguide/overview.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java Fri Aug 6 13:29:01 2010 @@ -20,6 +20,7 @@ import org.apache.commons.math.Convergin import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Provide a default implementation for several generic functions. @@ -67,7 +68,7 @@ public abstract class UnivariateRealInte throws IllegalArgumentException { super(defaultMaximalIterationCount, 1.0e-15); if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } this.f = f; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java Fri Aug 6 13:29:01 2010 @@ -22,6 +22,7 @@ import org.apache.commons.math.FunctionE import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Provide a default implementation for several functions useful to generic @@ -74,7 +75,7 @@ public abstract class UnivariateRealSolv final double defaultAbsoluteAccuracy) { super(defaultMaximalIterationCount, defaultAbsoluteAccuracy); if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } this.f = f; this.defaultFunctionValueAccuracy = 1.0e-15; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java Fri Aug 6 13:29:01 2010 @@ -21,6 +21,7 @@ import org.apache.commons.math.Convergen import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Utility routines for {@link UnivariateRealSolver} objects. @@ -170,7 +171,7 @@ public class UnivariateRealSolverUtils { FunctionEvaluationException { if (function == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } if (maximumIterations <= 0) { throw MathRuntimeException.createIllegalArgumentException( @@ -225,7 +226,7 @@ public class UnivariateRealSolverUtils { */ private static void setup(UnivariateRealFunction f) { if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java Fri Aug 6 13:29:01 2010 @@ -26,6 +26,7 @@ import java.util.Locale; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.util.CompositeFormat; +import org.apache.commons.math.exception.NullArgumentException; /** * Formats a Complex number in cartesian format "Re(c) + Im(c)i". 'i' can @@ -358,13 +359,11 @@ public class ComplexFormat extends Compo /** * Modify the imaginaryFormat. * @param imaginaryFormat The new imaginaryFormat value. - * @throws IllegalArgumentException if imaginaryFormat is - * null. + * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}. */ public void setImaginaryFormat(NumberFormat imaginaryFormat) { if (imaginaryFormat == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_IMAGINARY_FORMAT); + throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT); } this.imaginaryFormat = imaginaryFormat; } @@ -372,13 +371,11 @@ public class ComplexFormat extends Compo /** * Modify the realFormat. * @param realFormat The new realFormat value. - * @throws IllegalArgumentException if realFormat is - * null. + * @throws NullArgumentException if {@code realFormat} is {@code null}. */ public void setRealFormat(NumberFormat realFormat) { if (realFormat == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_REAL_FORMAT); + throw new NullArgumentException(LocalizedFormats.REAL_FORMAT); } this.realFormat = realFormat; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java Fri Aug 6 13:29:01 2010 @@ -145,11 +145,10 @@ public enum LocalizedFormats implements NEGATIVE_COMPLEX_MODULE("negative complex module {0}"), NEGATIVE_ELEMENT_AT_2D_INDEX("element ({0}, {1}) is negative: {2}"), NEGATIVE_ELEMENT_AT_INDEX("element {0} is negative: {1}"), - NEGATIVE_LENGTH("length cannot be negative ({0})"), NEGATIVE_NUMBER_OF_SUCCESSES("number of successes must be non-negative ({0})"), NEGATIVE_NUMBER_OF_TRIALS("number of trials must be non-negative ({0})"), NEGATIVE_ROBUSTNESS_ITERATIONS("the number of robustness iterations must be non-negative, but got {0}"), - NEGATIVE_START_POSITION("start position cannot be negative ({0})"), + START_POSITION("start position ({0})"), /* keep */ NON_CONVERGENT_CONTINUED_FRACTION("Continued fraction convergents failed to converge for value {0}"), NON_POSITIVE_MICROSPHERE_ELEMENTS("number of microsphere elements must be positive, but got {0}"), NON_POSITIVE_POLYNOMIAL_DEGREE("polynomial degree must be positive: degree={0}"), @@ -211,18 +210,19 @@ public enum LocalizedFormats implements NO_OPTIMUM_COMPUTED_YET("no optimum computed yet"), NO_RESULT_AVAILABLE("no result available"), NO_SUCH_MATRIX_ENTRY("no entry at indices ({0}, {1}) in a {2}x{3} matrix"), - NULL_COVARIANCE_MATRIX("covariance matrix is null"), - NULL_DENOMINATOR("denominator is null"), - NULL_DENOMINATOR_FORMAT("denominator format can not be null"), - NULL_FRACTION("null fraction"), - NULL_FUNCTION("function is null"), - NULL_IMAGINARY_FORMAT("null imaginary format"), - NULL_INPUT_ARRAY("input array is null"), - NULL_NUMERATOR("numerator is null"), - NULL_NUMERATOR_FORMAT("numerator format can not be null"), - NULL_OBJECT_TRANSFORMATION("Conversion Exception in Transformation, Object is null"), - NULL_REAL_FORMAT("null real format"), - NULL_WHOLE_FORMAT("whole format can not be null"), + NULL_NOT_ALLOWED("null is not allowed"), /* keep */ + COVARIANCE_MATRIX("covariance matrix"), /* keep */ + DENOMINATOR("denominator"), /* keep */ + DENOMINATOR_FORMAT("denominator format"), /* keep */ + FRACTION("fraction"), /* keep */ + FUNCTION("function"), /* keep */ + IMAGINARY_FORMAT("imaginary format"), /* keep */ + INPUT_ARRAY("input array"), /* keep */ + NUMERATOR("numerator"), /* keep */ + NUMERATOR_FORMAT("numerator format"), /* keep */ + OBJECT_TRANSFORMATION("conversion exception in transformation"), /* keep */ + REAL_FORMAT("real format"), /* keep */ + WHOLE_FORMAT("whole format"), /* keep */ NUMBER_TOO_LARGE("{0} is larger than the maximum ({1})"), /* keep */ NUMBER_TOO_SMALL("{0} is smaller than the minimum ({1})"), /* keep */ NUMBER_TOO_LARGE_BOUND_EXCLUDED("{0} is larger than, or equal to, the maximum ({1})"), /* keep */ Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java?rev=982950&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java Fri Aug 6 13:29:01 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; + +/** + * All conditions checks that fail due to a {@code null} argument must throw + * this exception. + * This class is meant to signal a precondition violation ("null is an illegal + * argument") and so does not extend the standard {@code NullPointerException}. + * Proagation of {@code NullPointerException} from within Commons-Math is + * construed to be a bug. + * + * @since 2.2 + * @version $Revision$ $Date$ + */ +public class NullArgumentException extends MathIllegalArgumentException { + /** Serializable version Id. */ + private static final long serialVersionUID = -6024911025449780478L; + + /** + * Default constructor. + */ + public NullArgumentException() { + super(LocalizedFormats.NULL_NOT_ALLOWED); + } + /** + * @param specific Message pattern providing the specific context of + * the error. + */ + public NullArgumentException(Localizable specific) { + super(specific, LocalizedFormats.NULL_NOT_ALLOWED); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java (from r982914, commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java) URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java&r1=982914&r2=982950&rev=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java Fri Aug 6 13:29:01 2010 @@ -23,7 +23,7 @@ package org.apache.commons.math.exceptio * @since 2.2 * @version $Revision$ $Date$ */ -public class ZeroNotAllowedException extends MathIllegalNumberException { +public class ZeroException extends MathIllegalNumberException { /** Serializable version identifier */ private static final long serialVersionUID = -1960874856936000015L; @@ -31,7 +31,7 @@ public class ZeroNotAllowedException ext /** * Construct the exception. */ - public ZeroNotAllowedException() { + public ZeroException() { this(null); } @@ -40,8 +40,7 @@ public class ZeroNotAllowedException ext * * @param specific Specific contexte pattern . */ - public ZeroNotAllowedException(Localizable specific) { + public ZeroException(Localizable specific) { super(specific, LocalizedFormats.ZERO_NOT_ALLOWED, 0); } - } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java Fri Aug 6 13:29:01 2010 @@ -23,7 +23,7 @@ import java.text.NumberFormat; import java.text.ParsePosition; import java.util.Locale; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.LocalizedFormats; /** @@ -114,13 +114,11 @@ public abstract class AbstractFormat ext /** * Modify the denominator format. * @param format the new denominator format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setDenominatorFormat(final NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_DENOMINATOR_FORMAT); + throw new NullArgumentException(LocalizedFormats.DENOMINATOR_FORMAT); } this.denominatorFormat = format; } @@ -128,13 +126,11 @@ public abstract class AbstractFormat ext /** * Modify the numerator format. * @param format the new numerator format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setNumeratorFormat(final NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_NUMERATOR_FORMAT); + throw new NullArgumentException(LocalizedFormats.NUMERATOR_FORMAT); } this.numeratorFormat = format; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java Fri Aug 6 13:29:01 2010 @@ -23,6 +23,7 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -104,19 +105,20 @@ public class BigFraction } /** - *

* Create a {@link BigFraction} given the numerator and denominator as - * BigInteger. The {@link BigFraction} is reduced to lowest terms. - *

+ * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * - * @param num - * the numerator, must not be null. - * @param den - * the denominator, must not be null. - * @throws ArithmeticException - * if the denominator is zero. + * @param num the numerator, must not be {@code null}. + * @param den the denominator, must not be {@code null}.. + * @throws ArithmeticException if the denominator is zero. */ public BigFraction(BigInteger num, BigInteger den) { + if (num == null) { + throw new NullArgumentException(LocalizedFormats.NUMERATOR); + } + if (den == null) { + throw new NullArgumentException(LocalizedFormats.DENOMINATOR); + } if (BigInteger.ZERO.equals(den)) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } @@ -498,10 +500,12 @@ public class BigFraction * @param fraction * the {@link BigFraction} to add, must not be null. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the {@link BigFraction} is null. + * @throws NullArgumentException if the {@link BigFraction} is {@code null}. */ public BigFraction add(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (ZERO.equals(fraction)) { return this; } @@ -601,8 +605,7 @@ public class BigFraction * the BigInteger to divide by, must not be * null. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the BigInteger is null. + * @throws NullArgumentException if the {@code BigInteger} is {@code null}. * @throws ArithmeticException * if the fraction to divide by is zero. */ @@ -651,15 +654,15 @@ public class BigFraction * reduced form. *

* - * @param fraction - * the fraction to divide by, must not be null. + * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the fraction is null. - * @throws ArithmeticException - * if the fraction to divide by is zero. + * @throws NullArgumentException if the {@code fraction} is {@code null}. + * @throws ArithmeticException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (BigInteger.ZERO.equals(fraction.numerator)) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } @@ -838,13 +841,14 @@ public class BigFraction * BigInteger, returning the result in reduced form. *

* - * @param bg - * the BigInteger to multiply by. - * @return a BigFraction instance with the resulting values. - * @throws NullPointerException - * if the bg is null. + * @param bg the {@code BigInteger} to multiply by. + * @return a {@code BigFraction} instance with the resulting values. + * @throws NullArgumentException if {@code bg} is {@code null}. */ public BigFraction multiply(final BigInteger bg) { + if (bg == null) { + throw new NullArgumentException(); + } return new BigFraction(bg.multiply(numerator), denominator); } @@ -882,13 +886,14 @@ public class BigFraction * reduced form. *

* - * @param fraction - * the fraction to multiply by, must not be null. + * @param fraction Fraction to multiply by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the fraction is null. + * @throws NullArgumentException if {@code fraction} is {@code null}. */ public BigFraction multiply(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (numerator.equals(BigInteger.ZERO) || fraction.numerator.equals(BigInteger.ZERO)) { return ZERO; @@ -1023,14 +1028,14 @@ public class BigFraction * returning the result in reduced form. *

* - * @param bg - * the {@link BigInteger} to subtract, must'nt be - * null. - * @return a BigFraction instance with the resulting values. - * @throws NullPointerException - * if the {@link BigInteger} is null. + * @param bg the {@link BigInteger} to subtract, cannot be {@code null}. + * @return a {@code BigFraction} instance with the resulting values. + * @throws NullArgumentException if the {@link BigInteger} is {@code null}. */ public BigFraction subtract(final BigInteger bg) { + if (bg == null) { + throw new NullArgumentException(); + } return new BigFraction(numerator.subtract(denominator.multiply(bg)), denominator); } @@ -1069,14 +1074,14 @@ public class BigFraction * returning the result in reduced form. *

* - * @param fraction - * the {@link BigFraction} to subtract, must not be - * null. + * @param fraction {@link BigFraction} to subtract, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values - * @throws NullPointerException - * if the fraction is null. + * @throws NullArgumentException if the {@code fraction} is {@code null}. */ public BigFraction subtract(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (ZERO.equals(fraction)) { return this; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java Fri Aug 6 13:29:01 2010 @@ -22,6 +22,7 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -473,7 +474,7 @@ public class Fraction */ private Fraction addSub(Fraction fraction, boolean isAdd) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); + throw new NullArgumentException(LocalizedFormats.FRACTION); } // zero is identity for addition. if (numerator == 0) { @@ -530,7 +531,7 @@ public class Fraction */ public Fraction multiply(Fraction fraction) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); + throw new NullArgumentException(LocalizedFormats.FRACTION); } if (numerator == 0 || fraction.numerator == 0) { return ZERO; @@ -565,7 +566,7 @@ public class Fraction */ public Fraction divide(Fraction fraction) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); + throw new NullArgumentException(LocalizedFormats.FRACTION); } if (fraction.numerator == 0) { throw MathRuntimeException.createArithmeticException( Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java Fri Aug 6 13:29:01 2010 @@ -21,8 +21,8 @@ import java.text.FieldPosition; import java.text.NumberFormat; import java.text.ParsePosition; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Formats a BigFraction number in proper format. The number format for each of @@ -228,15 +228,12 @@ public class ProperBigFractionFormat ext /** * Modify the whole format. * @param format The new whole format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setWholeFormat(final NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_WHOLE_FORMAT); + throw new NullArgumentException(LocalizedFormats.WHOLE_FORMAT); } this.wholeFormat = format; } - } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java Fri Aug 6 13:29:01 2010 @@ -20,8 +20,8 @@ import java.text.FieldPosition; import java.text.NumberFormat; import java.text.ParsePosition; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -221,13 +221,11 @@ public class ProperFractionFormat extend /** * Modify the whole format. * @param format The new whole format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setWholeFormat(NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_WHOLE_FORMAT); + throw new NullArgumentException(LocalizedFormats.WHOLE_FORMAT); } this.wholeFormat = format; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java Fri Aug 6 13:29:01 2010 @@ -24,7 +24,8 @@ import org.apache.commons.math.MathRunti import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.LocalizedFormats; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; /** * The derivative of {@link GaussianFunction}. Specifically: @@ -65,7 +66,7 @@ public class GaussianDerivativeFunction */ public GaussianDerivativeFunction(double b, double c, double d) { if (d == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.b = b; this.c = c; @@ -83,13 +84,13 @@ public class GaussianDerivativeFunction */ public GaussianDerivativeFunction(double[] parameters) { if (parameters == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (parameters.length != 3) { throw new DimensionMismatchException(3, parameters.length); } if (parameters[2] == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.b = parameters[0]; this.c = parameters[1]; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java Fri Aug 6 13:29:01 2010 @@ -18,8 +18,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.optimization. - DifferentiableMultivariateVectorialOptimizer; +import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.fitting.CurveFitter; import org.apache.commons.math.optimization.fitting.WeightedObservedPoint; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java Fri Aug 6 13:29:01 2010 @@ -25,7 +25,8 @@ import org.apache.commons.math.analysis. import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.LocalizedFormats; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; /** * A Gaussian function. Specifically: @@ -77,7 +78,7 @@ public class GaussianFunction implements */ public GaussianFunction(double a, double b, double c, double d) { if (d == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.a = a; this.b = b; @@ -97,13 +98,13 @@ public class GaussianFunction implements */ public GaussianFunction(double[] parameters) { if (parameters == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (parameters.length != 4) { throw new DimensionMismatchException(4, parameters.length); } if (parameters[3] == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.a = parameters[0]; this.b = parameters[1]; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java Fri Aug 6 13:29:01 2010 @@ -20,14 +20,14 @@ package org.apache.commons.math.optimiza import java.util.Arrays; import java.util.Comparator; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.OutOfRangeException; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; /** - * Guesses the parameters (a, b, c, and d) + * Guesses the parameters ({@code a}, {@code b}, {@code c}, and {@code d}) * of a {@link ParametricGaussianFunction} based on the specified observed * points. * @@ -49,7 +49,7 @@ public class GaussianParametersGuesser { */ public GaussianParametersGuesser(WeightedObservedPoint[] observations) { if (observations == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (observations.length < 3) { throw new NumberIsTooSmallException(observations.length, 3, true); @@ -154,7 +154,7 @@ public class GaussianParametersGuesser { private double interpolateXAtY(WeightedObservedPoint[] points, int startIdx, int idxStep, double y) throws OutOfRangeException { if (idxStep == 0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } WeightedObservedPoint[] twoPoints = getInterpolationPointsForY(points, startIdx, idxStep, y); WeightedObservedPoint pointA = twoPoints[0]; @@ -190,7 +190,7 @@ public class GaussianParametersGuesser { int startIdx, int idxStep, double y) throws OutOfRangeException { if (idxStep == 0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } for (int i = startIdx; (idxStep < 0) ? (i + idxStep >= 0) : (i + idxStep < points.length); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java Fri Aug 6 13:29:01 2010 @@ -20,10 +20,10 @@ package org.apache.commons.math.optimiza import java.io.Serializable; import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.LocalizedFormats; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.optimization.fitting.ParametricRealFunction; /** @@ -153,13 +153,13 @@ public class ParametricGaussianFunction */ private void validateParameters(double[] parameters) throws FunctionEvaluationException { if (parameters == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (parameters.length != 4) { throw new DimensionMismatchException(4, parameters.length); } if (parameters[3] == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java Fri Aug 6 13:29:01 2010 @@ -21,6 +21,8 @@ import org.apache.commons.math.MathRunti import org.apache.commons.math.distribution.TDistribution; import org.apache.commons.math.distribution.TDistributionImpl; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.BlockRealMatrix; import org.apache.commons.math.stat.regression.SimpleRegression; @@ -92,7 +94,7 @@ public class PearsonsCorrelation { public PearsonsCorrelation(Covariance covariance) { RealMatrix covarianceMatrix = covariance.getCovarianceMatrix(); if (covarianceMatrix == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_COVARIANCE_MATRIX); + throw new NullArgumentException(LocalizedFormats.COVARIANCE_MATRIX); } nObs = covariance.getN(); correlationMatrix = covarianceToCorrelation(covarianceMatrix); @@ -225,8 +227,7 @@ public class PearsonsCorrelation { public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException { SimpleRegression regression = new SimpleRegression(); if (xArray.length != yArray.length) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, xArray.length, yArray.length); + throw new DimensionMismatchException(xArray.length, yArray.length); } else if (xArray.length < 2) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java Fri Aug 6 13:29:01 2010 @@ -16,8 +16,8 @@ */ package org.apache.commons.math.stat.descriptive; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -56,7 +56,7 @@ public abstract class AbstractStorelessU @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); } @@ -124,7 +124,7 @@ public abstract class AbstractStorelessU */ public void incrementAll(double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } incrementAll(values, 0, values.length); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java Fri Aug 6 13:29:01 2010 @@ -18,6 +18,9 @@ package org.apache.commons.math.stat.des import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.NotPositiveException; +import org.apache.commons.math.exception.DimensionMismatchException; /** * Abstract base class for all implementations of the @@ -78,17 +81,15 @@ public abstract class AbstractUnivariate final int length) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (begin < 0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NEGATIVE_START_POSITION, begin); + throw new NotPositiveException(LocalizedFormats.START_POSITION, begin); } if (length < 0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NEGATIVE_LENGTH, length); + throw new NotPositiveException(LocalizedFormats.LENGTH, length); } if (begin + length > values.length) { @@ -140,12 +141,11 @@ public abstract class AbstractUnivariate final int length) { if (weights == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } - if (weights.length != values.length) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, weights.length, values.length); + if (weights.length != values.length) { + throw new DimensionMismatchException(weights.length, values.length); } boolean containsPositiveWeight = false; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java Fri Aug 6 13:29:01 2010 @@ -18,7 +18,7 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic; @@ -176,7 +176,7 @@ public class SemiVariance extends Abstra @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java Fri Aug 6 13:29:01 2010 @@ -18,7 +18,7 @@ package org.apache.commons.math.stat.des import java.io.Serializable; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.stat.descriptive.WeightedEvaluation; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; @@ -214,7 +214,7 @@ public class Variance extends AbstractSt @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); } @@ -589,7 +589,6 @@ public class Variance extends AbstractSt return result; } - /** * Copies source to dest. *

Neither source nor dest can be null.

@@ -599,9 +598,12 @@ public class Variance extends AbstractSt * @throws NullPointerException if either source or dest is null */ public static void copy(Variance source, Variance dest) { + if (source == null || + dest == null) { + throw new NullArgumentException(); + } dest.moment = source.moment.copy(); dest.isBiasCorrected = source.isBiasCorrected; dest.incMoment = source.incMoment; } - } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java Fri Aug 6 13:29:01 2010 @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * A Default NumberTransformer for java.lang.Numbers and Numeric Strings. This @@ -38,14 +39,13 @@ public class DefaultTransformer implemen /** * @param o the object that gets transformed. * @return a double primitive representation of the Object o. - * @throws org.apache.commons.math.MathException If it cannot successfully - * be transformed or is null. + * @throws MathException if it cannot successfully be transformed. + * @throws NullArgumentException if is {@code null}. * @see */ - public double transform(Object o) throws MathException{ - + public double transform(Object o) throws MathException { if (o == null) { - throw new MathException(LocalizedFormats.NULL_OBJECT_TRANSFORMATION); + throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION); } if (o instanceof Number) { 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=982950&r1=982949&r2=982950&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 Aug 6 13:29:01 2010 @@ -117,11 +117,10 @@ NEGATIVE_BRIGHTNESS_EXPONENT = l''exposa NEGATIVE_COMPLEX_MODULE = module n\u00e9gatif ({0}) pour un nombre complexe NEGATIVE_ELEMENT_AT_2D_INDEX = l''\u00e9l\u00e9ment ({0}, {1}) est n\u00e9gatif : {2} NEGATIVE_ELEMENT_AT_INDEX = l''\u00e9l\u00e9ment {0} est n\u00e9gatif : {1} -NEGATIVE_LENGTH = la longueur ne peut pas \u00eatre n\u00e9gative NEGATIVE_NUMBER_OF_SUCCESSES = le nombre de succ\u00e8s ne doit pas \u00eatre n\u00e9gatif ({0}) NEGATIVE_NUMBER_OF_TRIALS = le nombre d''essais ne doit pas \u00eatre n\u00e9gatif ({0}) NEGATIVE_ROBUSTNESS_ITERATIONS = le nombre d''it\u00e9rations robuste ne peut \u00eatre n\u00e9gatif, alors qu''il est de {0} -NEGATIVE_START_POSITION = la position de d\u00e9part ne peut pas \u00eatre n\u00e9gative +START_POSITION = position de d\u00e9part NON_CONVERGENT_CONTINUED_FRACTION = \u00c9chec de convergence de fraction continue pour la valeur {0} NON_POSITIVE_MICROSPHERE_ELEMENTS = le nombre d''\u00e9l\u00e9ments de la microsph\u00e8re devrait \u00eatre positif, or n = {0} NON_POSITIVE_POLYNOMIAL_DEGREE = le polyn\u00f4me doit \u00eatre de degr\u00e9 positif : degr\u00e9 = {0} @@ -189,12 +188,12 @@ DENOMINATOR = d\u00e9nominateur DENOMINATOR_FORMAT = format du d\u00e9nominateur FRACTION = fraction FUNCTION = fonction -IMAGINARY_FORMAT = format imaginaire +IMAGINARY_FORMAT = format de la partie imaginaire INPUT_ARRAY = tableau d''entr\u00e9e NUMERATOR = num\u00e9rateur NUMERATOR_FORMAT = format du num\u00e9rateur OBJECT_TRANSFORMATION = exception de conversion dans une transformation -REAL_FORMAT = format r\u00e9el +REAL_FORMAT = format de la partie r\u00e9elle WHOLE_FORMAT = format complet NUMBER_TOO_LARGE = {0} est plus grand que le maximum ({1}) NUMBER_TOO_SMALL = {0} est plus petit que le minimum ({1}) Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Aug 6 13:29:01 2010 @@ -96,6 +96,8 @@ The type attribute can be add,u Created package "exception" to contain the new exceptions hierarchy. Created package "exception.util": utilities for the exception classes (e.g. managing the localization of error messages). + Default policy for dealing with invalid null references: raise a + "NullArgumentException" (subclass of "IllegalArgumentException"). Implementation of linear interpolation. Modified: commons/proper/math/trunk/src/site/xdoc/userguide/overview.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/userguide/overview.xml?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/userguide/overview.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/userguide/overview.xml Fri Aug 6 13:29:01 2010 @@ -93,7 +93,7 @@ -

+

You should always read the javadoc class and method comments carefully when using Commons Math components in your programs. The javadoc provides references to the algorithms that are used, usage notes about limitations, performance, etc. as well as interface contracts. @@ -101,16 +101,27 @@ for the method to return valid results), special values returned (e.g. Double.NaN) or exceptions that may be thrown if the preconditions are not met, and definitions for returned values/objects or state changes.

-

- When the actual parameters provided to a method or the internal state of an object - make a computation meaningless, an IllegalArgumentException or IllegalStateException may - be thrown. Exact conditions under which runtime exceptions (and any other exceptions) are - thrown are specified in the javadoc method comments. In some cases, to be consistent with - the IEEE 754 standard for floating point - arithmetic and with java.lang.Math, Commons Math methods return Double.NaN values. - Conditions under which Double.NaN or other special values are returned are fully specified - in the javadoc method comments. -

+

+ When the actual parameters provided to a method or the internal state of an object + make a computation meaningless, an IllegalArgumentException or IllegalStateException may + be thrown. Exact conditions under which runtime exceptions (and any other exceptions) are + thrown are specified in the javadoc method comments. In some cases, to be consistent with + the IEEE 754 standard for floating point + arithmetic and with java.lang.Math, Commons Math methods return Double.NaN values. + Conditions under which Double.NaN or other special values are returned are fully specified + in the javadoc method comments. +

+

+ As of version 2.2, the policy for dealing with null references is as + follows: When an argument is unexpectedly null, a + + NullArgumentException is raised for signalling the + illegal argument. Note that this class does not inherit from the + standard NullPointerException but is a subclass of + IllegalArgumentException. + No NullPointerException should be propagated from within + Commons-Math. +

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java Fri Aug 6 13:29:01 2010 @@ -21,6 +21,7 @@ import java.math.BigInteger; import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; import junit.framework.TestCase; @@ -64,12 +65,12 @@ public class BigFractionTest extends Tes assertFraction(1055531162664967l, 70368744177664l, new BigFraction(15.0000000000001)); try { new BigFraction(null, BigInteger.ONE); - } catch (NullPointerException npe) { + } catch (NullArgumentException npe) { // expected } try { new BigFraction(BigInteger.ONE, null); - } catch (NullPointerException npe) { + } catch (NullArgumentException npe) { // expected } try { @@ -326,8 +327,8 @@ public class BigFractionTest extends Tes try { f.add((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } // if this fraction is added naively, it will overflow. @@ -414,8 +415,8 @@ public class BigFractionTest extends Tes try { f.divide((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } f1 = new BigFraction(Integer.MIN_VALUE, Integer.MAX_VALUE); @@ -460,8 +461,8 @@ public class BigFractionTest extends Tes try { f.multiply((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } } @@ -478,8 +479,8 @@ public class BigFractionTest extends Tes BigFraction f = new BigFraction(1, 1); try { f.subtract((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } // if this fraction is subtracted naively, it will overflow. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java Fri Aug 6 13:29:01 2010 @@ -18,7 +18,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.fitting.CurveFitter; import org.apache.commons.math.optimization.general. @@ -133,7 +133,7 @@ public class ParametricGaussianFunctionT * * @throws FunctionEvaluationException in the event of a test case error */ - @Test(expected=ZeroNotAllowedException.class) + @Test(expected=ZeroException.class) public void testValue03() throws FunctionEvaluationException { ParametricGaussianFunction f = new ParametricGaussianFunction(); f.value(0.0, new double[] {0.0, 1.0, 1.0, 0.0}); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java?rev=982950&r1=982949&r2=982950&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java Fri Aug 6 13:29:01 2010 @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.commons.math.MathException; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; /** * @version $Revision$ $Date$ @@ -41,12 +42,12 @@ public class DefaultTransformerTest exte /** * */ - public void testTransformNull(){ + public void testTransformNull() throws Exception { DefaultTransformer t = new DefaultTransformer(); try { t.transform(null); - fail("Expection MathException"); - } catch (MathException e) { + fail("Expecting NullArgumentException"); + } catch (NullArgumentException e) { // expected } }