diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/BaseAbstractUnivariateIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/BaseAbstractUnivariateIntegrator.java index 029474911..dc89073ab 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/BaseAbstractUnivariateIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/BaseAbstractUnivariateIntegrator.java @@ -18,6 +18,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.analysis.solvers.UnivariateSolverUtils; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; @@ -224,8 +225,7 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte * @param f the integrand function * @param lower the min bound for the interval * @param upper the upper bound for the interval - * @throws org.apache.commons.math4.legacy.exception.NullArgumentException - * if {@code f} is {@code null}. + * @throws NullArgumentException if {@code f} is {@code null}. * @throws org.apache.commons.math4.legacy.exception.MathIllegalArgumentException * if {@code min >= max}. */ @@ -234,7 +234,7 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte final double lower, final double upper) { // Checks. - MathUtils.checkNotNull(f); + NullArgumentException.check(f); UnivariateSolverUtils.verifyInterval(lower, upper); // Reset. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java index 2dc261927..55db19e8f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java @@ -92,7 +92,7 @@ public class FieldHermiteInterpolator> { throws ZeroException, MathArithmeticException, DimensionMismatchException, NullArgumentException { - MathUtils.checkNotNull(x); + NullArgumentException.check(x); T factorial = x.getField().getOne(); for (int i = 0; i < value.length; ++i) { @@ -140,7 +140,7 @@ public class FieldHermiteInterpolator> { public T[] value(T x) throws NoDataException, NullArgumentException { // safety check - MathUtils.checkNotNull(x); + NullArgumentException.check(x); if (abscissae.isEmpty()) { throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); } @@ -171,7 +171,7 @@ public class FieldHermiteInterpolator> { public T[][] derivatives(T x, int order) throws NoDataException, NullArgumentException { // safety check - MathUtils.checkNotNull(x); + NullArgumentException.check(x); if (abscissae.isEmpty()) { throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java index 8655585db..5ebfc69ed 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java @@ -468,7 +468,7 @@ public class LoessInterpolator */ private static void checkAllFiniteReal(final double[] values) { for (int i = 0; i < values.length; i++) { - MathUtils.checkFinite(values[i]); + NotFiniteNumberException.check(values[i]); } } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java index c7151e393..f99c61e71 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java @@ -64,7 +64,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser public PolynomialFunction(double c[]) throws NullArgumentException, NoDataException { super(); - MathUtils.checkNotNull(c); + NullArgumentException.check(c); int n = c.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); @@ -126,7 +126,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser */ protected static double evaluate(double[] coefficients, double argument) throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(coefficients); + NullArgumentException.check(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); @@ -147,7 +147,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser @Override public DerivativeStructure value(final DerivativeStructure t) throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(coefficients); + NullArgumentException.check(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); @@ -257,7 +257,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser */ protected static double[] differentiate(double[] coefficients) throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(coefficients); + NullArgumentException.check(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionNewtonForm.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionNewtonForm.java index 3ce1a2241..e10bd4233 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionNewtonForm.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionNewtonForm.java @@ -233,8 +233,8 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun */ protected static void verifyInputArray(double a[], double c[]) throws NullArgumentException, NoDataException, DimensionMismatchException { - MathUtils.checkNotNull(a); - MathUtils.checkNotNull(c); + NullArgumentException.check(a); + NullArgumentException.check(c); if (a.length == 0 || c.length == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseAbstractUnivariateSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseAbstractUnivariateSolver.java index a13e87b58..5585beb33 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseAbstractUnivariateSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseAbstractUnivariateSolver.java @@ -18,10 +18,10 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.util.IntegerSequence; -import org.apache.commons.math4.legacy.util.MathUtils; /** * Provide a default implementation for several functions useful to generic @@ -170,15 +170,14 @@ public abstract class BaseAbstractUnivariateSolver> throws NullArgumentException, NoBracketingException { // Checks. - MathUtils.checkNotNull(f); + NullArgumentException.check(f); // Reset. evaluations = evaluations.withMaximalCount(maxEval).withStart(0); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java index c52c4cee1..cc2881b2c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java @@ -192,7 +192,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution * @throws ZeroException if URL contains no data */ public void load(URL url) throws IOException, NullArgumentException, ZeroException { - MathUtils.checkNotNull(url); + NullArgumentException.check(url); Charset charset = Charset.forName(FILE_CHARSET); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), charset)); @@ -226,7 +226,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution * @throws NullArgumentException if file is null */ public void load(File file) throws IOException, NullArgumentException { - MathUtils.checkNotNull(file); + NullArgumentException.check(file); Charset charset = Charset.forName(FILE_CHARSET); InputStream is = new FileInputStream(file); BufferedReader in = new BufferedReader(new InputStreamReader(is, charset)); @@ -333,7 +333,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution */ ArrayDataAdapter(double[] in) throws NullArgumentException { super(); - MathUtils.checkNotNull(in); + NullArgumentException.check(in); inputArray = in; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NotFiniteNumberException.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NotFiniteNumberException.java index dd315a8d3..ea87fec1a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NotFiniteNumberException.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NotFiniteNumberException.java @@ -51,4 +51,35 @@ public class NotFiniteNumberException extends MathIllegalNumberException { Object ... args) { super(specific, wrong, args); } + + /** + * Check that the argument is a real number. + * + * @param x Argument. + * @throws NotFiniteNumberException if {@code x} is not a + * finite real number. + */ + public static void check(final double x) { + if (Double.isInfinite(x) || + Double.isNaN(x)) { + throw new NotFiniteNumberException(x); + } + } + + /** + * Check that all the elements are real numbers. + * + * @param val Arguments. + * @throws NotFiniteNumberException if any values of the array is not a + * finite real number. + */ + public static void check(final double[] val) { + for (int i = 0; i < val.length; i++) { + final double x = val[i]; + if (Double.isInfinite(x) || + Double.isNaN(x)) { + throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i); + } + } + } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NullArgumentException.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NullArgumentException.java index fa9117c2c..2fec3fef9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NullArgumentException.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/exception/NullArgumentException.java @@ -81,4 +81,31 @@ public class NullArgumentException extends NullPointerException return context.getLocalizedMessage(); } + /** + * Checks that an object is not null. + * + * @param o Object to be checked. + * @param pattern Message pattern. + * @param args Arguments to replace the placeholders in {@code pattern}. + * @throws NullArgumentException if {@code o} is {@code null}. + */ + public static void check(Object o, + Localizable pattern, + Object ... args) { + if (o == null) { + throw new NullArgumentException(pattern, args); + } + } + + /** + * Checks that an object is not null. + * + * @param o Object to be checked. + * @throws NullArgumentException if {@code o} is {@code null}. + */ + public static void check(Object o) { + if (o == null) { + throw new NullArgumentException(); + } + } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/filter/KalmanFilter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/filter/KalmanFilter.java index f6a749b9a..b49f869fd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/filter/KalmanFilter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/filter/KalmanFilter.java @@ -120,14 +120,14 @@ public class KalmanFilter { throws NullArgumentException, NonSquareMatrixException, DimensionMismatchException, MatrixDimensionMismatchException { - MathUtils.checkNotNull(process); - MathUtils.checkNotNull(measurement); + NullArgumentException.check(process); + NullArgumentException.check(measurement); this.processModel = process; this.measurementModel = measurement; transitionMatrix = processModel.getStateTransitionMatrix(); - MathUtils.checkNotNull(transitionMatrix); + NullArgumentException.check(transitionMatrix); transitionMatrixT = transitionMatrix.transpose(); // create an empty matrix if no control matrix was given @@ -138,16 +138,16 @@ public class KalmanFilter { } measurementMatrix = measurementModel.getMeasurementMatrix(); - MathUtils.checkNotNull(measurementMatrix); + NullArgumentException.check(measurementMatrix); measurementMatrixT = measurementMatrix.transpose(); // check that the process and measurement noise matrices are not null // they will be directly accessed from the model as they may change // over time RealMatrix processNoise = processModel.getProcessNoise(); - MathUtils.checkNotNull(processNoise); + NullArgumentException.check(processNoise); RealMatrix measNoise = measurementModel.getMeasurementNoise(); - MathUtils.checkNotNull(measNoise); + NullArgumentException.check(measNoise); // set the initial state estimate to a zero vector if it is not // available from the process model @@ -349,7 +349,7 @@ public class KalmanFilter { throws NullArgumentException, DimensionMismatchException, SingularMatrixException { // sanity checks - MathUtils.checkNotNull(z); + NullArgumentException.check(z); if (z.getDimension() != measurementMatrix.getRowDimension()) { throw new DimensionMismatchException(z.getDimension(), measurementMatrix.getRowDimension()); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java index 9719e144f..5b3cef4c0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java @@ -435,7 +435,7 @@ public abstract class AbstractRealMatrix public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws NoDataException, OutOfRangeException, DimensionMismatchException, NullArgumentException { - MathUtils.checkNotNull(subMatrix); + NullArgumentException.check(subMatrix); final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java index 9dcdf4542..b8247db7d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java @@ -156,7 +156,7 @@ public class Array2DRowFieldMatrix> if (copyArray) { copyIn(d); } else { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); final int nRows = d.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowRealMatrix.java index b17effdb2..d4d8cbd50 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowRealMatrix.java @@ -274,7 +274,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ if (column > 0) { throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); } - MathUtils.checkNotNull(subMatrix); + NullArgumentException.check(subMatrix); final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java index c3baa2bf2..b2ff81d50 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java @@ -98,7 +98,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(T[] d) throws NullArgumentException, ZeroException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); try { field = d[0].getField(); data = d.clone(); @@ -117,7 +117,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(Field field, T[] d) throws NullArgumentException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); this.field = field; data = d.clone(); } @@ -145,7 +145,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(T[] d, boolean copyArray) throws NullArgumentException, ZeroException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); if (d.length == 0) { throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } @@ -170,7 +170,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(Field field, T[] d, boolean copyArray) throws NullArgumentException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); this.field = field; data = copyArray ? d.clone() : d; } @@ -187,7 +187,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(T[] d, int pos, int size) throws NullArgumentException, NumberIsTooLargeException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); if (d.length < pos + size) { throw new NumberIsTooLargeException(pos + size, d.length, true); } @@ -209,7 +209,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(Field field, T[] d, int pos, int size) throws NullArgumentException, NumberIsTooLargeException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); if (d.length < pos + size) { throw new NumberIsTooLargeException(pos + size, d.length, true); } @@ -226,7 +226,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(FieldVector v) throws NullArgumentException { - MathUtils.checkNotNull(v); + NullArgumentException.check(v); field = v.getField(); data = MathArrays.buildArray(field, v.getDimension()); for (int i = 0; i < data.length; ++i) { @@ -242,7 +242,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(ArrayFieldVector v) throws NullArgumentException { - MathUtils.checkNotNull(v); + NullArgumentException.check(v); field = v.getField(); data = v.data.clone(); } @@ -257,7 +257,7 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(ArrayFieldVector v, boolean deep) throws NullArgumentException { - MathUtils.checkNotNull(v); + NullArgumentException.check(v); field = v.getField(); data = deep ? v.data.clone() : v.data; } @@ -273,8 +273,8 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(FieldVector v1, FieldVector v2) throws NullArgumentException { - MathUtils.checkNotNull(v1); - MathUtils.checkNotNull(v2); + NullArgumentException.check(v1); + NullArgumentException.check(v2); field = v1.getField(); final T[] v1Data = (v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector) v1).data : v1.toArray(); @@ -296,8 +296,8 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(FieldVector v1, T[] v2) throws NullArgumentException { - MathUtils.checkNotNull(v1); - MathUtils.checkNotNull(v2); + NullArgumentException.check(v1); + NullArgumentException.check(v2); field = v1.getField(); final T[] v1Data = (v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector) v1).data : v1.toArray(); @@ -317,8 +317,8 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(T[] v1, FieldVector v2) throws NullArgumentException { - MathUtils.checkNotNull(v1); - MathUtils.checkNotNull(v2); + NullArgumentException.check(v1); + NullArgumentException.check(v2); field = v2.getField(); final T[] v2Data = (v2 instanceof ArrayFieldVector) ? ((ArrayFieldVector) v2).data : v2.toArray(); @@ -344,8 +344,8 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(T[] v1, T[] v2) throws NullArgumentException, ZeroException { - MathUtils.checkNotNull(v1); - MathUtils.checkNotNull(v2); + NullArgumentException.check(v1); + NullArgumentException.check(v2); if (v1.length + v2.length == 0) { throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } @@ -368,8 +368,8 @@ public class ArrayFieldVector> implements FieldVector< */ public ArrayFieldVector(Field field, T[] v1, T[] v2) throws NullArgumentException, ZeroException { - MathUtils.checkNotNull(v1); - MathUtils.checkNotNull(v2); + NullArgumentException.check(v1); + NullArgumentException.check(v2); if (v1.length + v2.length == 0) { throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } @@ -518,7 +518,7 @@ public class ArrayFieldVector> implements FieldVector< @Override public FieldVector mapDivide(T d) throws NullArgumentException, MathArithmeticException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].divide(d); @@ -530,7 +530,7 @@ public class ArrayFieldVector> implements FieldVector< @Override public FieldVector mapDivideToSelf(T d) throws NullArgumentException, MathArithmeticException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); for (int i = 0; i < data.length; i++) { data[i] = data[i].divide(d); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java index e5641ede7..332731f33 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java @@ -781,7 +781,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa throws DimensionMismatchException, OutOfRangeException, NoDataException, NullArgumentException { // safety checks - MathUtils.checkNotNull(subMatrix); + NullArgumentException.check(subMatrix); final int refLength = subMatrix[0].length; if (refLength == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java index 8adea5181..0fa9a795a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java @@ -789,7 +789,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable throws OutOfRangeException, NoDataException, NullArgumentException, DimensionMismatchException { // safety checks - MathUtils.checkNotNull(subMatrix); + NullArgumentException.check(subMatrix); final int refLength = subMatrix[0].length; if (refLength == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java index 328b3b6d9..e2302d0e7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java @@ -79,7 +79,7 @@ public class DiagonalMatrix extends AbstractRealMatrix */ public DiagonalMatrix(final double[] d, final boolean copyArray) throws NullArgumentException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); data = copyArray ? d.clone() : d; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/IterativeLinearSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/IterativeLinearSolver.java index d926d21e8..6d83cd271 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/IterativeLinearSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/IterativeLinearSolver.java @@ -52,7 +52,7 @@ public abstract class IterativeLinearSolver { */ public IterativeLinearSolver(final IterationManager manager) throws NullArgumentException { - MathUtils.checkNotNull(manager); + NullArgumentException.check(manager); this.manager = manager; } @@ -74,9 +74,9 @@ public abstract class IterativeLinearSolver { final RealVector b, final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException { - MathUtils.checkNotNull(a); - MathUtils.checkNotNull(b); - MathUtils.checkNotNull(x0); + NullArgumentException.check(a); + NullArgumentException.check(b); + NullArgumentException.check(x0); if (a.getRowDimension() != a.getColumnDimension()) { throw new NonSquareOperatorException(a.getRowDimension(), a.getColumnDimension()); @@ -119,7 +119,7 @@ public abstract class IterativeLinearSolver { public RealVector solve(final RealLinearOperator a, final RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); x.set(0.); return solveInPlace(a, b, x); @@ -145,7 +145,7 @@ public abstract class IterativeLinearSolver { public RealVector solve(RealLinearOperator a, RealVector b, RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { - MathUtils.checkNotNull(x0); + NullArgumentException.check(x0); return solveInPlace(a, b, x0.copy()); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java index b56553e8a..d8eb3c5c6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java @@ -1009,7 +1009,7 @@ public class MatrixUtils { public static RealMatrix inverse(RealMatrix matrix, double threshold) throws NullArgumentException, SingularMatrixException, NonSquareMatrixException { - MathUtils.checkNotNull(matrix); + NullArgumentException.check(matrix); if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/PreconditionedIterativeLinearSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/PreconditionedIterativeLinearSolver.java index 553382c48..94d94de07 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/PreconditionedIterativeLinearSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/PreconditionedIterativeLinearSolver.java @@ -93,7 +93,7 @@ public abstract class PreconditionedIterativeLinearSolver final RealLinearOperator m, final RealVector b, final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { - MathUtils.checkNotNull(x0); + NullArgumentException.check(x0); return solveInPlace(a, m, b, x0.copy()); } @@ -102,7 +102,7 @@ public abstract class PreconditionedIterativeLinearSolver public RealVector solve(final RealLinearOperator a, final RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); x.set(0.); return solveInPlace(a, null, b, x); @@ -114,7 +114,7 @@ public abstract class PreconditionedIterativeLinearSolver final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { - MathUtils.checkNotNull(x0); + NullArgumentException.check(x0); return solveInPlace(a, null, b, x0.copy()); } @@ -173,7 +173,7 @@ public abstract class PreconditionedIterativeLinearSolver public RealVector solve(RealLinearOperator a, RealLinearOperator m, RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); return solveInPlace(a, m, b, x); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java index 7cd2b3e1e..051853802 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java @@ -115,7 +115,7 @@ public class SparseFieldVector> implements FieldVector * @exception NullArgumentException if values is null */ public SparseFieldVector(Field field, T[] values) throws NullArgumentException { - MathUtils.checkNotNull(values); + NullArgumentException.check(values); this.field = field; virtualSize = values.length; entries = new OpenIntToFieldHashMap<>(field); @@ -208,7 +208,7 @@ public class SparseFieldVector> implements FieldVector */ @Override public FieldVector append(T d) throws NullArgumentException { - MathUtils.checkNotNull(d); + NullArgumentException.check(d); FieldVector res = new SparseFieldVector<>(this, 1); res.setEntry(virtualSize, d); return res; @@ -434,7 +434,7 @@ public class SparseFieldVector> implements FieldVector */ @Override public void set(T value) { - MathUtils.checkNotNull(value); + NullArgumentException.check(value); for (int i = 0; i < virtualSize; i++) { setEntry(i, value); } @@ -445,7 +445,7 @@ public class SparseFieldVector> implements FieldVector */ @Override public void setEntry(int index, T value) throws NullArgumentException, OutOfRangeException { - MathUtils.checkNotNull(value); + NullArgumentException.check(value); checkIndex(index); entries.put(index, value); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java index 8c4864acb..6e16c1d33 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java @@ -917,7 +917,7 @@ public class SymmLQ DimensionMismatchException, MaxCountExceededException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); return solveInPlace(a, m, b, x, false, 0.); } @@ -968,7 +968,7 @@ public class SymmLQ NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); return solveInPlace(a, m, b, x, goodb, shift); } @@ -991,7 +991,7 @@ public class SymmLQ DimensionMismatchException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException, MaxCountExceededException { - MathUtils.checkNotNull(x); + NullArgumentException.check(x); return solveInPlace(a, m, b, x.copy(), false, 0.); } @@ -1007,7 +1007,7 @@ public class SymmLQ throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); x.set(0.); return solveInPlace(a, null, b, x, false, 0.); @@ -1053,7 +1053,7 @@ public class SymmLQ NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException { - MathUtils.checkNotNull(a); + NullArgumentException.check(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); return solveInPlace(a, null, b, x, goodb, shift); } @@ -1073,7 +1073,7 @@ public class SymmLQ NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException { - MathUtils.checkNotNull(x); + NullArgumentException.check(x); return solveInPlace(a, null, b, x.copy(), false, 0.); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/DBSCANClusterer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/DBSCANClusterer.java index 3e88c0dd1..0687b6ed5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/DBSCANClusterer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/DBSCANClusterer.java @@ -25,10 +25,10 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; import org.apache.commons.math4.legacy.ml.distance.EuclideanDistance; -import org.apache.commons.math4.legacy.util.MathUtils; /** * DBSCAN (density-based spatial clustering of applications with noise) algorithm. @@ -130,7 +130,7 @@ public class DBSCANClusterer extends Clusterer { @Override public List> cluster(final Collection points) { // sanity checks - MathUtils.checkNotNull(points); + NullArgumentException.check(points); final List> clusters = new ArrayList<>(); final Map visited = new HashMap<>(); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java index 7f27065a8..b5cc1b2f1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.MathIllegalStateException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.linear.MatrixUtils; @@ -31,7 +32,6 @@ import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.math4.legacy.util.FastMath; import org.apache.commons.math4.legacy.util.MathArrays; -import org.apache.commons.math4.legacy.util.MathUtils; /** * Fuzzy K-Means clustering algorithm. @@ -264,7 +264,7 @@ public class FuzzyKMeansClusterer extends Clusterer { @Override public List> cluster(final Collection dataPoints) { // sanity checks - MathUtils.checkNotNull(dataPoints); + NullArgumentException.check(dataPoints); final int size = dataPoints.size(); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/KMeansPlusPlusClusterer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/KMeansPlusPlusClusterer.java index 27d93cf91..4fcdda453 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/KMeansPlusPlusClusterer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/KMeansPlusPlusClusterer.java @@ -17,13 +17,13 @@ package org.apache.commons.math4.legacy.ml.clustering; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.ConvergenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; import org.apache.commons.math4.legacy.ml.distance.EuclideanDistance; import org.apache.commons.math4.legacy.stat.descriptive.moment.Variance; -import org.apache.commons.math4.legacy.util.MathUtils; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; @@ -179,7 +179,7 @@ public class KMeansPlusPlusClusterer extends Clusterer @Override public List> cluster(final Collection points) { // sanity checks - MathUtils.checkNotNull(points); + NullArgumentException.check(points); // number of clusters has to be smaller or equal the number of data points if (points.size() < numberOfClusters) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/MiniBatchKMeansClusterer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/MiniBatchKMeansClusterer.java index 6cfba2401..a18b892d9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/MiniBatchKMeansClusterer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/MiniBatchKMeansClusterer.java @@ -17,9 +17,9 @@ package org.apache.commons.math4.legacy.ml.clustering; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; -import org.apache.commons.math4.legacy.util.MathUtils; import org.apache.commons.math4.legacy.util.Pair; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.sampling.ListSampler; @@ -105,7 +105,7 @@ public class MiniBatchKMeansClusterer @Override public List> cluster(final Collection points) { // Sanity check. - MathUtils.checkNotNull(points); + NullArgumentException.check(points); if (points.size() < getNumberOfClusters()) { throw new NumberIsTooSmallException(points.size(), getNumberOfClusters(), false); } @@ -228,7 +228,7 @@ public class MiniBatchKMeansClusterer closestCentroidCluster = centroidCluster; } } - MathUtils.checkNotNull(closestCentroidCluster); + NullArgumentException.check(closestCentroidCluster); closestCentroidCluster.addPoint(point); return minDistance; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java index 092e1ced9..afaff83ab 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java @@ -20,10 +20,10 @@ import org.apache.commons.math4.legacy.analysis.MultivariateFunction; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.analysis.function.Logit; import org.apache.commons.math4.legacy.analysis.function.Sigmoid; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathUtils; /** *

Adapter for mapping bounded {@link MultivariateFunction} to unbounded ones.

@@ -98,8 +98,8 @@ public class MultivariateFunctionMappingAdapter public MultivariateFunctionMappingAdapter(final MultivariateFunction bounded, final double[] lower, final double[] upper) { // safety checks - MathUtils.checkNotNull(lower); - MathUtils.checkNotNull(upper); + NullArgumentException.check(lower); + NullArgumentException.check(upper); if (lower.length != upper.length) { throw new DimensionMismatchException(lower.length, upper.length); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java index f405d8222..6a3e51e48 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java @@ -17,10 +17,10 @@ package org.apache.commons.math4.legacy.optim.nonlinear.scalar; import org.apache.commons.math4.legacy.analysis.MultivariateFunction; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathUtils; /** *

Adapter extending bounded {@link MultivariateFunction} to an unbouded @@ -124,9 +124,9 @@ public class MultivariateFunctionPenaltyAdapter final double offset, final double[] scale) { // safety checks - MathUtils.checkNotNull(lower); - MathUtils.checkNotNull(upper); - MathUtils.checkNotNull(scale); + NullArgumentException.check(lower); + NullArgumentException.check(upper); + NullArgumentException.check(scale); if (lower.length != upper.length) { throw new DimensionMismatchException(lower.length, upper.length); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java index 9510395f2..3671b0524 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java @@ -104,7 +104,7 @@ public class HaltonSequenceGenerator implements RandomVectorGenerator { public HaltonSequenceGenerator(final int dimension, final int[] bases, final int[] weights) throws NullArgumentException, OutOfRangeException, DimensionMismatchException { - MathUtils.checkNotNull(bases); + NullArgumentException.check(bases); if (dimension < 1 || dimension > bases.length) { throw new OutOfRangeException(dimension, 1, PRIMES.length); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/Frequency.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/Frequency.java index 4f2686acc..2719d1273 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/Frequency.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/Frequency.java @@ -301,7 +301,7 @@ public class Frequency> implements Serializable { * @since 3.1 */ public void merge(final Frequency other) throws NullArgumentException { - MathUtils.checkNotNull(other, LocalizedFormats.NULL_NOT_ALLOWED); + NullArgumentException.check(other, LocalizedFormats.NULL_NOT_ALLOWED); final Iterator> iter = other.entrySetIterator(); while (iter.hasNext()) { @@ -320,7 +320,7 @@ public class Frequency> implements Serializable { * @since 3.1 */ public void merge(final Collection> others) throws NullArgumentException { - MathUtils.checkNotNull(others, LocalizedFormats.NULL_NOT_ALLOWED); + NullArgumentException.check(others, LocalizedFormats.NULL_NOT_ALLOWED); for (final Frequency freq : others) { merge(freq); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java index cdb4d82ca..a1abfd48b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java @@ -781,8 +781,8 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { */ public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); // Copy data and window size dest.eDA = source.eDA.copy(); dest.windowSize = source.windowSize; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java index ef817d780..dc53c1e2f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java @@ -699,8 +699,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { */ public static void copy(SummaryStatistics source, SummaryStatistics dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.maxImpl = source.maxImpl.copy(); dest.minImpl = source.minImpl.copy(); dest.sumImpl = source.sumImpl.copy(); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedDescriptiveStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedDescriptiveStatistics.java index 37e3e0d4e..8d31880ce 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedDescriptiveStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedDescriptiveStatistics.java @@ -181,8 +181,8 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics { public static void copy(SynchronizedDescriptiveStatistics source, SynchronizedDescriptiveStatistics dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); synchronized (source) { synchronized (dest) { DescriptiveStatistics.copy(source, dest); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedSummaryStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedSummaryStatistics.java index 39fea7832..f4217518f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedSummaryStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedSummaryStatistics.java @@ -354,8 +354,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics { public static void copy(SynchronizedSummaryStatistics source, SynchronizedSummaryStatistics dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); synchronized (source) { synchronized (dest) { SummaryStatistics.copy(source, dest); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FirstMoment.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FirstMoment.java index d675241ab..90fb0fa79 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FirstMoment.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FirstMoment.java @@ -156,8 +156,8 @@ class FirstMoment extends AbstractStorelessUnivariateStatistic */ public static void copy(FirstMoment source, FirstMoment dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.m1 = source.m1; dest.dev = source.dev; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FourthMoment.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FourthMoment.java index fe4e13e1e..d4ab86db7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FourthMoment.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/FourthMoment.java @@ -142,8 +142,8 @@ class FourthMoment extends ThirdMoment implements Serializable{ */ public static void copy(FourthMoment source, FourthMoment dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); ThirdMoment.copy(source, dest); dest.m4 = source.m4; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java index 5d1cb2377..895b24708 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java @@ -189,8 +189,8 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen */ public static void copy(GeometricMean source, GeometricMean dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.sumOfLogs = source.sumOfLogs.copy(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java index a33b8d975..4d53247e6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java @@ -217,8 +217,8 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S */ public static void copy(Kurtosis source, Kurtosis dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.moment = source.moment.copy(); dest.incMoment = source.incMoment; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java index e7c470287..c5fb2de15 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java @@ -280,8 +280,8 @@ public class Mean extends AbstractStorelessUnivariateStatistic */ public static void copy(Mean source, Mean dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.incMoment = source.incMoment; dest.moment = source.moment.copy(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SecondMoment.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SecondMoment.java index 347b90bc5..12ac49354 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SecondMoment.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SecondMoment.java @@ -123,8 +123,8 @@ public class SecondMoment extends FirstMoment implements Serializable { */ public static void copy(SecondMoment source, SecondMoment dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); FirstMoment.copy(source, dest); dest.m2 = source.m2; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java index 398d415a3..a47cb587b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java @@ -158,8 +158,8 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali */ public static void copy(final SemiVariance source, SemiVariance dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.biasCorrected = source.biasCorrected; dest.varianceDirection = source.varianceDirection; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java index d08b0a998..55d047c2a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java @@ -219,8 +219,8 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se */ public static void copy(Skewness source, Skewness dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.moment = new ThirdMoment(source.moment.copy()); dest.incMoment = source.incMoment; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java index e8078d78a..e98c59375 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java @@ -269,8 +269,8 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic * @throws NullArgumentException if either source or dest is null */ public static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.variance = source.variance.copy(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/ThirdMoment.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/ThirdMoment.java index 7cb4fd4d4..7f647b42d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/ThirdMoment.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/ThirdMoment.java @@ -138,8 +138,8 @@ class ThirdMoment extends SecondMoment implements Serializable { */ public static void copy(ThirdMoment source, ThirdMoment dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); SecondMoment.copy(source, dest); dest.m3 = source.m3; dest.nDevSq = source.nDevSq; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java index 55b940f70..0415f6de3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java @@ -618,8 +618,8 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se */ public static void copy(Variance source, Variance dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.moment = source.moment.copy(); dest.isBiasCorrected = source.isBiasCorrected; dest.incMoment = source.incMoment; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java index 1f89aea23..cda695689 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java @@ -162,8 +162,8 @@ public class Max extends AbstractStorelessUnivariateStatistic implements Seriali */ public static void copy(Max source, Max dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.value = source.value; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java index 11ea26160..7f8f56ef5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java @@ -162,8 +162,8 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali */ public static void copy(Min source, Min dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.value = source.value; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java index c4ea09360..ee06b41b3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java @@ -32,11 +32,11 @@ import org.apache.commons.math4.legacy.analysis.interpolation.NevilleInterpolato import org.apache.commons.math4.legacy.analysis.interpolation.UnivariateInterpolator; import org.apache.commons.math4.legacy.exception.InsufficientDataException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math4.legacy.util.MathArrays; -import org.apache.commons.math4.legacy.util.MathUtils; import org.apache.commons.numbers.core.Precision; /** @@ -341,7 +341,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic * @param theMarkerArray marker array to be used */ private Markers(final Marker[] theMarkerArray) { - MathUtils.checkNotNull(theMarkerArray); + NullArgumentException.check(theMarkerArray); markerArray = theMarkerArray; for (int i = 1; i < PSQUARE_CONSTANT; i++) { markerArray[i].previous(markerArray[i - 1]) @@ -680,7 +680,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic * @return this instance */ private Marker previous(final Marker previousMarker) { - MathUtils.checkNotNull(previousMarker); + NullArgumentException.check(previousMarker); this.previous = previousMarker; return this; } @@ -693,7 +693,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic * @return this instance */ private Marker next(final Marker nextMarker) { - MathUtils.checkNotNull(nextMarker); + NullArgumentException.check(nextMarker); this.next = nextMarker; return this; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java index 24d9c37d4..1beb9373b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Arrays; import java.util.BitSet; +import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; @@ -30,7 +31,6 @@ import org.apache.commons.math4.legacy.stat.ranking.NaNStrategy; import org.apache.commons.math4.legacy.util.FastMath; import org.apache.commons.math4.legacy.util.KthSelector; import org.apache.commons.math4.legacy.util.MathArrays; -import org.apache.commons.math4.legacy.util.MathUtils; import org.apache.commons.math4.legacy.util.MedianOf3PivotingStrategy; import org.apache.commons.math4.legacy.util.PivotingStrategyInterface; import org.apache.commons.numbers.core.Precision; @@ -163,7 +163,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa * Cannot be {@code null}. */ public Percentile(final Percentile original) { - MathUtils.checkNotNull(original); + NullArgumentException.check(original); estimationType = original.getEstimationType(); nanStrategy = original.getNaNStrategy(); kthSelector = original.getKthSelector(); @@ -193,9 +193,9 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa final KthSelector kthSelector) { setQuantile(quantile); cachedPivots = null; - MathUtils.checkNotNull(estimationType); - MathUtils.checkNotNull(nanStrategy); - MathUtils.checkNotNull(kthSelector); + NullArgumentException.check(estimationType); + NullArgumentException.check(nanStrategy); + NullArgumentException.check(kthSelector); this.estimationType = estimationType; this.nanStrategy = nanStrategy; this.kthSelector = kthSelector; @@ -1307,7 +1307,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa */ protected double evaluate(final double[] work, final int[] pivotsHeap, final double p, final KthSelector selector) { - MathUtils.checkNotNull(work); + NullArgumentException.check(work); if (p > 100 || p <= 0) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java index fbbf4ebe6..833186c82 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java @@ -222,8 +222,8 @@ public class Product extends AbstractStorelessUnivariateStatistic implements Ser */ public static void copy(Product source, Product dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.value = source.value; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java index 6fd8e5380..79358929b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java @@ -216,8 +216,8 @@ public class Sum extends AbstractStorelessUnivariateStatistic implements Seriali */ public static void copy(Sum source, Sum dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.value = source.value; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java index 33d94daf1..be1938d25 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java @@ -163,8 +163,8 @@ public class SumOfLogs extends AbstractStorelessUnivariateStatistic implements S */ public static void copy(SumOfLogs source, SumOfLogs dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.value = source.value; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfSquares.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfSquares.java index 77a3f568b..54083f282 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfSquares.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfSquares.java @@ -151,8 +151,8 @@ public class SumOfSquares extends AbstractStorelessUnivariateStatistic implement */ public static void copy(SumOfSquares source, SumOfSquares dest) throws NullArgumentException { - MathUtils.checkNotNull(source); - MathUtils.checkNotNull(dest); + NullArgumentException.check(source); + NullArgumentException.check(dest); dest.n = source.n; dest.value = source.value; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java index a367f986c..b4d41ea87 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java @@ -192,7 +192,7 @@ public class OneWayAnova { private AnovaStats anovaStats(final Collection categoryData) throws NullArgumentException, DimensionMismatchException { - MathUtils.checkNotNull(categoryData); + NullArgumentException.check(categoryData); final Collection categoryDataSummaryStatistics = new ArrayList<>(categoryData.size()); @@ -275,7 +275,7 @@ public class OneWayAnova { final boolean allowOneElementData) throws NullArgumentException, DimensionMismatchException { - MathUtils.checkNotNull(categoryData); + NullArgumentException.check(categoryData); if (!allowOneElementData) { // check if we have enough categories diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/KthSelector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/KthSelector.java index ab21dfed5..5b6138c77 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/KthSelector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/KthSelector.java @@ -57,7 +57,7 @@ public class KthSelector implements Serializable { */ public KthSelector(final PivotingStrategyInterface pivotingStrategy) throws NullArgumentException { - MathUtils.checkNotNull(pivotingStrategy); + NullArgumentException.check(pivotingStrategy); this.pivotingStrategy = pivotingStrategy; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java index e7a1e3ccf..2ab470d4a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java @@ -545,7 +545,7 @@ public class MathArrays { */ public static void checkRectangular(final long[][] in) throws NullArgumentException, DimensionMismatchException { - MathUtils.checkNotNull(in); + NullArgumentException.check(in); for (int i = 1; i < in.length; i++) { if (in[i].length != in[0].length) { throw new DimensionMismatchException( @@ -993,8 +993,8 @@ public class MathArrays { public static double[] convolve(double[] x, double[] h) throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(x); - MathUtils.checkNotNull(h); + NullArgumentException.check(x); + NullArgumentException.check(h); final int xLen = x.length; final int hLen = h.length; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java index 6b771353b..47cf8bfc4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java @@ -54,65 +54,4 @@ public final class MathUtils { final double p = FastMath.abs(period); return a - p * FastMath.floor((a - offset) / p) - offset; } - - /** - * Check that the argument is a real number. - * - * @param x Argument. - * @throws NotFiniteNumberException if {@code x} is not a - * finite real number. - */ - public static void checkFinite(final double x) - throws NotFiniteNumberException { - if (Double.isInfinite(x) || Double.isNaN(x)) { - throw new NotFiniteNumberException(x); - } - } - - /** - * Check that all the elements are real numbers. - * - * @param val Arguments. - * @throws NotFiniteNumberException if any values of the array is not a - * finite real number. - */ - public static void checkFinite(final double[] val) - throws NotFiniteNumberException { - for (int i = 0; i < val.length; i++) { - final double x = val[i]; - if (Double.isInfinite(x) || Double.isNaN(x)) { - throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i); - } - } - } - - /** - * Checks that an object is not null. - * - * @param o Object to be checked. - * @param pattern Message pattern. - * @param args Arguments to replace the placeholders in {@code pattern}. - * @throws NullArgumentException if {@code o} is {@code null}. - */ - public static void checkNotNull(Object o, - Localizable pattern, - Object ... args) - throws NullArgumentException { - if (o == null) { - throw new NullArgumentException(pattern, args); - } - } - - /** - * Checks that an object is not null. - * - * @param o Object to be checked. - * @throws NullArgumentException if {@code o} is {@code null}. - */ - public static void checkNotNull(Object o) - throws NullArgumentException { - if (o == null) { - throw new NullArgumentException(); - } - } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/ResizableDoubleArray.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/ResizableDoubleArray.java index 99eadf8f3..c0036b0f8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/ResizableDoubleArray.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/ResizableDoubleArray.java @@ -278,7 +278,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { initialCapacity); } checkContractExpand(contractionCriterion, expansionFactor); - MathUtils.checkNotNull(expansionMode); + NullArgumentException.check(expansionMode); this.expansionFactor = expansionFactor; this.contractionCriterion = contractionCriterion; @@ -304,7 +304,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { */ public ResizableDoubleArray(final ResizableDoubleArray original) throws NullArgumentException { - MathUtils.checkNotNull(original); + NullArgumentException.check(original); this.contractionCriterion = original.contractionCriterion; this.expansionFactor = original.expansionFactor; this.expansionMode = original.expansionMode; diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java index 91b5d62bd..0cd5dc588 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java @@ -97,65 +97,4 @@ public final class MathUtilsTest { } } } - - @Test - public void testCheckFinite() { - try { - MathUtils.checkFinite(Double.POSITIVE_INFINITY); - Assert.fail("an exception should have been thrown"); - } catch (NotFiniteNumberException e) { - // Expected - } - try { - MathUtils.checkFinite(Double.NEGATIVE_INFINITY); - Assert.fail("an exception should have been thrown"); - } catch (NotFiniteNumberException e) { - // Expected - } - try { - MathUtils.checkFinite(Double.NaN); - Assert.fail("an exception should have been thrown"); - } catch (NotFiniteNumberException e) { - // Expected - } - - try { - MathUtils.checkFinite(new double[] {0, -1, Double.POSITIVE_INFINITY, -2, 3}); - Assert.fail("an exception should have been thrown"); - } catch (NotFiniteNumberException e) { - // Expected - } - try { - MathUtils.checkFinite(new double[] {1, Double.NEGATIVE_INFINITY, -2, 3}); - Assert.fail("an exception should have been thrown"); - } catch (NotFiniteNumberException e) { - // Expected - } - try { - MathUtils.checkFinite(new double[] {4, 3, -1, Double.NaN, -2, 1}); - Assert.fail("an exception should have been thrown"); - } catch (NotFiniteNumberException e) { - // Expected - } - } - - @Test - public void testCheckNotNull1() { - try { - Object obj = null; - MathUtils.checkNotNull(obj); - } catch (NullArgumentException e) { - // Expected. - } - } - - @Test - public void testCheckNotNull2() { - try { - double[] array = null; - MathUtils.checkNotNull(array, LocalizedFormats.INPUT_ARRAY); - } catch (NullArgumentException e) { - // Expected. - } - } }