diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java index f8d8e9e8f..d0128b66d 100644 --- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java @@ -21,10 +21,12 @@ import java.util.Arrays; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.ParametricUnivariateRealFunction; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Immutable representation of a real polynomial function with real coefficients. @@ -57,11 +59,13 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction, * the coefficients property.

* * @param c Polynomial coefficients. - * @throws NullPointerException if {@code c} is {@code null}. + * @throws NullArgumentException if {@code c} is {@code null}. * @throws NoDataException if {@code c} is empty. */ - public PolynomialFunction(double c[]) { + public PolynomialFunction(double c[]) + throws NullArgumentException, NoDataException { super(); + MathUtils.checkNotNull(c); int n = c.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); @@ -117,9 +121,11 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction, * @param argument Input value. * @return the value of the polynomial. * @throws NoDataException if {@code coefficients} is empty. - * @throws NullPointerException if {@code coefficients} is {@code null}. + * @throws NullArgumentException if {@code coefficients} is {@code null}. */ - protected static double evaluate(double[] coefficients, double argument) { + protected static double evaluate(double[] coefficients, double argument) + throws NullArgumentException, NoDataException { + MathUtils.checkNotNull(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); @@ -224,9 +230,11 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction, * @param coefficients Coefficients of the polynomial to differentiate. * @return the coefficients of the derivative or {@code null} if coefficients has length 1. * @throws NoDataException if {@code coefficients} is empty. - * @throws NullPointerException if {@code coefficients} is {@code null}. + * @throws NullArgumentException if {@code coefficients} is {@code null}. */ - protected static double[] differentiate(double[] coefficients) { + protected static double[] differentiate(double[] coefficients) + throws NullArgumentException, NoDataException { + MathUtils.checkNotNull(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); diff --git a/src/main/java/org/apache/commons/math/complex/Complex.java b/src/main/java/org/apache/commons/math/complex/Complex.java index 5bac623e5..e65f63371 100644 --- a/src/main/java/org/apache/commons/math/complex/Complex.java +++ b/src/main/java/org/apache/commons/math/complex/Complex.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.FastMath; @@ -144,9 +145,11 @@ public class Complex implements FieldElement, Serializable { * * @param rhs the other complex number * @return the complex number sum - * @throws NullPointerException if rhs is null + * @throws NullArgumentException if rhs is null */ - public Complex add(Complex rhs) { + public Complex add(Complex rhs) + throws NullArgumentException { + MathUtils.checkNotNull(rhs); return createComplex(real + rhs.getReal(), imaginary + rhs.getImaginary()); } @@ -205,9 +208,11 @@ public class Complex implements FieldElement, Serializable { * * @param rhs the other complex number * @return the complex number quotient - * @throws NullPointerException if rhs is null + * @throws NullArgumentException if rhs is null */ - public Complex divide(Complex rhs) { + public Complex divide(Complex rhs) + throws NullArgumentException { + MathUtils.checkNotNull(rhs); if (isNaN() || rhs.isNaN()) { return NaN; } @@ -352,9 +357,11 @@ public class Complex implements FieldElement, Serializable { * * @param rhs the other complex number * @return the complex number product - * @throws NullPointerException if rhs is null + * @throws NullArgumentException if rhs is null */ - public Complex multiply(Complex rhs) { + public Complex multiply(Complex rhs) + throws NullArgumentException { + MathUtils.checkNotNull(rhs); if (isNaN() || rhs.isNaN()) { return NaN; } @@ -437,9 +444,11 @@ public class Complex implements FieldElement, Serializable { * * @param rhs the other complex number * @return the complex number difference - * @throws NullPointerException if rhs is null + * @throws NullArgumentException if rhs is null */ - public Complex subtract(Complex rhs) { + public Complex subtract(Complex rhs) + throws NullArgumentException { + MathUtils.checkNotNull(rhs); if (isNaN() || rhs.isNaN()) { return NaN; } @@ -673,13 +682,12 @@ public class Complex implements FieldElement, Serializable { * * @param x the exponent. * @return thisx - * @throws NullPointerException if x is null + * @throws NullArgumentException if x is null * @since 1.2 */ - public Complex pow(Complex x) { - if (x == null) { - throw new NullPointerException(); - } + public Complex pow(Complex x) + throws NullArgumentException { + MathUtils.checkNotNull(x); return this.log().multiply(x).exp(); } diff --git a/src/main/java/org/apache/commons/math/exception/NullArgumentException.java b/src/main/java/org/apache/commons/math/exception/NullArgumentException.java index 71e775b77..23309b636 100644 --- a/src/main/java/org/apache/commons/math/exception/NullArgumentException.java +++ b/src/main/java/org/apache/commons/math/exception/NullArgumentException.java @@ -24,7 +24,7 @@ import org.apache.commons.math.exception.util.LocalizedFormats; * 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 + * Propagation of {@code NullPointerException} from within Commons-Math is * construed to be a bug. * * @since 2.2 diff --git a/src/main/java/org/apache/commons/math/fraction/BigFraction.java b/src/main/java/org/apache/commons/math/fraction/BigFraction.java index 6c4536fc0..8eddcc4cc 100644 --- a/src/main/java/org/apache/commons/math/fraction/BigFraction.java +++ b/src/main/java/org/apache/commons/math/fraction/BigFraction.java @@ -458,10 +458,11 @@ public class BigFraction * @param bg * the {@link BigInteger} to add, must'nt be null. * @return a BigFraction instance with the resulting values. - * @throws NullPointerException + * @throws NullArgumentException * if the {@link BigInteger} is null. */ - public BigFraction add(final BigInteger bg) { + public BigFraction add(final BigInteger bg) throws NullArgumentException { + MathUtils.checkNotNull(bg); return new BigFraction(numerator.add(denominator.multiply(bg)), denominator); } diff --git a/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java b/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java index 5ee2b3e60..c707aeca5 100644 --- a/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.NotStrictlyPositiveException; import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.FastMath; @@ -385,7 +386,9 @@ public abstract class AbstractRealMatrix implements RealMatrix { } /** {@inheritDoc} */ - public void setSubMatrix(final double[][] subMatrix, final int row, final int column) { + public void setSubMatrix(final double[][] subMatrix, final int row, final int column) + throws NoDataException, DimensionMismatchException, NullArgumentException { + MathUtils.checkNotNull(subMatrix); final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); diff --git a/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java index 875d8ba66..7255e0f63 100644 --- a/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java @@ -24,7 +24,9 @@ import org.apache.commons.math.FieldElement; import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.MathIllegalStateException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; +import org.apache.commons.math.util.MathUtils; /** * Implementation of FieldMatrix using a {@link FieldElement}[][] array to store entries. @@ -140,18 +142,16 @@ public class Array2DRowFieldMatrix> * @param copyArray Whether to copy or reference the input array. * @throws DimensionMismatchException if {@code d} is not rectangular. * @throws NoDataException if there are not at least one row and one column. - * @throws org.apache.commons.math.exception.NullArgumentException - * if {@code d} is {@code null}. + * @throws NullArgumentException if {@code d} is {@code null}. * @see #Array2DRowFieldMatrix(FieldElement[][]) */ - public Array2DRowFieldMatrix(final Field field, final T[][] d, final boolean copyArray) { + public Array2DRowFieldMatrix(final Field field, final T[][] d, final boolean copyArray) + throws DimensionMismatchException, NoDataException, NullArgumentException { super(field); if (copyArray) { copyIn(d); } else { - if (d == null) { - throw new NullPointerException(); - } + MathUtils.checkNotNull(d); final int nRows = d.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); diff --git a/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java b/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java index b721f8f79..8db8dc716 100644 --- a/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java @@ -24,6 +24,7 @@ import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.exception.util.LocalizedFormats; +import org.apache.commons.math.util.MathUtils; /** * Implementation of RealMatrix using a double[][] array to store entries and @@ -87,10 +88,11 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ * @param d Data for the new matrix. * @throws DimensionMismatchException if {@code d} is not rectangular. * @throws NoDataException if {@code d} row or colum dimension is zero. - * @throws NullPointerException if {@code d} is {@code null}. + * @throws NullArgumentException if {@code d} is {@code null}. * @see #Array2DRowRealMatrix(double[][], boolean) */ - public Array2DRowRealMatrix(final double[][] d) { + public Array2DRowRealMatrix(final double[][] d) + throws DimensionMismatchException, NoDataException, NullArgumentException { copyIn(d); } @@ -275,6 +277,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ if (column > 0) { throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); } + MathUtils.checkNotNull(subMatrix); final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); @@ -526,10 +529,11 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ * @param in Data to copy. * @throws NoDataException if the input array is empty. * @throws DimensionMismatchException if the input array is not rectangular. - * @throws org.apache.commons.math.exception.NullArgumentException if + * @throws NullArgumentException if * the input array is {@code null}. */ - private void copyIn(final double[][] in) { + private void copyIn(final double[][] in) + throws DimensionMismatchException, NoDataException, NullArgumentException { setSubMatrix(in, 0, 0); } } diff --git a/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java index 12edd46b0..8e9378317 100644 --- a/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java @@ -25,6 +25,7 @@ import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Cache-friendly implementation of FieldMatrix using a flat arrays to store @@ -759,6 +760,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa @Override public void setSubMatrix(final T[][] subMatrix, final int row, final int column) { // safety checks + MathUtils.checkNotNull(subMatrix); final int refLength = subMatrix[0].length; if (refLength == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); diff --git a/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java b/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java index 91a8c7043..b466fb6bd 100644 --- a/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java @@ -22,8 +22,10 @@ import java.util.Arrays; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Cache-friendly implementation of RealMatrix using a flat arrays to store @@ -764,8 +766,10 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable /** {@inheritDoc} */ @Override - public void setSubMatrix(final double[][] subMatrix, final int row, final int column) { + public void setSubMatrix(final double[][] subMatrix, final int row, final int column) + throws NoDataException, NullArgumentException { // safety checks + MathUtils.checkNotNull(subMatrix); final int refLength = subMatrix[0].length; if (refLength == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); diff --git a/src/main/java/org/apache/commons/math/linear/RealMatrix.java b/src/main/java/org/apache/commons/math/linear/RealMatrix.java index 2b733517f..a0f4fd3c1 100644 --- a/src/main/java/org/apache/commons/math/linear/RealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/RealMatrix.java @@ -17,6 +17,11 @@ package org.apache.commons.math.linear; +import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.OutOfRangeException; +import org.apache.commons.math.exception.ZeroException; + /** * Interface defining a real-valued matrix with basic algebraic operations. *

@@ -210,19 +215,16 @@ public interface RealMatrix extends AnyMatrix { * @param subMatrix array containing the submatrix replacement data * @param row row coordinate of the top, left element to be replaced * @param column column coordinate of the top, left element to be replaced - * @throws org.apache.commons.math.exception.ZeroException if - * {@code subMatrix} does not contain at least one column. - * @throws org.apache.commons.math.exception.OutOfRangeException if - * {@code subMatrix} does not fit into this matrix from element in - * {@code (row, column)}. - * @throws org.apache.commons.math.exception.DimensionMismatchException - * if {@code subMatrix} is not rectangular. + * @throws ZeroException if {@code subMatrix} does not contain at least one column. + * @throws OutOfRangeException if {@code subMatrix} does not fit into + * this matrix from element in {@code (row, column)}. + * @throws DimensionMismatchException if {@code subMatrix} is not rectangular. * (not all rows have the same length) or empty. - * @throws org.apache.commons.math.exception.NullArgumentException if - * {@code subMatrix} is {@code null}. + * @throws NullArgumentException if {@code subMatrix} is {@code null}. * @since 2.0 */ - void setSubMatrix(double[][] subMatrix, int row, int column); + void setSubMatrix(double[][] subMatrix, int row, int column) + throws ZeroException, OutOfRangeException, DimensionMismatchException, NullArgumentException; /** * Geet the entries at the given row index diff --git a/src/main/java/org/apache/commons/math/random/EmpiricalDistribution.java b/src/main/java/org/apache/commons/math/random/EmpiricalDistribution.java index 2bf910eb7..b0a1047a4 100644 --- a/src/main/java/org/apache/commons/math/random/EmpiricalDistribution.java +++ b/src/main/java/org/apache/commons/math/random/EmpiricalDistribution.java @@ -22,6 +22,7 @@ import java.io.File; import java.net.URL; import java.util.List; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.StatisticalSummary; import org.apache.commons.math.stat.descriptive.SummaryStatistics; @@ -62,6 +63,7 @@ public interface EmpiricalDistribution { * * @param file the input file * @throws IOException if an IO error occurs + * @throws NullArgumentException if file is null */ void load(File file) throws IOException; @@ -70,8 +72,9 @@ public interface EmpiricalDistribution { * * @param url url of the input file * @throws IOException if an IO error occurs + * @throws NullArgumentException if url is null */ - void load(URL url) throws IOException; + void load(URL url) throws IOException, NullArgumentException; /** * Generates a random value from this distribution. diff --git a/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index 6f7df7722..4604ac228 100644 --- a/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -28,10 +28,12 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.StatisticalSummary; import org.apache.commons.math.stat.descriptive.SummaryStatistics; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Implements EmpiricalDistribution interface. This implementation @@ -115,8 +117,9 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * array of numbers. * * @param in the input data array + * @exception NullArgumentException if in is null */ - public void load(double[] in) { + public void load(double[] in) throws NullArgumentException { DataAdapter da = new ArrayDataAdapter(in); try { da.computeStats(); @@ -133,8 +136,10 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * @param url url of the input file * * @throws IOException if an IO error occurs + * @throws NullArgumentException if url is null */ - public void load(URL url) throws IOException { + public void load(URL url) throws IOException, NullArgumentException { + MathUtils.checkNotNull(url); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); try { @@ -161,8 +166,10 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * * @param file the input file * @throws IOException if an IO error occurs + * @throws NullArgumentException if file is null */ - public void load(File file) throws IOException { + public void load(File file) throws IOException, NullArgumentException { + MathUtils.checkNotNull(file); BufferedReader in = new BufferedReader(new FileReader(file)); try { DataAdapter da = new StreamDataAdapter(in); @@ -288,9 +295,11 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * Construct an ArrayDataAdapter from a double[] array * * @param in double[] array holding the data + * @throws NullArgumentException if in is null */ - public ArrayDataAdapter(double[] in){ + public ArrayDataAdapter(double[] in) throws NullArgumentException { super(); + MathUtils.checkNotNull(in); inputArray = in; } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java index b948b6183..c25a48198 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java @@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.moment.GeometricMean; import org.apache.commons.math.stat.descriptive.moment.Kurtosis; @@ -32,6 +33,7 @@ import org.apache.commons.math.stat.descriptive.rank.Min; import org.apache.commons.math.stat.descriptive.rank.Percentile; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.ResizableDoubleArray; import org.apache.commons.math.util.FastMath; @@ -699,9 +701,12 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { * * @param source DescriptiveStatistics to copy * @param dest DescriptiveStatistics to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest) { + public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); // Copy data and window size dest.eDA = source.eDA.copy(); dest.windowSize = source.windowSize; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java index 8eb689efd..d4f80e57c 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java @@ -19,6 +19,7 @@ package org.apache.commons.math.stat.descriptive; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.moment.GeometricMean; import org.apache.commons.math.stat.descriptive.moment.Mean; @@ -652,9 +653,12 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { * * @param source SummaryStatistics to copy * @param dest SummaryStatistics to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(SummaryStatistics source, SummaryStatistics dest) { + public static void copy(SummaryStatistics source, SummaryStatistics dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.maxImpl = source.maxImpl.copy(); dest.meanImpl = source.meanImpl.copy(); dest.minImpl = source.minImpl.copy(); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java index 5f9310861..0dc015e78 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java @@ -16,6 +16,9 @@ */ package org.apache.commons.math.stat.descriptive; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.util.MathUtils; + /** * Implementation of * {@link org.apache.commons.math.stat.descriptive.DescriptiveStatistics} that @@ -159,10 +162,13 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics { * * @param source SynchronizedDescriptiveStatistics to copy * @param dest SynchronizedDescriptiveStatistics to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ public static void copy(SynchronizedDescriptiveStatistics source, - SynchronizedDescriptiveStatistics dest) { + SynchronizedDescriptiveStatistics dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); synchronized (source) { synchronized (dest) { DescriptiveStatistics.copy(source, dest); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedSummaryStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedSummaryStatistics.java index 75e06242e..fa4782838 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedSummaryStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/SynchronizedSummaryStatistics.java @@ -16,6 +16,9 @@ */ package org.apache.commons.math.stat.descriptive; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.util.MathUtils; + /** * Implementation of * {@link org.apache.commons.math.stat.descriptive.SummaryStatistics} that @@ -319,10 +322,13 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics { * * @param source SynchronizedSummaryStatistics to copy * @param dest SynchronizedSummaryStatistics to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ public static void copy(SynchronizedSummaryStatistics source, - SynchronizedSummaryStatistics dest) { + SynchronizedSummaryStatistics dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); synchronized (source) { synchronized (dest) { SummaryStatistics.copy(source, dest); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/FirstMoment.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/FirstMoment.java index c760b29f8..5d5b2f4bc 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/FirstMoment.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/FirstMoment.java @@ -17,7 +17,10 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; + +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** * Computes the first moment (arithmetic mean). Uses the definitional formula: @@ -148,9 +151,12 @@ public class FirstMoment extends AbstractStorelessUnivariateStatistic * * @param source FirstMoment to copy * @param dest FirstMoment to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(FirstMoment source, FirstMoment dest) { + public static void copy(FirstMoment source, FirstMoment dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.m1 = source.m1; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/FourthMoment.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/FourthMoment.java index cbcd3a350..ed288e708 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/FourthMoment.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/FourthMoment.java @@ -18,6 +18,9 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.util.MathUtils; + /** * Computes a statistic related to the Fourth Central Moment. Specifically, * what is computed is the sum of @@ -133,9 +136,12 @@ public class FourthMoment extends ThirdMoment implements Serializable{ * * @param source FourthMoment to copy * @param dest FourthMoment to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(FourthMoment source, FourthMoment dest) { + public static void copy(FourthMoment source, FourthMoment dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); ThirdMoment.copy(source, dest); dest.m4 = source.m4; } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java index 459124695..735efea71 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java @@ -19,11 +19,13 @@ 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.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Returns the @@ -183,9 +185,12 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen * * @param source GeometricMean to copy * @param dest GeometricMean to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(GeometricMean source, GeometricMean dest) { + public static void copy(GeometricMean source, GeometricMean dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.sumOfLogs = source.sumOfLogs.copy(); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java index 815e7964b..e0e552412 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java @@ -19,9 +19,11 @@ 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.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** @@ -211,9 +213,12 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S * * @param source Kurtosis to copy * @param dest Kurtosis to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Kurtosis source, Kurtosis dest) { + public static void copy(Kurtosis source, Kurtosis dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.moment = source.moment.copy(); dest.incMoment = source.incMoment; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Mean.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Mean.java index e959b029b..b1b67fd1e 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Mean.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Mean.java @@ -18,9 +18,11 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.WeightedEvaluation; import org.apache.commons.math.stat.descriptive.summary.Sum; +import org.apache.commons.math.util.MathUtils; /** *

Computes the arithmetic mean of a set of values. Uses the definitional @@ -262,9 +264,12 @@ public class Mean extends AbstractStorelessUnivariateStatistic * * @param source Mean to copy * @param dest Mean to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Mean source, Mean dest) { + public static void copy(Mean source, Mean dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.incMoment = source.incMoment; dest.moment = source.moment.copy(); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SecondMoment.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SecondMoment.java index ade16025a..53cdf3319 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SecondMoment.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SecondMoment.java @@ -18,6 +18,9 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.util.MathUtils; + /** * Computes a statistic related to the Second Central Moment. Specifically, * what is computed is the sum of squared deviations from the sample mean. @@ -114,9 +117,12 @@ public class SecondMoment extends FirstMoment implements Serializable { * * @param source SecondMoment to copy * @param dest SecondMoment to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(SecondMoment source, SecondMoment dest) { + public static void copy(SecondMoment source, SecondMoment dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); FirstMoment.copy(source, dest); dest.m2 = source.m2; } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java index 669f4f074..707a97675 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** *

Computes the semivariance of a set of values with respect to a given cutoff value. @@ -156,9 +157,12 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali * * @param source SemiVariance to copy * @param dest SemiVariance to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(final SemiVariance source, SemiVariance dest) { + public static void copy(final SemiVariance source, SemiVariance dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.biasCorrected = source.biasCorrected; dest.varianceDirection = source.varianceDirection; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java index 24401732e..a33cbbb2c 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java @@ -18,8 +18,10 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Computes the skewness of the available values. @@ -203,9 +205,12 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se * * @param source Skewness to copy * @param dest Skewness to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Skewness source, Skewness dest) { + public static void copy(Skewness source, Skewness dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.moment = new ThirdMoment(source.moment.copy()); dest.incMoment = source.incMoment; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java index 5e6385803..10a23ed1b 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java @@ -18,8 +18,10 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Computes the sample standard deviation. The standard deviation @@ -261,9 +263,12 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic * * @param source StandardDeviation to copy * @param dest StandardDeviation to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(StandardDeviation source, StandardDeviation dest) { + public static void copy(StandardDeviation source, StandardDeviation dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.variance = source.variance.copy(); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/ThirdMoment.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/ThirdMoment.java index 16f829935..7e7c49c8b 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/ThirdMoment.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/ThirdMoment.java @@ -18,6 +18,9 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.util.MathUtils; + /** * Computes a statistic related to the Third Central Moment. Specifically, @@ -128,9 +131,12 @@ public class ThirdMoment extends SecondMoment implements Serializable { * * @param source ThirdMoment to copy * @param dest ThirdMoment to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(ThirdMoment source, ThirdMoment dest) { + public static void copy(ThirdMoment source, ThirdMoment dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); SecondMoment.copy(source, dest); dest.m3 = source.m3; dest.nDevSq = source.nDevSq; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java index 150243fd7..124d266f1 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java @@ -22,6 +22,7 @@ import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.WeightedEvaluation; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** * Computes the variance of the available values. By default, the unbiased @@ -595,13 +596,12 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se * * @param source Variance to copy * @param dest Variance to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Variance source, Variance dest) { - if (source == null || - dest == null) { - throw new NullArgumentException(); - } + public static void copy(Variance source, Variance dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.moment = source.moment.copy(); dest.isBiasCorrected = source.isBiasCorrected; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Max.java b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Max.java index 743611710..c59ed540c 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Max.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Max.java @@ -18,7 +18,9 @@ package org.apache.commons.math.stat.descriptive.rank; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** * Returns the maximum of the available values. @@ -153,9 +155,12 @@ public class Max extends AbstractStorelessUnivariateStatistic implements Seriali * * @param source Max to copy * @param dest Max to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Max source, Max dest) { + public static void copy(Max source, Max dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.value = source.value; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Min.java b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Min.java index 60e00a467..6f5c82d28 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Min.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Min.java @@ -18,7 +18,9 @@ package org.apache.commons.math.stat.descriptive.rank; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** * Returns the minimum of the available values. @@ -153,9 +155,12 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali * * @param source Min to copy * @param dest Min to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Min source, Min dest) { + public static void copy(Min source, Min dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.value = source.value; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java index deaaa450c..c3cd66e0f 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java @@ -19,10 +19,12 @@ package org.apache.commons.math.stat.descriptive.rank; import java.io.Serializable; import java.util.Arrays; +import org.apache.commons.math.exception.NullArgumentException; 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; +import org.apache.commons.math.util.MathUtils; /** * Provides percentile computation. @@ -482,9 +484,12 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa * * @param source Percentile to copy * @param dest Percentile to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Percentile source, Percentile dest) { + public static void copy(Percentile source, Percentile dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); if (source.cachedPivots != null) { System.arraycopy(source.cachedPivots, 0, dest.cachedPivots, 0, source.cachedPivots.length); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java b/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java index 7d7141b5f..bc656d3c4 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java @@ -18,9 +18,11 @@ package org.apache.commons.math.stat.descriptive.summary; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.WeightedEvaluation; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Returns the product of the available values. @@ -210,9 +212,12 @@ public class Product extends AbstractStorelessUnivariateStatistic implements Ser * * @param source Product to copy * @param dest Product to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Product source, Product dest) { + public static void copy(Product source, Product dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.value = source.value; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/summary/Sum.java b/src/main/java/org/apache/commons/math/stat/descriptive/summary/Sum.java index d93d1ed5b..f865f8d82 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/summary/Sum.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/summary/Sum.java @@ -18,7 +18,9 @@ package org.apache.commons.math.stat.descriptive.summary; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** @@ -206,9 +208,12 @@ public class Sum extends AbstractStorelessUnivariateStatistic implements Seriali * * @param source Sum to copy * @param dest Sum to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(Sum source, Sum dest) { + public static void copy(Sum source, Sum dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.value = source.value; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java b/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java index cb1313dbe..8166d289d 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java @@ -18,8 +18,10 @@ package org.apache.commons.math.stat.descriptive.summary; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Returns the sum of the natural logs for this collection of values. @@ -152,9 +154,12 @@ public class SumOfLogs extends AbstractStorelessUnivariateStatistic implements S * * @param source SumOfLogs to copy * @param dest SumOfLogs to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(SumOfLogs source, SumOfLogs dest) { + public static void copy(SumOfLogs source, SumOfLogs dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.value = source.value; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfSquares.java b/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfSquares.java index 535092270..15053c898 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfSquares.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfSquares.java @@ -18,7 +18,9 @@ package org.apache.commons.math.stat.descriptive.summary; import java.io.Serializable; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.MathUtils; /** * Returns the sum of the squares of the available values. @@ -140,9 +142,12 @@ public class SumOfSquares extends AbstractStorelessUnivariateStatistic implement * * @param source SumOfSquares to copy * @param dest SumOfSquares to copy to - * @throws NullPointerException if either source or dest is null + * @throws NullArgumentException if either source or dest is null */ - public static void copy(SumOfSquares source, SumOfSquares dest) { + public static void copy(SumOfSquares source, SumOfSquares dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.n = source.n; dest.value = source.value; diff --git a/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java b/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java index f70a3b91a..090aacd0d 100644 --- a/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java +++ b/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java @@ -19,6 +19,7 @@ package org.apache.commons.math.stat.inference; import org.apache.commons.math.MathException; import org.apache.commons.math.exception.NotPositiveException; import org.apache.commons.math.exception.NotStrictlyPositiveException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.DimensionMismatchException; @@ -27,6 +28,7 @@ import org.apache.commons.math.distribution.ChiSquaredDistribution; import org.apache.commons.math.distribution.ChiSquaredDistributionImpl; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Implements Chi-Square test statistics defined in the @@ -337,10 +339,12 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { * Throws MathIllegalArgumentException if the input array is not rectangular. * * @param in array to be tested - * @throws NullPointerException if input array is null + * @throws NullArgumentException if input array is null * @throws MathIllegalArgumentException if input array is not rectangular */ - private void checkRectangular(long[][] in) { + private void checkRectangular(long[][] in) + throws NullArgumentException { + MathUtils.checkNotNull(in); for (int i = 1; i < in.length; i++) { if (in[i].length != in[0].length) { throw new DimensionMismatchException(LocalizedFormats.DIFFERENT_ROWS_LENGTHS, diff --git a/src/main/java/org/apache/commons/math/util/MathUtils.java b/src/main/java/org/apache/commons/math/util/MathUtils.java index 05ca7b9da..85cb6d26e 100644 --- a/src/main/java/org/apache/commons/math/util/MathUtils.java +++ b/src/main/java/org/apache/commons/math/util/MathUtils.java @@ -2325,7 +2325,8 @@ public final class MathUtils { * @param o Object to be checked. * @throws NullArgumentException if {@code o} is {@code null}. */ - public static void checkNotNull(Object o) { + public static void checkNotNull(Object o) + throws NullArgumentException { if (o == null) { throw new NullArgumentException(); } diff --git a/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java b/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java index 1b222333f..e80f2c012 100644 --- a/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java +++ b/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; /** @@ -277,13 +278,16 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { /** * Copy constructor. Creates a new ResizableDoubleArray that is a deep, * fresh copy of the original. Needs to acquire synchronization lock - * on original. Original may not be null; otherwise a NullPointerException + * on original. Original may not be null; otherwise a {@link NullArgumentException} * is thrown. * * @param original array to copy + * @exception NullArgumentException if original is null * @since 2.0 */ - public ResizableDoubleArray(ResizableDoubleArray original) { + public ResizableDoubleArray(ResizableDoubleArray original) + throws NullArgumentException { + MathUtils.checkNotNull(original); copy(original, this); } @@ -823,16 +827,20 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { *

Obtains synchronization locks on both source and dest * (in that order) before performing the copy.

* - *

Neither source nor dest may be null; otherwise a NullPointerException + *

Neither source nor dest may be null; otherwise a {@link NullArgumentException} * is thrown

* * @param source ResizableDoubleArray to copy * @param dest ResizableArray to replace with a copy of the source array + * @exception NullArgumentException if either source or dest is null * @since 2.0 * */ - public static void copy(ResizableDoubleArray source, ResizableDoubleArray dest) { - synchronized(source) { + public static void copy(ResizableDoubleArray source, ResizableDoubleArray dest) + throws NullArgumentException { + MathUtils.checkNotNull(source); + MathUtils.checkNotNull(dest); + synchronized(source) { synchronized(dest) { dest.initialCapacity = source.initialCapacity; dest.contractionCriteria = source.contractionCriteria; diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 1d52bd93b..8d10be3fc 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -52,6 +52,9 @@ The type attribute can be add,update,fix,remove. If the output is not quite correct, check for invisible trailing spaces! --> + + Replaced NullPointerException by NullArgumentException. + Added a consistent classes hierarchy for Euclidean spaces in dimension 1, 2 and 3. diff --git a/src/test/java/org/apache/commons/math/complex/ComplexTest.java b/src/test/java/org/apache/commons/math/complex/ComplexTest.java index 48da3d47c..3eb6d3eab 100644 --- a/src/test/java/org/apache/commons/math/complex/ComplexTest.java +++ b/src/test/java/org/apache/commons/math/complex/ComplexTest.java @@ -18,6 +18,7 @@ package org.apache.commons.math.complex; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -632,14 +633,9 @@ public class ComplexTest { new Complex(-1, 3).pow(Complex.ZERO), 10e-12); } - @Test + @Test(expected=NullArgumentException.class) public void testpowNull() { - try { - Complex.ONE.pow(null); - Assert.fail("Expecting NullPointerException"); - } catch (NullPointerException ex) { - // expected - } + Complex.ONE.pow(null); } @Test diff --git a/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java b/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java index 2511ce6ec..100d3478b 100644 --- a/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java +++ b/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java @@ -23,6 +23,7 @@ import org.apache.commons.math.TestUtils; import org.apache.commons.math.util.FastMath; import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.NumberIsTooSmallException; @@ -930,8 +931,8 @@ public final class Array2DRowRealMatrixTest { // null try { m.setSubMatrix(null,1,1); - Assert.fail("expecting NullPointerException"); - } catch (NullPointerException e) { + Assert.fail("expecting NullArgumentException"); + } catch (NullArgumentException e) { // expected } Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(); diff --git a/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java b/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java index ab11e3024..15212c3f8 100644 --- a/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java +++ b/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java @@ -27,6 +27,7 @@ import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.fraction.Fraction; import org.apache.commons.math.fraction.FractionField; import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.NotStrictlyPositiveException; @@ -1213,8 +1214,8 @@ public final class BlockFieldMatrixTest { // null try { m.setSubMatrix(null,1,1); - Assert.fail("expecting NullPointerException"); - } catch (NullPointerException e) { + Assert.fail("expecting NullArgumentException"); + } catch (NullArgumentException e) { // expected } diff --git a/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java b/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java index 21d83db33..9099b9971 100644 --- a/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java +++ b/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java @@ -25,6 +25,7 @@ import org.junit.Assert; import org.apache.commons.math.TestUtils; import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.NumberIsTooSmallException; @@ -1113,8 +1114,8 @@ public final class BlockRealMatrixTest { // null try { m.setSubMatrix(null,1,1); - Assert.fail("expecting NullPointerException"); - } catch (NullPointerException e) { + Assert.fail("expecting NullArgumentException"); + } catch (NullArgumentException e) { // expected } diff --git a/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java b/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java index a2a7e5062..ba69bd021 100644 --- a/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java +++ b/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java @@ -20,6 +20,7 @@ import org.junit.Test; import org.junit.Assert; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.NumberIsTooSmallException; @@ -629,8 +630,8 @@ public final class SparseRealMatrixTest { // null try { m.setSubMatrix(null, 1, 1); - Assert.fail("expecting NullPointerException"); - } catch (NullPointerException e) { + Assert.fail("expecting NullArgumentException"); + } catch (NullArgumentException e) { // expected } try { diff --git a/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java b/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java index 058ac8d30..9a2ab369e 100644 --- a/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java +++ b/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import org.apache.commons.math.RetryRunner; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.stat.descriptive.SummaryStatistics; import org.junit.Assert; import org.junit.Before; @@ -184,37 +185,19 @@ public final class EmpiricalDistributionTest { verifySame(empiricalDistribution2, dist2); } - @Test + @Test(expected=NullArgumentException.class) public void testLoadNullDoubleArray() { - EmpiricalDistribution dist = new EmpiricalDistributionImpl(); - try { - dist.load((double[]) null); - Assert.fail("load((double[]) null) expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } + new EmpiricalDistributionImpl().load((double[]) null); } - @Test + @Test(expected=NullArgumentException.class) public void testLoadNullURL() throws Exception { - EmpiricalDistribution dist = new EmpiricalDistributionImpl(); - try { - dist.load((URL) null); - Assert.fail("load((URL) null) expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } + new EmpiricalDistributionImpl().load((URL) null); } - @Test + @Test(expected=NullArgumentException.class) public void testLoadNullFile() throws Exception { - EmpiricalDistribution dist = new EmpiricalDistributionImpl(); - try { - dist.load((File) null); - Assert.fail("load((File) null) expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } + new EmpiricalDistributionImpl().load((File) null); } /**