You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2010/12/10 01:50:52 UTC
svn commit: r1044186 [1/4] - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/analysis/interpolation/
main/java/org/apache/commons/math/complex/
main/java/org/apache/commons/math/distribution/
main/java/org/apache/commons/math/excep...
Author: erans
Date: Fri Dec 10 00:50:50 2010
New Revision: 1044186
URL: http://svn.apache.org/viewvc?rev=1044186&view=rev
Log:
MATH-447
Made all new exception classes inherit from "MathRuntimeException".
Changed accordingly all tests that relied on catching the standard
Java exception (e.g. "MathIllegalArgumentEception" is not a subclass
of "IllegalArgumentEception" anymore).
Replaced occurrences of the old "MathRuntimeException" by the
appropriate exception from the "exception" package (MATH-459).
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/complex/ComplexFormat.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.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/MathIllegalStateException.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.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/linear/AbstractRealVector.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.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/rank/Percentile.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.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/test/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunctionTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatorTest.java
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/analysis/polynomials/PolynomialFunctionLagrangeFormTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonFormTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunctionTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ContinuousDistributionAbstractTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/IntegerDistributionAbstractTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskySolverTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/FieldMatrixImplTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUSolverTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/MatrixUtilsTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/QRSolverTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SingularValueSolverTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseFieldMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseFieldVectorTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/GaussianFitterTest.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/random/AbstractRandomGeneratorTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/MersenneTwisterTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/Well1024aTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/StatUtilsTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatisticTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SemiVarianceTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareTestTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TestUtilsTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.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=1044186&r1=1044185&r2=1044186&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 Fri Dec 10 00:50:50 2010
@@ -16,8 +16,8 @@
*/
package org.apache.commons.math.analysis.interpolation;
-import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.analysis.BivariateRealFunction;
+import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.util.MathUtils;
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=1044186&r1=1044185&r2=1044186&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 Fri Dec 10 00:50:50 2010
@@ -16,10 +16,10 @@
*/
package org.apache.commons.math.analysis.interpolation;
-import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
+import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.util.MathUtils;
@@ -37,7 +37,7 @@ public class BicubicSplineInterpolator
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 new NoDataException();
}
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=1044186&r1=1044185&r2=1044186&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 Dec 10 00:50:50 2010
@@ -24,9 +24,11 @@ import java.text.ParsePosition;
import java.util.Locale;
import org.apache.commons.math.MathRuntimeException;
-import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.CompositeFormat;
+import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.NoDataException;
/**
* Formats a Complex number in cartesian format "Re(c) + Im(c)i". 'i' can
@@ -169,7 +171,7 @@ public class ComplexFormat extends Compo
}
/**
- * Formats a object to produce a string. <code>obj</code> must be either a
+ * Formats a object to produce a string. {@code obj} must be either a
* {@link Complex} object or a {@link Number} object. Any other type of
* object will result in an {@link IllegalArgumentException} being thrown.
*
@@ -179,7 +181,7 @@ public class ComplexFormat extends Compo
* offsets of the alignment field
* @return the value passed in as toAppendTo.
* @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
- * @throws IllegalArgumentException is <code>obj</code> is not a valid type.
+ * @throws IllegalArgumentException is {@code obj} is not a valid type.
*/
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo,
@@ -193,9 +195,8 @@ public class ComplexFormat extends Compo
ret = format( new Complex(((Number)obj).doubleValue(), 0.0),
toAppendTo, pos);
} else {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_COMPLEX,
- obj.getClass().getName());
+ throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_COMPLEX,
+ obj.getClass().getName());
}
return ret;
@@ -345,13 +346,17 @@ public class ComplexFormat extends Compo
/**
* Modify the imaginaryCharacter.
* @param imaginaryCharacter The new imaginaryCharacter value.
- * @throws IllegalArgumentException if <code>imaginaryCharacter</code> is
- * <code>null</code> or an empty string.
+ * @throws NullArgumentException if {@code imaginaryCharacter} is
+ * {@code null}.
+ * @throws NoDataException if {@code imaginaryCharacter} is an
+ * empty string.
*/
public void setImaginaryCharacter(String imaginaryCharacter) {
- if (imaginaryCharacter == null || imaginaryCharacter.length() == 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.EMPTY_STRING_FOR_IMAGINARY_CHARACTER);
+ if (imaginaryCharacter == null) {
+ throw new NullArgumentException();
+ }
+ if (imaginaryCharacter.length() == 0) {
+ throw new NoDataException();
}
this.imaginaryCharacter = imaginaryCharacter;
}
@@ -379,5 +384,4 @@ public class ComplexFormat extends Compo
}
this.realFormat = realFormat;
}
-
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Fri Dec 10 00:50:50 2010
@@ -20,7 +20,6 @@ import java.io.Serializable;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.UnivariateRealFunction;
-import org.apache.commons.math.analysis.solvers.BrentSolver;
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java Fri Dec 10 00:50:50 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.distribu
import java.io.Serializable;
import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**
@@ -51,18 +51,17 @@ public abstract class AbstractDistributi
* @param x0 the (inclusive) lower bound
* @param x1 the (inclusive) upper bound
* @return the probability that a random variable with this distribution
- * will take a value between <code>x0</code> and <code>x1</code>,
+ * will take a value between {@code x0} and {@code x1},
* including the endpoints.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if <code>x0 > x1</code>
+ * @throws NumberIsTooLargeException if {@code x0 > x1}
*/
public double cumulativeProbability(double x0, double x1)
throws MathException {
if (x0 > x1) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
- x0, x1);
+ throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
+ x0, x1, true);
}
return cumulativeProbability(x1) - cumulativeProbability(x0);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java Fri Dec 10 00:50:50 2010
@@ -86,7 +86,7 @@ public abstract class AbstractIntegerDis
throws MathException {
if (x1 < x0) {
throw new NumberIsTooSmallException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
- x0, x1, true);
+ x1, x0, true);
}
if (FastMath.floor(x0) < x0) {
return cumulativeProbability(((int) FastMath.floor(x0)) + 1,
@@ -143,7 +143,7 @@ public abstract class AbstractIntegerDis
public double cumulativeProbability(int x0, int x1) throws MathException {
if (x1 < x0) {
throw new NumberIsTooSmallException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
- x0, x1, true);
+ x1, x0, true);
}
return cumulativeProbability(x1) - cumulativeProbability(x0 - 1);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java Fri Dec 10 00:50:50 2010
@@ -122,11 +122,10 @@ public class NormalDistributionImpl exte
*/
public double cumulativeProbability(double x) throws MathException {
final double dev = x - mean;
- if (FastMath.abs(dev) > 40 * standardDeviation) {
+ if (FastMath.abs(dev) > 40 * standardDeviation) {
return dev < 0 ? 0.0d : 1.0d;
}
- return 0.5 * (1.0 + Erf.erf((dev) /
- (standardDeviation * FastMath.sqrt(2.0))));
+ return 0.5 * (1 + Erf.erf(dev / (standardDeviation * FastMath.sqrt(2))));
}
/**
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java Fri Dec 10 00:50:50 2010
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
@@ -32,21 +28,11 @@ import org.apache.commons.math.exception
* @since 3.0
* @version $Revision$ $Date$
*/
-public class MathArithmeticException extends ArithmeticException {
-
+public class MathArithmeticException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param args Arguments.
*/
public MathArithmeticException(Object ... args) {
@@ -59,33 +45,6 @@ public class MathArithmeticException ext
*/
public MathArithmeticException(Localizable specific,
Object ... args) {
- this.specific = specific;
- arguments = ArgUtils.flatten(args);
- }
-
- /**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- *
- * @return the localized message.
- */
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale,
- specific,
- LocalizedFormats.UNSUPPORTED_OPERATION,
- arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
+ super(null, specific, LocalizedFormats.ARITHMETIC_EXCEPTION, args);
}
}
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=1044186&r1=1044185&r2=1044186&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 Dec 10 00:50:50 2010
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
/**
@@ -32,25 +28,11 @@ import org.apache.commons.math.exception
* @since 2.2
* @version $Revision$ $Date$
*/
-public class MathIllegalArgumentException extends IllegalArgumentException implements MathThrowable {
-
+public class MathIllegalArgumentException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Pattern used to build the message (general problem description).
- */
- private final Localizable general;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param specific Message pattern providing the specific context of
* the error.
* @param general Message pattern explaining the cause of the error.
@@ -59,9 +41,7 @@ public class MathIllegalArgumentExceptio
public MathIllegalArgumentException(Localizable specific,
Localizable general,
Object ... args) {
- this.specific = specific;
- this.general = general;
- arguments = ArgUtils.flatten(args);
+ super(null, specific, general, args);
}
/**
* @param general Message pattern explaining the cause of the error.
@@ -71,41 +51,4 @@ public class MathIllegalArgumentExceptio
Object ... args) {
this(null, general, args);
}
-
- /** {@inheritDoc} */
- public Localizable getSpecificPattern() {
- return specific;
- }
-
- /** {@inheritDoc} */
- public Localizable getGeneralPattern() {
- return general;
- }
-
- /** {@inheritDoc} */
- public Object[] getArguments() {
- return arguments.clone();
- }
-
- /**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- * @return the localized message.
- */
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale, specific, general, arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
- }
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java Fri Dec 10 00:50:50 2010
@@ -16,11 +16,8 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
+import org.apache.commons.math.exception.util.LocalizedFormats;
/**
* Base class for all exceptions that signal a mismatch between the
@@ -29,25 +26,11 @@ import org.apache.commons.math.exception
* @since 2.2
* @version $Revision$ $Date$
*/
-public class MathIllegalStateException extends IllegalStateException implements MathThrowable {
-
+public class MathIllegalStateException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Pattern used to build the message (general problem description).
- */
- private final Localizable general;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param specific Message pattern providing the specific context of
* the error.
* @param general Message pattern explaining the cause of the error.
@@ -56,55 +39,20 @@ public class MathIllegalStateException e
public MathIllegalStateException(Localizable specific,
Localizable general,
Object ... args) {
- this.specific = specific;
- this.general = general;
- arguments = ArgUtils.flatten(args);
+ super(null, specific, general, args);
}
/**
- * @param general Message pattern explaining the cause of the error.
+ * @param specific Message pattern explaining the cause of the error.
* @param args Arguments.
*/
- public MathIllegalStateException(Localizable general,
+ public MathIllegalStateException(Localizable specific,
Object ... args) {
- this(null, general, args);
- }
-
- /** {@inheritDoc} */
- public Localizable getSpecificPattern() {
- return specific;
- }
-
- /** {@inheritDoc} */
- public Localizable getGeneralPattern() {
- return general;
+ this(specific, LocalizedFormats.ILLEGAL_STATE, args);
}
-
- /** {@inheritDoc} */
- public Object[] getArguments() {
- return arguments.clone();
- }
-
/**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- *
- * @return the localized message.
+ * @param args Arguments.
*/
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale, specific, general, arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
+ public MathIllegalStateException(Object ... args) {
+ this(null, args);
}
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
- }
-
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java Fri Dec 10 00:50:50 2010
@@ -23,9 +23,10 @@ import org.apache.commons.math.exception
import org.apache.commons.math.exception.util.MessageFactory;
/**
- * This class is intended as a base class for exceptions that must wrap
- * low-level exceptions in order to propagate an exception that better
- * corresponds to the high-level action that triggered the problem.
+ * This class is primarily intended as a base class for exceptions
+ * that must wrap low-level exceptions in order to propagate an
+ * exception that better corresponds to the high-level action that
+ * triggered the problem.
*
* @since 3.0
* @version $Revision$ $Date$
@@ -48,7 +49,7 @@ public class MathRuntimeException extend
private final Object[] arguments;
/**
- * Builds an exception from two patterns (specific and general) and
+ * Build an exception from two patterns (specific and general) and
* an argument list.
*
* @param cause Cause of the error (may be null).
@@ -57,16 +58,25 @@ public class MathRuntimeException extend
* @param arguments Format arguments. They will be substituted in
* <em>both</em> the {@code general} and {@code specific} format specifiers.
*/
- protected MathRuntimeException(final Throwable cause,
- final Localizable specific,
- final Localizable general,
- final Object ... arguments) {
+ public MathRuntimeException(final Throwable cause,
+ final Localizable specific,
+ final Localizable general,
+ final Object ... arguments) {
super(cause);
this.specific = specific;
this.general = general;
this.arguments = ArgUtils.flatten(arguments);
}
+ /**
+ * Wrap an exception.
+ *
+ * @param cause Cause of the error (may be null).
+ */
+ public MathRuntimeException(final Throwable cause) {
+ this(cause, null, null);
+ }
+
/** {@inheritDoc} */
public Localizable getSpecificPattern() {
return specific;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java Fri Dec 10 00:50:50 2010
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
@@ -32,21 +28,11 @@ import org.apache.commons.math.exception
* @since 2.2
* @version $Revision$ $Date$
*/
-public class MathUnsupportedOperationException extends UnsupportedOperationException implements MathThrowable {
-
+public class MathUnsupportedOperationException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param args Arguments.
*/
public MathUnsupportedOperationException(Object ... args) {
@@ -59,48 +45,6 @@ public class MathUnsupportedOperationExc
*/
public MathUnsupportedOperationException(Localizable specific,
Object ... args) {
- this.specific = specific;
- arguments = ArgUtils.flatten(args);
- }
-
- /** {@inheritDoc} */
- public Localizable getSpecificPattern() {
- return specific;
- }
-
- /** {@inheritDoc} */
- public Localizable getGeneralPattern() {
- return LocalizedFormats.UNSUPPORTED_OPERATION;
- }
-
- /** {@inheritDoc} */
- public Object[] getArguments() {
- return arguments.clone();
- }
-
- /**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- *
- * @return the localized message.
- */
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale,
- specific,
- LocalizedFormats.UNSUPPORTED_OPERATION,
- arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
+ super(null, specific, LocalizedFormats.UNSUPPORTED_OPERATION, args);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Fri Dec 10 00:50:50 2010
@@ -304,6 +304,8 @@ public enum LocalizedFormats implements
UNPARSEABLE_REAL_VECTOR("unparseable real vector: \"{0}\""),
UNSUPPORTED_EXPANSION_MODE("unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})"),
UNSUPPORTED_OPERATION("unsupported operation"), /* keep */
+ ARITHMETIC_EXCEPTION("arithmetic exception"), /* keep */
+ ILLEGAL_STATE("illegal state"), /* keep */
USER_EXCEPTION("exception generated in user code"), /* keep */
URL_CONTAINS_NO_DATA("URL {0} contains no data"),
VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC("{0} values have been added before statistic is configured"),
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=1044186&r1=1044185&r2=1044186&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 Dec 10 00:50:50 2010
@@ -20,8 +20,8 @@ import java.io.Serializable;
import java.math.BigInteger;
import org.apache.commons.math.FieldElement;
-import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.MathArithmeticException;
import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.util.MathUtils;
import org.apache.commons.math.util.FastMath;
@@ -110,7 +110,7 @@ public class Fraction
* </p>
* @param value the double value to convert to a fraction.
* @param epsilon maximum error allowed. The resulting fraction is within
- * <code>epsilon</code> of <code>value</code>, in absolute terms.
+ * {@code epsilon} of {@code value}, in absolute terms.
* @param maxIterations maximum number of convergents
* @throws FractionConversionException if the continued fraction failed to
* converge.
@@ -166,7 +166,7 @@ public class Fraction
*
* @param value the double value to convert to a fraction.
* @param epsilon maximum error allowed. The resulting fraction is within
- * <code>epsilon</code> of <code>value</code>, in absolute terms.
+ * {@code epsilon} of {@code value}, in absolute terms.
* @param maxDenominator maximum denominator value allowed.
* @param maxIterations maximum number of convergents
* @throws FractionConversionException if the continued fraction failed to
@@ -251,17 +251,18 @@ public class Fraction
* reduced to lowest terms.
* @param num the numerator.
* @param den the denominator.
- * @throws ArithmeticException if the denominator is <code>zero</code>
+ * @throws MathArithmeticException if the denominator is {@code zero}
*/
public Fraction(int num, int den) {
if (den == 0) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION, num, den);
+ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
+ num, den);
}
if (den < 0) {
- if (num == Integer.MIN_VALUE || den == Integer.MIN_VALUE) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.OVERFLOW_IN_FRACTION, num, den);
+ if (num == Integer.MIN_VALUE ||
+ den == Integer.MIN_VALUE) {
+ throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
+ num, den);
}
num = -num;
den = -den;
@@ -403,8 +404,7 @@ public class Fraction
*/
public Fraction negate() {
if (numerator==Integer.MIN_VALUE) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator);
+ throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator);
}
return new Fraction(-numerator, denominator);
}
@@ -421,11 +421,11 @@ public class Fraction
* <p>Adds the value of this fraction to another, returning the result in reduced form.
* The algorithm follows Knuth, 4.5.1.</p>
*
- * @param fraction the fraction to add, must not be <code>null</code>
- * @return a <code>Fraction</code> instance with the resulting values
- * @throws IllegalArgumentException if the fraction is <code>null</code>
- * @throws ArithmeticException if the resulting numerator or denominator exceeds
- * <code>Integer.MAX_VALUE</code>
+ * @param fraction the fraction to add, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator exceeds
+ * {@code Integer.MAX_VALUE}
*/
public Fraction add(Fraction fraction) {
return addSub(fraction, true /* add */);
@@ -444,11 +444,11 @@ public class Fraction
* <p>Subtracts the value of another fraction from the value of this one,
* returning the result in reduced form.</p>
*
- * @param fraction the fraction to subtract, must not be <code>null</code>
- * @return a <code>Fraction</code> instance with the resulting values
- * @throws IllegalArgumentException if the fraction is <code>null</code>
- * @throws ArithmeticException if the resulting numerator or denominator
- * cannot be represented in an <code>int</code>.
+ * @param fraction the fraction to subtract, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator
+ * cannot be represented in an {@code int}.
*/
public Fraction subtract(Fraction fraction) {
return addSub(fraction, false /* subtract */);
@@ -466,12 +466,12 @@ public class Fraction
/**
* Implement add and subtract using algorithm described in Knuth 4.5.1.
*
- * @param fraction the fraction to subtract, must not be <code>null</code>
+ * @param fraction the fraction to subtract, must not be {@code null}
* @param isAdd true to add, false to subtract
- * @return a <code>Fraction</code> instance with the resulting values
- * @throws IllegalArgumentException if the fraction is <code>null</code>
- * @throws ArithmeticException if the resulting numerator or denominator
- * cannot be represented in an <code>int</code>.
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator
+ * cannot be represented in an {@code int}.
*/
private Fraction addSub(Fraction fraction, boolean isAdd) {
if (fraction == null) {
@@ -512,8 +512,8 @@ public class Fraction
// result is (t/d2) / (u'/d1)(v'/d2)
BigInteger w = t.divide(BigInteger.valueOf(d2));
if (w.bitLength() > 31) {
- throw MathRuntimeException.createArithmeticException(LocalizedFormats.NUMERATOR_OVERFLOW_AFTER_MULTIPLY,
- w);
+ throw new MathArithmeticException(LocalizedFormats.NUMERATOR_OVERFLOW_AFTER_MULTIPLY,
+ w);
}
return new Fraction (w.intValue(),
MathUtils.mulAndCheck(denominator/d1,
@@ -524,11 +524,11 @@ public class Fraction
* <p>Multiplies the value of this fraction by another, returning the
* result in reduced form.</p>
*
- * @param fraction the fraction to multiply by, must not be <code>null</code>
- * @return a <code>Fraction</code> instance with the resulting values
- * @throws IllegalArgumentException if the fraction is <code>null</code>
- * @throws ArithmeticException if the resulting numerator or denominator exceeds
- * <code>Integer.MAX_VALUE</code>
+ * @param fraction the fraction to multiply by, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator exceeds
+ * {@code Integer.MAX_VALUE}
*/
public Fraction multiply(Fraction fraction) {
if (fraction == null) {
@@ -558,21 +558,20 @@ public class Fraction
/**
* <p>Divide the value of this fraction by another.</p>
*
- * @param fraction the fraction to divide by, must not be <code>null</code>
- * @return a <code>Fraction</code> instance with the resulting values
- * @throws IllegalArgumentException if the fraction is <code>null</code>
- * @throws ArithmeticException if the fraction to divide by is zero
- * @throws ArithmeticException if the resulting numerator or denominator exceeds
- * <code>Integer.MAX_VALUE</code>
+ * @param fraction the fraction to divide by, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws IllegalArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the fraction to divide by is zero
+ * @throws MathArithmeticException if the resulting numerator or denominator exceeds
+ * {@code Integer.MAX_VALUE}
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
if (fraction.numerator == 0) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY,
- fraction.numerator, fraction.denominator);
+ throw new MathArithmeticException(LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY,
+ fraction.numerator, fraction.denominator);
}
return multiply(fraction.reciprocal());
}
@@ -587,7 +586,7 @@ public class Fraction
}
/**
- * <p>Creates a <code>Fraction</code> instance with the 2 parts
+ * <p>Creates a {@code Fraction} instance with the 2 parts
* of a fraction Y/Z.</p>
*
* <p>Any negative signs are resolved to be on the numerator.</p>
@@ -595,12 +594,12 @@ public class Fraction
* @param numerator the numerator, for example the three in 'three sevenths'
* @param denominator the denominator, for example the seven in 'three sevenths'
* @return a new fraction instance, with the numerator and denominator reduced
- * @throws ArithmeticException if the denominator is <code>zero</code>
+ * @throws MathArithmeticException if the denominator is {@code zero}
*/
public static Fraction getReducedFraction(int numerator, int denominator) {
if (denominator == 0) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION, numerator, denominator);
+ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
+ numerator, denominator);
}
if (numerator==0) {
return ZERO; // normalize zero.
@@ -612,8 +611,8 @@ public class Fraction
if (denominator < 0) {
if (numerator==Integer.MIN_VALUE ||
denominator==Integer.MIN_VALUE) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator);
+ throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
+ numerator, denominator);
}
numerator = -numerator;
denominator = -denominator;
@@ -627,7 +626,7 @@ public class Fraction
/**
* <p>
- * Returns the <code>String</code> representing this fraction, ie
+ * Returns the {@code String} representing this fraction, ie
* "num / dem" or just "num" if the denominator is one.
* </p>
*
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java Fri Dec 10 00:50:50 2010
@@ -27,7 +27,6 @@ import org.apache.commons.math.analysis.
import org.apache.commons.math.analysis.function.Add;
import org.apache.commons.math.analysis.function.Multiply;
import org.apache.commons.math.analysis.function.Divide;
-import org.apache.commons.math.analysis.function.Power;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.FastMath;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java Fri Dec 10 00:50:50 2010
@@ -18,7 +18,6 @@
package org.apache.commons.math.optimization.direct;
import org.apache.commons.math.util.Incrementor;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.MaxCountExceededException;
import org.apache.commons.math.exception.TooManyEvaluationsException;
import org.apache.commons.math.exception.NullArgumentException;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java Fri Dec 10 00:50:50 2010
@@ -22,7 +22,6 @@ import java.util.List;
import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
import org.apache.commons.math.optimization.VectorialPointValuePair;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java Fri Dec 10 00:50:50 2010
@@ -16,7 +16,9 @@
*/
package org.apache.commons.math.stat;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NumberIsTooSmallException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math.stat.descriptive.UnivariateStatistic;
@@ -560,19 +562,17 @@ public final class StatUtils {
* @param sample1 the first array
* @param sample2 the second array
* @return sum of paired differences
- * @throws IllegalArgumentException if the arrays do not have the same
- * (positive) length
+ * @throws DimensionMismatchException if the arrays do not have the same
+ * (positive) length.
+ * @throws NoDataException if the sample arrays are empty.
*/
- public static double sumDifference(final double[] sample1, final double[] sample2)
- throws IllegalArgumentException {
+ public static double sumDifference(final double[] sample1, final double[] sample2) {
int n = sample1.length;
- if (n != sample2.length) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, sample2.length);
+ if (n != sample2.length) {
+ throw new DimensionMismatchException(n, sample2.length);
}
- if (n < 1) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INSUFFICIENT_DIMENSION, sample2.length, 1);
+ if (n <= 0) {
+ throw new NoDataException(LocalizedFormats.INSUFFICIENT_DIMENSION);
}
double result = 0;
for (int i = 0; i < n; i++) {
@@ -588,11 +588,11 @@ public final class StatUtils {
* @param sample1 the first array
* @param sample2 the second array
* @return mean of paired differences
- * @throws IllegalArgumentException if the arrays do not have the same
- * (positive) length
+ * @throws DimensionMismatchException if the arrays do not have the same
+ * (positive) length.
+ * @throws NoDataException if the sample arrays are empty.
*/
- public static double meanDifference(final double[] sample1, final double[] sample2)
- throws IllegalArgumentException {
+ public static double meanDifference(final double[] sample1, final double[] sample2) {
return sumDifference(sample1, sample2) / sample1.length;
}
@@ -605,22 +605,22 @@ public final class StatUtils {
* @param meanDifference the mean difference between corresponding entries
* @see #meanDifference(double[],double[])
* @return variance of paired differences
- * @throws IllegalArgumentException if the arrays do not have the same
- * length or their common length is less than 2.
- */
- public static double varianceDifference(final double[] sample1, final double[] sample2,
- double meanDifference) throws IllegalArgumentException {
+ * @throws DimensionMismatchException if the arrays do not have the same
+ * length.
+ * @throws NumberIsTooSmallException if the arrays length is less than 2.
+ */
+ public static double varianceDifference(final double[] sample1,
+ final double[] sample2,
+ double meanDifference) {
double sum1 = 0d;
double sum2 = 0d;
double diff = 0d;
int n = sample1.length;
if (n != sample2.length) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, sample2.length);
+ throw new DimensionMismatchException(n, sample2.length);
}
if (n < 2) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INSUFFICIENT_DIMENSION, n, 2);
+ throw new NumberIsTooSmallException(n, 2, true);
}
for (int i = 0; i < n; i++) {
diff = sample1[i] - sample2[i];
@@ -629,34 +629,32 @@ public final class StatUtils {
}
return (sum1 - (sum2 * sum2 / n)) / (n - 1);
}
-
-
- /**
- * Normalize (standardize) the series, so in the end it is having a mean of 0 and a standard deviation of 1.
- *
- * @param sample sample to normalize
- * @return normalized (standardized) sample
- */
- public static double[] normalize(final double[] sample) {
- DescriptiveStatistics stats = new DescriptiveStatistics();
-
- // Add the data from the series to stats
- for (int i = 0; i < sample.length; i++) {
- stats.addValue(sample[i]);
- }
-
- // Compute mean and standard deviation
- double mean = stats.getMean();
- double standardDeviation = stats.getStandardDeviation();
-
- // initialize the standardizedSample, which has the same length as the sample
- double[] standardizedSample = new double[sample.length];
-
- for (int i = 0; i < sample.length; i++) {
- // z = (x- mean)/standardDeviation
- standardizedSample[i] = (sample[i] - mean) / standardDeviation;
- }
- return standardizedSample;
- }
+ /**
+ * Normalize (standardize) the series, so in the end it is having a mean of 0 and a standard deviation of 1.
+ *
+ * @param sample Sample to normalize.
+ * @return normalized (standardized) sample.
+ */
+ public static double[] normalize(final double[] sample) {
+ DescriptiveStatistics stats = new DescriptiveStatistics();
+
+ // Add the data from the series to stats
+ for (int i = 0; i < sample.length; i++) {
+ stats.addValue(sample[i]);
+ }
+
+ // Compute mean and standard deviation
+ double mean = stats.getMean();
+ double standardDeviation = stats.getStandardDeviation();
+
+ // initialize the standardizedSample, which has the same length as the sample
+ double[] standardizedSample = new double[sample.length];
+
+ for (int i = 0; i < sample.length; i++) {
+ // z = (x- mean)/standardDeviation
+ standardizedSample[i] = (sample[i] - mean) / standardDeviation;
+ }
+ return standardizedSample;
+ }
}
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=1044186&r1=1044185&r2=1044186&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 Dec 10 00:50:50 2010
@@ -16,10 +16,11 @@
*/
package org.apache.commons.math.stat.descriptive;
-import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.NotPositiveException;
import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**
@@ -172,8 +173,8 @@ public abstract class AbstractUnivariate
}
if (begin + length > values.length) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END);
+ throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END,
+ begin + length, values.length, true);
}
if (length == 0 && !allowEmpty) {
@@ -265,16 +266,13 @@ public abstract class AbstractUnivariate
boolean containsPositiveWeight = false;
for (int i = begin; i < begin + length; i++) {
if (Double.isNaN(weights[i])) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NAN_ELEMENT_AT_INDEX, i);
+ throw new MathIllegalArgumentException(LocalizedFormats.NAN_ELEMENT_AT_INDEX, i);
}
if (Double.isInfinite(weights[i])) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INFINITE_ARRAY_ELEMENT, weights[i], i);
+ throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, weights[i], i);
}
if (weights[i] < 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, i, weights[i]);
+ throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, i, weights[i]);
}
if (!containsPositiveWeight && weights[i] > 0.0) {
containsPositiveWeight = true;
@@ -282,8 +280,7 @@ public abstract class AbstractUnivariate
}
if (!containsPositiveWeight) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO);
+ throw new MathIllegalArgumentException(LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO);
}
return test(values, begin, length, allowEmpty);
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java Fri Dec 10 00:50:50 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.stat.des
import java.io.Serializable;
import java.util.Arrays;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic;
import org.apache.commons.math.util.FastMath;
@@ -258,8 +258,7 @@ public class Percentile extends Abstract
test(values, begin, length);
if ((p > 100) || (p <= 0)) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p);
+ throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100);
}
if (length == 0) {
return Double.NaN;
@@ -462,8 +461,7 @@ public class Percentile extends Abstract
*/
public void setQuantile(final double p) {
if (p <= 0 || p > 100) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p);
+ throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100);
}
quantile = p;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java Fri Dec 10 00:50:50 2010
@@ -17,7 +17,12 @@
package org.apache.commons.math.stat.inference;
import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NotPositiveException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.exception.NumberIsTooSmallException;
+import org.apache.commons.math.exception.OutOfRangeException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.distribution.ChiSquaredDistribution;
import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
import org.apache.commons.math.exception.util.LocalizedFormats;
@@ -60,18 +65,14 @@ public class ChiSquareTestImpl implement
* @param observed array of observed frequency counts
* @param expected array of expected frequency counts
* @return chi-square test statistic
- * @throws IllegalArgumentException if preconditions are not met
- * or length is less than 2
+ * @throws DimensionMismatchException if the arrays length is less than 2.
*/
- public double chiSquare(double[] expected, long[] observed)
- throws IllegalArgumentException {
+ public double chiSquare(double[] expected, long[] observed) {
if (expected.length < 2) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INSUFFICIENT_DIMENSION, expected.length, 2);
+ throw new DimensionMismatchException(expected.length, 2);
}
if (expected.length != observed.length) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, expected.length, observed.length);
+ throw new DimensionMismatchException(expected.length, observed.length);
}
checkPositive(expected);
checkNonNegative(observed);
@@ -109,11 +110,11 @@ public class ChiSquareTestImpl implement
* @param observed array of observed frequency counts
* @param expected array of expected frequency counts
* @return p-value
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @throws MathException if an error occurs computing the p-value
*/
public double chiSquareTest(double[] expected, long[] observed)
- throws IllegalArgumentException, MathException {
+ throws MathException {
distribution = new ChiSquaredDistributionImpl(expected.length - 1.0);
return 1.0 - distribution.cumulativeProbability(
chiSquare(expected, observed));
@@ -130,15 +131,15 @@ public class ChiSquareTestImpl implement
* @param alpha significance level of the test
* @return true iff null hypothesis can be rejected with confidence
* 1 - alpha
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @throws MathException if an error occurs performing the test
*/
public boolean chiSquareTest(double[] expected, long[] observed,
- double alpha) throws IllegalArgumentException, MathException {
+ double alpha)
+ throws MathException {
if ((alpha <= 0) || (alpha > 0.5)) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
- alpha, 0, 0.5);
+ throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
+ alpha, 0, 0.5);
}
return chiSquareTest(expected, observed) < alpha;
}
@@ -146,10 +147,9 @@ public class ChiSquareTestImpl implement
/**
* @param counts array representation of 2-way table
* @return chi-square test statistic
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met.
*/
- public double chiSquare(long[][] counts) throws IllegalArgumentException {
-
+ public double chiSquare(long[][] counts) {
checkArray(counts);
int nRows = counts.length;
int nCols = counts[0].length;
@@ -182,11 +182,11 @@ public class ChiSquareTestImpl implement
/**
* @param counts array representation of 2-way table
* @return p-value
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @throws MathException if an error occurs computing the p-value
*/
public double chiSquareTest(long[][] counts)
- throws IllegalArgumentException, MathException {
+ throws MathException {
checkArray(counts);
double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
distribution = new ChiSquaredDistributionImpl(df);
@@ -198,15 +198,14 @@ public class ChiSquareTestImpl implement
* @param alpha significance level of the test
* @return true iff null hypothesis can be rejected with confidence
* 1 - alpha
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @throws MathException if an error occurs performing the test
*/
public boolean chiSquareTest(long[][] counts, double alpha)
- throws IllegalArgumentException, MathException {
+ throws MathException {
if ((alpha <= 0) || (alpha > 0.5)) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
- alpha, 0.0, 0.5);
+ throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
+ alpha, 0, 0.5);
}
return chiSquareTest(counts) < alpha;
}
@@ -215,21 +214,16 @@ public class ChiSquareTestImpl implement
* @param observed1 array of observed frequency counts of the first data set
* @param observed2 array of observed frequency counts of the second data set
* @return chi-square test statistic
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @since 1.2
*/
- public double chiSquareDataSetsComparison(long[] observed1, long[] observed2)
- throws IllegalArgumentException {
-
+ public double chiSquareDataSetsComparison(long[] observed1, long[] observed2) {
// Make sure lengths are same
if (observed1.length < 2) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INSUFFICIENT_DIMENSION, observed1.length, 2);
+ throw new DimensionMismatchException(observed1.length, 2);
}
if (observed1.length != observed2.length) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
- observed1.length, observed2.length);
+ throw new DimensionMismatchException(observed1.length, observed2.length);
}
// Ensure non-negative counts
@@ -247,12 +241,10 @@ public class ChiSquareTestImpl implement
}
// Ensure neither sample is uniformly 0
if (countSum1 == 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OBSERVED_COUNTS_ALL_ZERO, 1);
+ throw new MathIllegalArgumentException(LocalizedFormats.OBSERVED_COUNTS_ALL_ZERO, 1);
}
if (countSum2 == 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OBSERVED_COUNTS_ALL_ZERO, 2);
+ throw new MathIllegalArgumentException(LocalizedFormats.OBSERVED_COUNTS_ALL_ZERO, 2);
}
// Compare and compute weight only if different
unequalCounts = countSum1 != countSum2;
@@ -266,8 +258,7 @@ public class ChiSquareTestImpl implement
double obs2 = 0.0d;
for (int i = 0; i < observed1.length; i++) {
if (observed1[i] == 0 && observed2[i] == 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OBSERVED_COUNTS_BOTTH_ZERO_FOR_ENTRY, i);
+ throw new MathIllegalArgumentException(LocalizedFormats.OBSERVED_COUNTS_BOTTH_ZERO_FOR_ENTRY, i);
} else {
obs1 = observed1[i];
obs2 = observed2[i];
@@ -286,12 +277,12 @@ public class ChiSquareTestImpl implement
* @param observed1 array of observed frequency counts of the first data set
* @param observed2 array of observed frequency counts of the second data set
* @return p-value
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @throws MathException if an error occurs computing the p-value
* @since 1.2
*/
public double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
- throws IllegalArgumentException, MathException {
+ throws MathException {
distribution = new ChiSquaredDistributionImpl((double) observed1.length - 1);
return 1 - distribution.cumulativeProbability(
chiSquareDataSetsComparison(observed1, observed2));
@@ -303,16 +294,17 @@ public class ChiSquareTestImpl implement
* @param alpha significance level of the test
* @return true iff null hypothesis can be rejected with confidence
* 1 - alpha
- * @throws IllegalArgumentException if preconditions are not met
+ * @throws MathIllegalArgumentException if preconditions are not met
* @throws MathException if an error occurs performing the test
* @since 1.2
*/
public boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
- double alpha) throws IllegalArgumentException, MathException {
- if ((alpha <= 0) || (alpha > 0.5)) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
- alpha, 0.0, 0.5);
+ double alpha)
+ throws MathException {
+ if (alpha <= 0 ||
+ alpha > 0.5) {
+ throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
+ alpha, 0, 0.5);
}
return chiSquareTestDataSetsComparison(observed1, observed2) < alpha;
}
@@ -320,21 +312,18 @@ public class ChiSquareTestImpl implement
/**
* Checks to make sure that the input long[][] array is rectangular,
* has at least 2 rows and 2 columns, and has all non-negative entries,
- * throwing IllegalArgumentException if any of these checks fail.
+ * throwing MathIllegalArgumentException if any of these checks fail.
*
* @param in input 2-way table to check
- * @throws IllegalArgumentException if the array is not valid
+ * @throws MathIllegalArgumentException if the array is not valid
*/
- private void checkArray(long[][] in) throws IllegalArgumentException {
-
+ private void checkArray(long[][] in) {
if (in.length < 2) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INSUFFICIENT_DIMENSION, in.length, 2);
+ throw new NumberIsTooSmallException(in.length, 2, true);
}
if (in[0].length < 2) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.INSUFFICIENT_DIMENSION, in[0].length, 2);
+ throw new NumberIsTooSmallException(in[0].length, 2, true);
}
checkRectangular(in);
@@ -345,34 +334,31 @@ public class ChiSquareTestImpl implement
//--------------------- Private array methods -- should find a utility home for these
/**
- * Throws IllegalArgumentException if the input array is not rectangular.
+ * Throws MathIllegalArgumentException if the input array is not rectangular.
*
* @param in array to be tested
* @throws NullPointerException if input array is null
- * @throws IllegalArgumentException if input array is not rectangular
+ * @throws MathIllegalArgumentException if input array is not rectangular
*/
private void checkRectangular(long[][] in) {
for (int i = 1; i < in.length; i++) {
if (in[i].length != in[0].length) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.DIFFERENT_ROWS_LENGTHS,
- in[i].length, in[0].length);
+ throw new DimensionMismatchException(LocalizedFormats.DIFFERENT_ROWS_LENGTHS,
+ in[i].length, in[0].length);
}
}
}
/**
- * Check all entries of the input array are > 0.
+ * Check all entries of the input array are strictly postive.
*
- * @param in array to be tested
- * @exception IllegalArgumentException if one entry is not positive
+ * @param in Array to be tested.
+ * @exception NotStrictlyPositiveException if one entry is not positive.
*/
- private void checkPositive(double[] in) throws IllegalArgumentException {
+ private void checkPositive(double[] in) {
for (int i = 0; i < in.length; i++) {
if (in[i] <= 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_ELEMENT_AT_INDEX,
- i, in[i]);
+ throw new NotStrictlyPositiveException(in[i]);
}
}
}
@@ -380,15 +366,13 @@ public class ChiSquareTestImpl implement
/**
* Check all entries of the input array are >= 0.
*
- * @param in array to be tested
- * @exception IllegalArgumentException if one entry is negative
+ * @param in Array to be tested.
+ * @exception NotPositiveException if one entry is negative.
*/
- private void checkNonNegative(long[] in) throws IllegalArgumentException {
+ private void checkNonNegative(long[] in) {
for (int i = 0; i < in.length; i++) {
if (in[i] < 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX,
- i, in[i]);
+ throw new NotPositiveException(in[i]);
}
}
}
@@ -396,16 +380,14 @@ public class ChiSquareTestImpl implement
/**
* Check all entries of the input array are >= 0.
*
- * @param in array to be tested
- * @exception IllegalArgumentException if one entry is negative
+ * @param in Array to be tested.
+ * @exception NotPositiveException if one entry is negative.
*/
- private void checkNonNegative(long[][] in) throws IllegalArgumentException {
+ private void checkNonNegative(long[][] in) {
for (int i = 0; i < in.length; i ++) {
for (int j = 0; j < in[i].length; j++) {
if (in[i][j] < 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NEGATIVE_ELEMENT_AT_2D_INDEX,
- i, j, in[i][j]);
+ throw new NotPositiveException(in[i][j]);
}
}
}