MATH-1584: Move "MathUtils.check..." functions to associated exception class.

This commit is contained in:
Gilles Sadowski 2021-05-26 04:22:20 +02:00
parent a4c8c52bd2
commit 23c029484f
60 changed files with 213 additions and 279 deletions

View File

@ -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.UnivariateFunction;
import org.apache.commons.math4.legacy.analysis.solvers.UnivariateSolverUtils; 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.MaxCountExceededException;
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
@ -224,8 +225,7 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte
* @param f the integrand function * @param f the integrand function
* @param lower the min bound for the interval * @param lower the min bound for the interval
* @param upper the upper bound for the interval * @param upper the upper bound for the interval
* @throws org.apache.commons.math4.legacy.exception.NullArgumentException * @throws NullArgumentException if {@code f} is {@code null}.
* if {@code f} is {@code null}.
* @throws org.apache.commons.math4.legacy.exception.MathIllegalArgumentException * @throws org.apache.commons.math4.legacy.exception.MathIllegalArgumentException
* if {@code min >= max}. * if {@code min >= max}.
*/ */
@ -234,7 +234,7 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte
final double lower, final double upper) { final double lower, final double upper) {
// Checks. // Checks.
MathUtils.checkNotNull(f); NullArgumentException.check(f);
UnivariateSolverUtils.verifyInterval(lower, upper); UnivariateSolverUtils.verifyInterval(lower, upper);
// Reset. // Reset.

View File

@ -92,7 +92,7 @@ public class FieldHermiteInterpolator<T extends FieldElement<T>> {
throws ZeroException, MathArithmeticException, throws ZeroException, MathArithmeticException,
DimensionMismatchException, NullArgumentException { DimensionMismatchException, NullArgumentException {
MathUtils.checkNotNull(x); NullArgumentException.check(x);
T factorial = x.getField().getOne(); T factorial = x.getField().getOne();
for (int i = 0; i < value.length; ++i) { for (int i = 0; i < value.length; ++i) {
@ -140,7 +140,7 @@ public class FieldHermiteInterpolator<T extends FieldElement<T>> {
public T[] value(T x) throws NoDataException, NullArgumentException { public T[] value(T x) throws NoDataException, NullArgumentException {
// safety check // safety check
MathUtils.checkNotNull(x); NullArgumentException.check(x);
if (abscissae.isEmpty()) { if (abscissae.isEmpty()) {
throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE);
} }
@ -171,7 +171,7 @@ public class FieldHermiteInterpolator<T extends FieldElement<T>> {
public T[][] derivatives(T x, int order) throws NoDataException, NullArgumentException { public T[][] derivatives(T x, int order) throws NoDataException, NullArgumentException {
// safety check // safety check
MathUtils.checkNotNull(x); NullArgumentException.check(x);
if (abscissae.isEmpty()) { if (abscissae.isEmpty()) {
throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE);
} }

View File

@ -468,7 +468,7 @@ public class LoessInterpolator
*/ */
private static void checkAllFiniteReal(final double[] values) { private static void checkAllFiniteReal(final double[] values) {
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
MathUtils.checkFinite(values[i]); NotFiniteNumberException.check(values[i]);
} }
} }
} }

View File

@ -64,7 +64,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
public PolynomialFunction(double c[]) public PolynomialFunction(double c[])
throws NullArgumentException, NoDataException { throws NullArgumentException, NoDataException {
super(); super();
MathUtils.checkNotNull(c); NullArgumentException.check(c);
int n = c.length; int n = c.length;
if (n == 0) { if (n == 0) {
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); 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) protected static double evaluate(double[] coefficients, double argument)
throws NullArgumentException, NoDataException { throws NullArgumentException, NoDataException {
MathUtils.checkNotNull(coefficients); NullArgumentException.check(coefficients);
int n = coefficients.length; int n = coefficients.length;
if (n == 0) { if (n == 0) {
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
@ -147,7 +147,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
@Override @Override
public DerivativeStructure value(final DerivativeStructure t) public DerivativeStructure value(final DerivativeStructure t)
throws NullArgumentException, NoDataException { throws NullArgumentException, NoDataException {
MathUtils.checkNotNull(coefficients); NullArgumentException.check(coefficients);
int n = coefficients.length; int n = coefficients.length;
if (n == 0) { if (n == 0) {
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
@ -257,7 +257,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
*/ */
protected static double[] differentiate(double[] coefficients) protected static double[] differentiate(double[] coefficients)
throws NullArgumentException, NoDataException { throws NullArgumentException, NoDataException {
MathUtils.checkNotNull(coefficients); NullArgumentException.check(coefficients);
int n = coefficients.length; int n = coefficients.length;
if (n == 0) { if (n == 0) {
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);

View File

@ -233,8 +233,8 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
*/ */
protected static void verifyInputArray(double a[], double c[]) protected static void verifyInputArray(double a[], double c[])
throws NullArgumentException, NoDataException, DimensionMismatchException { throws NullArgumentException, NoDataException, DimensionMismatchException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
MathUtils.checkNotNull(c); NullArgumentException.check(c);
if (a.length == 0 || c.length == 0) { if (a.length == 0 || c.length == 0) {
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
} }

View File

@ -18,10 +18,10 @@
package org.apache.commons.math4.legacy.analysis.solvers; package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction; 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.MaxCountExceededException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
import org.apache.commons.math4.legacy.util.IntegerSequence; 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 * Provide a default implementation for several functions useful to generic
@ -170,15 +170,14 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
* @param max Upper bound for the interval. * @param max Upper bound for the interval.
* @param startValue Start value to use. * @param startValue Start value to use.
* @param maxEval Maximum number of evaluations. * @param maxEval Maximum number of evaluations.
* @throws org.apache.commons.math4.legacy.exception.NullArgumentException * @throws NullArgumentException if {@code f} is {@code null}.
* if {@code f} is {@code null}.
*/ */
protected void setup(int maxEval, protected void setup(int maxEval,
FUNC f, FUNC f,
double min, double max, double min, double max,
double startValue) { double startValue) {
// Checks. // Checks.
MathUtils.checkNotNull(f); NullArgumentException.check(f);
// Reset. // Reset.
searchMin = min; searchMin = min;
@ -285,8 +284,7 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
* *
* @param lower Lower endpoint. * @param lower Lower endpoint.
* @param upper Upper endpoint. * @param upper Upper endpoint.
* @throws org.apache.commons.math4.legacy.exception.NullArgumentException * @throws NullArgumentException if the function has not been set.
* if the function has not been set.
* @throws org.apache.commons.math4.legacy.exception.NoBracketingException * @throws org.apache.commons.math4.legacy.exception.NoBracketingException
* if the function has the same sign at the endpoints. * if the function has the same sign at the endpoints.
*/ */

View File

@ -198,7 +198,7 @@ public class FieldBracketingNthOrderBrentSolver<T extends RealFieldElement<T>>
throws NullArgumentException, NoBracketingException { throws NullArgumentException, NoBracketingException {
// Checks. // Checks.
MathUtils.checkNotNull(f); NullArgumentException.check(f);
// Reset. // Reset.
evaluations = evaluations.withMaximalCount(maxEval).withStart(0); evaluations = evaluations.withMaximalCount(maxEval).withStart(0);

View File

@ -192,7 +192,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution
* @throws ZeroException if URL contains no data * @throws ZeroException if URL contains no data
*/ */
public void load(URL url) throws IOException, NullArgumentException, ZeroException { public void load(URL url) throws IOException, NullArgumentException, ZeroException {
MathUtils.checkNotNull(url); NullArgumentException.check(url);
Charset charset = Charset.forName(FILE_CHARSET); Charset charset = Charset.forName(FILE_CHARSET);
BufferedReader in = BufferedReader in =
new BufferedReader(new InputStreamReader(url.openStream(), charset)); new BufferedReader(new InputStreamReader(url.openStream(), charset));
@ -226,7 +226,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution
* @throws NullArgumentException if file is null * @throws NullArgumentException if file is null
*/ */
public void load(File file) throws IOException, NullArgumentException { public void load(File file) throws IOException, NullArgumentException {
MathUtils.checkNotNull(file); NullArgumentException.check(file);
Charset charset = Charset.forName(FILE_CHARSET); Charset charset = Charset.forName(FILE_CHARSET);
InputStream is = new FileInputStream(file); InputStream is = new FileInputStream(file);
BufferedReader in = new BufferedReader(new InputStreamReader(is, charset)); BufferedReader in = new BufferedReader(new InputStreamReader(is, charset));
@ -333,7 +333,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution
*/ */
ArrayDataAdapter(double[] in) throws NullArgumentException { ArrayDataAdapter(double[] in) throws NullArgumentException {
super(); super();
MathUtils.checkNotNull(in); NullArgumentException.check(in);
inputArray = in; inputArray = in;
} }

View File

@ -51,4 +51,35 @@ public class NotFiniteNumberException extends MathIllegalNumberException {
Object ... args) { Object ... args) {
super(specific, wrong, 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);
}
}
}
} }

View File

@ -81,4 +81,31 @@ public class NullArgumentException extends NullPointerException
return context.getLocalizedMessage(); 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();
}
}
} }

View File

@ -120,14 +120,14 @@ public class KalmanFilter {
throws NullArgumentException, NonSquareMatrixException, DimensionMismatchException, throws NullArgumentException, NonSquareMatrixException, DimensionMismatchException,
MatrixDimensionMismatchException { MatrixDimensionMismatchException {
MathUtils.checkNotNull(process); NullArgumentException.check(process);
MathUtils.checkNotNull(measurement); NullArgumentException.check(measurement);
this.processModel = process; this.processModel = process;
this.measurementModel = measurement; this.measurementModel = measurement;
transitionMatrix = processModel.getStateTransitionMatrix(); transitionMatrix = processModel.getStateTransitionMatrix();
MathUtils.checkNotNull(transitionMatrix); NullArgumentException.check(transitionMatrix);
transitionMatrixT = transitionMatrix.transpose(); transitionMatrixT = transitionMatrix.transpose();
// create an empty matrix if no control matrix was given // create an empty matrix if no control matrix was given
@ -138,16 +138,16 @@ public class KalmanFilter {
} }
measurementMatrix = measurementModel.getMeasurementMatrix(); measurementMatrix = measurementModel.getMeasurementMatrix();
MathUtils.checkNotNull(measurementMatrix); NullArgumentException.check(measurementMatrix);
measurementMatrixT = measurementMatrix.transpose(); measurementMatrixT = measurementMatrix.transpose();
// check that the process and measurement noise matrices are not null // check that the process and measurement noise matrices are not null
// they will be directly accessed from the model as they may change // they will be directly accessed from the model as they may change
// over time // over time
RealMatrix processNoise = processModel.getProcessNoise(); RealMatrix processNoise = processModel.getProcessNoise();
MathUtils.checkNotNull(processNoise); NullArgumentException.check(processNoise);
RealMatrix measNoise = measurementModel.getMeasurementNoise(); RealMatrix measNoise = measurementModel.getMeasurementNoise();
MathUtils.checkNotNull(measNoise); NullArgumentException.check(measNoise);
// set the initial state estimate to a zero vector if it is not // set the initial state estimate to a zero vector if it is not
// available from the process model // available from the process model
@ -349,7 +349,7 @@ public class KalmanFilter {
throws NullArgumentException, DimensionMismatchException, SingularMatrixException { throws NullArgumentException, DimensionMismatchException, SingularMatrixException {
// sanity checks // sanity checks
MathUtils.checkNotNull(z); NullArgumentException.check(z);
if (z.getDimension() != measurementMatrix.getRowDimension()) { if (z.getDimension() != measurementMatrix.getRowDimension()) {
throw new DimensionMismatchException(z.getDimension(), throw new DimensionMismatchException(z.getDimension(),
measurementMatrix.getRowDimension()); measurementMatrix.getRowDimension());

View File

@ -435,7 +435,7 @@ public abstract class AbstractRealMatrix
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, OutOfRangeException, throws NoDataException, OutOfRangeException,
DimensionMismatchException, NullArgumentException { DimensionMismatchException, NullArgumentException {
MathUtils.checkNotNull(subMatrix); NullArgumentException.check(subMatrix);
final int nRows = subMatrix.length; final int nRows = subMatrix.length;
if (nRows == 0) { if (nRows == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);

View File

@ -156,7 +156,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
if (copyArray) { if (copyArray) {
copyIn(d); copyIn(d);
} else { } else {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
final int nRows = d.length; final int nRows = d.length;
if (nRows == 0) { if (nRows == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);

View File

@ -274,7 +274,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
if (column > 0) { if (column > 0) {
throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
} }
MathUtils.checkNotNull(subMatrix); NullArgumentException.check(subMatrix);
final int nRows = subMatrix.length; final int nRows = subMatrix.length;
if (nRows == 0) { if (nRows == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);

View File

@ -98,7 +98,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(T[] d) public ArrayFieldVector(T[] d)
throws NullArgumentException, ZeroException { throws NullArgumentException, ZeroException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
try { try {
field = d[0].getField(); field = d[0].getField();
data = d.clone(); data = d.clone();
@ -117,7 +117,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(Field<T> field, T[] d) public ArrayFieldVector(Field<T> field, T[] d)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
this.field = field; this.field = field;
data = d.clone(); data = d.clone();
} }
@ -145,7 +145,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(T[] d, boolean copyArray) public ArrayFieldVector(T[] d, boolean copyArray)
throws NullArgumentException, ZeroException { throws NullArgumentException, ZeroException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
if (d.length == 0) { if (d.length == 0) {
throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
} }
@ -170,7 +170,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(Field<T> field, T[] d, boolean copyArray) public ArrayFieldVector(Field<T> field, T[] d, boolean copyArray)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
this.field = field; this.field = field;
data = copyArray ? d.clone() : d; data = copyArray ? d.clone() : d;
} }
@ -187,7 +187,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(T[] d, int pos, int size) public ArrayFieldVector(T[] d, int pos, int size)
throws NullArgumentException, NumberIsTooLargeException { throws NullArgumentException, NumberIsTooLargeException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
if (d.length < pos + size) { if (d.length < pos + size) {
throw new NumberIsTooLargeException(pos + size, d.length, true); throw new NumberIsTooLargeException(pos + size, d.length, true);
} }
@ -209,7 +209,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(Field<T> field, T[] d, int pos, int size) public ArrayFieldVector(Field<T> field, T[] d, int pos, int size)
throws NullArgumentException, NumberIsTooLargeException { throws NullArgumentException, NumberIsTooLargeException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
if (d.length < pos + size) { if (d.length < pos + size) {
throw new NumberIsTooLargeException(pos + size, d.length, true); throw new NumberIsTooLargeException(pos + size, d.length, true);
} }
@ -226,7 +226,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(FieldVector<T> v) public ArrayFieldVector(FieldVector<T> v)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(v); NullArgumentException.check(v);
field = v.getField(); field = v.getField();
data = MathArrays.buildArray(field, v.getDimension()); data = MathArrays.buildArray(field, v.getDimension());
for (int i = 0; i < data.length; ++i) { for (int i = 0; i < data.length; ++i) {
@ -242,7 +242,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(ArrayFieldVector<T> v) public ArrayFieldVector(ArrayFieldVector<T> v)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(v); NullArgumentException.check(v);
field = v.getField(); field = v.getField();
data = v.data.clone(); data = v.data.clone();
} }
@ -257,7 +257,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(ArrayFieldVector<T> v, boolean deep) public ArrayFieldVector(ArrayFieldVector<T> v, boolean deep)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(v); NullArgumentException.check(v);
field = v.getField(); field = v.getField();
data = deep ? v.data.clone() : v.data; data = deep ? v.data.clone() : v.data;
} }
@ -273,8 +273,8 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(FieldVector<T> v1, FieldVector<T> v2) public ArrayFieldVector(FieldVector<T> v1, FieldVector<T> v2)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(v1); NullArgumentException.check(v1);
MathUtils.checkNotNull(v2); NullArgumentException.check(v2);
field = v1.getField(); field = v1.getField();
final T[] v1Data = final T[] v1Data =
(v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v1).data : v1.toArray(); (v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v1).data : v1.toArray();
@ -296,8 +296,8 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(FieldVector<T> v1, T[] v2) public ArrayFieldVector(FieldVector<T> v1, T[] v2)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(v1); NullArgumentException.check(v1);
MathUtils.checkNotNull(v2); NullArgumentException.check(v2);
field = v1.getField(); field = v1.getField();
final T[] v1Data = final T[] v1Data =
(v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v1).data : v1.toArray(); (v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v1).data : v1.toArray();
@ -317,8 +317,8 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(T[] v1, FieldVector<T> v2) public ArrayFieldVector(T[] v1, FieldVector<T> v2)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(v1); NullArgumentException.check(v1);
MathUtils.checkNotNull(v2); NullArgumentException.check(v2);
field = v2.getField(); field = v2.getField();
final T[] v2Data = final T[] v2Data =
(v2 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v2).data : v2.toArray(); (v2 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v2).data : v2.toArray();
@ -344,8 +344,8 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(T[] v1, T[] v2) public ArrayFieldVector(T[] v1, T[] v2)
throws NullArgumentException, ZeroException { throws NullArgumentException, ZeroException {
MathUtils.checkNotNull(v1); NullArgumentException.check(v1);
MathUtils.checkNotNull(v2); NullArgumentException.check(v2);
if (v1.length + v2.length == 0) { if (v1.length + v2.length == 0) {
throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
} }
@ -368,8 +368,8 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/ */
public ArrayFieldVector(Field<T> field, T[] v1, T[] v2) public ArrayFieldVector(Field<T> field, T[] v1, T[] v2)
throws NullArgumentException, ZeroException { throws NullArgumentException, ZeroException {
MathUtils.checkNotNull(v1); NullArgumentException.check(v1);
MathUtils.checkNotNull(v2); NullArgumentException.check(v2);
if (v1.length + v2.length == 0) { if (v1.length + v2.length == 0) {
throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
} }
@ -518,7 +518,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
@Override @Override
public FieldVector<T> mapDivide(T d) public FieldVector<T> mapDivide(T d)
throws NullArgumentException, MathArithmeticException { throws NullArgumentException, MathArithmeticException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
T[] out = MathArrays.buildArray(field, data.length); T[] out = MathArrays.buildArray(field, data.length);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
out[i] = data[i].divide(d); out[i] = data[i].divide(d);
@ -530,7 +530,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
@Override @Override
public FieldVector<T> mapDivideToSelf(T d) public FieldVector<T> mapDivideToSelf(T d)
throws NullArgumentException, MathArithmeticException { throws NullArgumentException, MathArithmeticException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = data[i].divide(d); data[i] = data[i].divide(d);
} }

View File

@ -781,7 +781,7 @@ public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
throws DimensionMismatchException, OutOfRangeException, throws DimensionMismatchException, OutOfRangeException,
NoDataException, NullArgumentException { NoDataException, NullArgumentException {
// safety checks // safety checks
MathUtils.checkNotNull(subMatrix); NullArgumentException.check(subMatrix);
final int refLength = subMatrix[0].length; final int refLength = subMatrix[0].length;
if (refLength == 0) { if (refLength == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);

View File

@ -789,7 +789,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable
throws OutOfRangeException, NoDataException, NullArgumentException, throws OutOfRangeException, NoDataException, NullArgumentException,
DimensionMismatchException { DimensionMismatchException {
// safety checks // safety checks
MathUtils.checkNotNull(subMatrix); NullArgumentException.check(subMatrix);
final int refLength = subMatrix[0].length; final int refLength = subMatrix[0].length;
if (refLength == 0) { if (refLength == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);

View File

@ -79,7 +79,7 @@ public class DiagonalMatrix extends AbstractRealMatrix
*/ */
public DiagonalMatrix(final double[] d, final boolean copyArray) public DiagonalMatrix(final double[] d, final boolean copyArray)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
data = copyArray ? d.clone() : d; data = copyArray ? d.clone() : d;
} }

View File

@ -52,7 +52,7 @@ public abstract class IterativeLinearSolver {
*/ */
public IterativeLinearSolver(final IterationManager manager) public IterativeLinearSolver(final IterationManager manager)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(manager); NullArgumentException.check(manager);
this.manager = manager; this.manager = manager;
} }
@ -74,9 +74,9 @@ public abstract class IterativeLinearSolver {
final RealVector b, final RealVector x0) throws final RealVector b, final RealVector x0) throws
NullArgumentException, NonSquareOperatorException, NullArgumentException, NonSquareOperatorException,
DimensionMismatchException { DimensionMismatchException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
MathUtils.checkNotNull(b); NullArgumentException.check(b);
MathUtils.checkNotNull(x0); NullArgumentException.check(x0);
if (a.getRowDimension() != a.getColumnDimension()) { if (a.getRowDimension() != a.getColumnDimension()) {
throw new NonSquareOperatorException(a.getRowDimension(), throw new NonSquareOperatorException(a.getRowDimension(),
a.getColumnDimension()); a.getColumnDimension());
@ -119,7 +119,7 @@ public abstract class IterativeLinearSolver {
public RealVector solve(final RealLinearOperator a, final RealVector b) public RealVector solve(final RealLinearOperator a, final RealVector b)
throws NullArgumentException, NonSquareOperatorException, throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, MaxCountExceededException { DimensionMismatchException, MaxCountExceededException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
x.set(0.); x.set(0.);
return solveInPlace(a, b, x); return solveInPlace(a, b, x);
@ -145,7 +145,7 @@ public abstract class IterativeLinearSolver {
public RealVector solve(RealLinearOperator a, RealVector b, RealVector x0) public RealVector solve(RealLinearOperator a, RealVector b, RealVector x0)
throws NullArgumentException, NonSquareOperatorException, throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, MaxCountExceededException { DimensionMismatchException, MaxCountExceededException {
MathUtils.checkNotNull(x0); NullArgumentException.check(x0);
return solveInPlace(a, b, x0.copy()); return solveInPlace(a, b, x0.copy());
} }

View File

@ -1009,7 +1009,7 @@ public class MatrixUtils {
public static RealMatrix inverse(RealMatrix matrix, double threshold) public static RealMatrix inverse(RealMatrix matrix, double threshold)
throws NullArgumentException, SingularMatrixException, NonSquareMatrixException { throws NullArgumentException, SingularMatrixException, NonSquareMatrixException {
MathUtils.checkNotNull(matrix); NullArgumentException.check(matrix);
if (!matrix.isSquare()) { if (!matrix.isSquare()) {
throw new NonSquareMatrixException(matrix.getRowDimension(), throw new NonSquareMatrixException(matrix.getRowDimension(),

View File

@ -93,7 +93,7 @@ public abstract class PreconditionedIterativeLinearSolver
final RealLinearOperator m, final RealVector b, final RealVector x0) final RealLinearOperator m, final RealVector b, final RealVector x0)
throws NullArgumentException, NonSquareOperatorException, throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, MaxCountExceededException { DimensionMismatchException, MaxCountExceededException {
MathUtils.checkNotNull(x0); NullArgumentException.check(x0);
return solveInPlace(a, m, b, x0.copy()); return solveInPlace(a, m, b, x0.copy());
} }
@ -102,7 +102,7 @@ public abstract class PreconditionedIterativeLinearSolver
public RealVector solve(final RealLinearOperator a, final RealVector b) public RealVector solve(final RealLinearOperator a, final RealVector b)
throws NullArgumentException, NonSquareOperatorException, throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, MaxCountExceededException { DimensionMismatchException, MaxCountExceededException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
x.set(0.); x.set(0.);
return solveInPlace(a, null, b, x); return solveInPlace(a, null, b, x);
@ -114,7 +114,7 @@ public abstract class PreconditionedIterativeLinearSolver
final RealVector x0) final RealVector x0)
throws NullArgumentException, NonSquareOperatorException, throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, MaxCountExceededException { DimensionMismatchException, MaxCountExceededException {
MathUtils.checkNotNull(x0); NullArgumentException.check(x0);
return solveInPlace(a, null, b, x0.copy()); return solveInPlace(a, null, b, x0.copy());
} }
@ -173,7 +173,7 @@ public abstract class PreconditionedIterativeLinearSolver
public RealVector solve(RealLinearOperator a, RealLinearOperator m, public RealVector solve(RealLinearOperator a, RealLinearOperator m,
RealVector b) throws NullArgumentException, NonSquareOperatorException, RealVector b) throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, MaxCountExceededException { DimensionMismatchException, MaxCountExceededException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
return solveInPlace(a, m, b, x); return solveInPlace(a, m, b, x);
} }

View File

@ -115,7 +115,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
* @exception NullArgumentException if values is null * @exception NullArgumentException if values is null
*/ */
public SparseFieldVector(Field<T> field, T[] values) throws NullArgumentException { public SparseFieldVector(Field<T> field, T[] values) throws NullArgumentException {
MathUtils.checkNotNull(values); NullArgumentException.check(values);
this.field = field; this.field = field;
virtualSize = values.length; virtualSize = values.length;
entries = new OpenIntToFieldHashMap<>(field); entries = new OpenIntToFieldHashMap<>(field);
@ -208,7 +208,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
*/ */
@Override @Override
public FieldVector<T> append(T d) throws NullArgumentException { public FieldVector<T> append(T d) throws NullArgumentException {
MathUtils.checkNotNull(d); NullArgumentException.check(d);
FieldVector<T> res = new SparseFieldVector<>(this, 1); FieldVector<T> res = new SparseFieldVector<>(this, 1);
res.setEntry(virtualSize, d); res.setEntry(virtualSize, d);
return res; return res;
@ -434,7 +434,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
*/ */
@Override @Override
public void set(T value) { public void set(T value) {
MathUtils.checkNotNull(value); NullArgumentException.check(value);
for (int i = 0; i < virtualSize; i++) { for (int i = 0; i < virtualSize; i++) {
setEntry(i, value); setEntry(i, value);
} }
@ -445,7 +445,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
*/ */
@Override @Override
public void setEntry(int index, T value) throws NullArgumentException, OutOfRangeException { public void setEntry(int index, T value) throws NullArgumentException, OutOfRangeException {
MathUtils.checkNotNull(value); NullArgumentException.check(value);
checkIndex(index); checkIndex(index);
entries.put(index, value); entries.put(index, value);
} }

View File

@ -917,7 +917,7 @@ public class SymmLQ
DimensionMismatchException, MaxCountExceededException, DimensionMismatchException, MaxCountExceededException,
NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException,
IllConditionedOperatorException { IllConditionedOperatorException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
return solveInPlace(a, m, b, x, false, 0.); return solveInPlace(a, m, b, x, false, 0.);
} }
@ -968,7 +968,7 @@ public class SymmLQ
NonSquareOperatorException, DimensionMismatchException, NonSquareOperatorException, DimensionMismatchException,
MaxCountExceededException, NonSelfAdjointOperatorException, MaxCountExceededException, NonSelfAdjointOperatorException,
NonPositiveDefiniteOperatorException, IllConditionedOperatorException { NonPositiveDefiniteOperatorException, IllConditionedOperatorException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
return solveInPlace(a, m, b, x, goodb, shift); return solveInPlace(a, m, b, x, goodb, shift);
} }
@ -991,7 +991,7 @@ public class SymmLQ
DimensionMismatchException, NonSelfAdjointOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException,
NonPositiveDefiniteOperatorException, IllConditionedOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException,
MaxCountExceededException { MaxCountExceededException {
MathUtils.checkNotNull(x); NullArgumentException.check(x);
return solveInPlace(a, m, b, x.copy(), false, 0.); return solveInPlace(a, m, b, x.copy(), false, 0.);
} }
@ -1007,7 +1007,7 @@ public class SymmLQ
throws NullArgumentException, NonSquareOperatorException, throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, NonSelfAdjointOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException,
IllConditionedOperatorException, MaxCountExceededException { IllConditionedOperatorException, MaxCountExceededException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
x.set(0.); x.set(0.);
return solveInPlace(a, null, b, x, false, 0.); return solveInPlace(a, null, b, x, false, 0.);
@ -1053,7 +1053,7 @@ public class SymmLQ
NonSquareOperatorException, DimensionMismatchException, NonSquareOperatorException, DimensionMismatchException,
NonSelfAdjointOperatorException, IllConditionedOperatorException, NonSelfAdjointOperatorException, IllConditionedOperatorException,
MaxCountExceededException { MaxCountExceededException {
MathUtils.checkNotNull(a); NullArgumentException.check(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension()); final RealVector x = new ArrayRealVector(a.getColumnDimension());
return solveInPlace(a, null, b, x, goodb, shift); return solveInPlace(a, null, b, x, goodb, shift);
} }
@ -1073,7 +1073,7 @@ public class SymmLQ
NonSquareOperatorException, DimensionMismatchException, NonSquareOperatorException, DimensionMismatchException,
NonSelfAdjointOperatorException, IllConditionedOperatorException, NonSelfAdjointOperatorException, IllConditionedOperatorException,
MaxCountExceededException { MaxCountExceededException {
MathUtils.checkNotNull(x); NullArgumentException.check(x);
return solveInPlace(a, null, b, x.copy(), false, 0.); return solveInPlace(a, null, b, x.copy(), false, 0.);
} }

View File

@ -25,10 +25,10 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; 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.exception.NotPositiveException;
import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure;
import org.apache.commons.math4.legacy.ml.distance.EuclideanDistance; 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. * DBSCAN (density-based spatial clustering of applications with noise) algorithm.
@ -130,7 +130,7 @@ public class DBSCANClusterer<T extends Clusterable> extends Clusterer<T> {
@Override @Override
public List<Cluster<T>> cluster(final Collection<T> points) { public List<Cluster<T>> cluster(final Collection<T> points) {
// sanity checks // sanity checks
MathUtils.checkNotNull(points); NullArgumentException.check(points);
final List<Cluster<T>> clusters = new ArrayList<>(); final List<Cluster<T>> clusters = new ArrayList<>();
final Map<Clusterable, PointStatus> visited = new HashMap<>(); final Map<Clusterable, PointStatus> visited = new HashMap<>();

View File

@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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.MathIllegalStateException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.linear.MatrixUtils; 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.rng.UniformRandomProvider;
import org.apache.commons.math4.legacy.util.FastMath; import org.apache.commons.math4.legacy.util.FastMath;
import org.apache.commons.math4.legacy.util.MathArrays; import org.apache.commons.math4.legacy.util.MathArrays;
import org.apache.commons.math4.legacy.util.MathUtils;
/** /**
* Fuzzy K-Means clustering algorithm. * Fuzzy K-Means clustering algorithm.
@ -264,7 +264,7 @@ public class FuzzyKMeansClusterer<T extends Clusterable> extends Clusterer<T> {
@Override @Override
public List<CentroidCluster<T>> cluster(final Collection<T> dataPoints) { public List<CentroidCluster<T>> cluster(final Collection<T> dataPoints) {
// sanity checks // sanity checks
MathUtils.checkNotNull(dataPoints); NullArgumentException.check(dataPoints);
final int size = dataPoints.size(); final int size = dataPoints.size();

View File

@ -17,13 +17,13 @@
package org.apache.commons.math4.legacy.ml.clustering; 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.ConvergenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; 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.DistanceMeasure;
import org.apache.commons.math4.legacy.ml.distance.EuclideanDistance; 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.stat.descriptive.moment.Variance;
import org.apache.commons.math4.legacy.util.MathUtils;
import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.simple.RandomSource;
@ -179,7 +179,7 @@ public class KMeansPlusPlusClusterer<T extends Clusterable> extends Clusterer<T>
@Override @Override
public List<CentroidCluster<T>> cluster(final Collection<T> points) { public List<CentroidCluster<T>> cluster(final Collection<T> points) {
// sanity checks // sanity checks
MathUtils.checkNotNull(points); NullArgumentException.check(points);
// number of clusters has to be smaller or equal the number of data points // number of clusters has to be smaller or equal the number of data points
if (points.size() < numberOfClusters) { if (points.size() < numberOfClusters) {

View File

@ -17,9 +17,9 @@
package org.apache.commons.math4.legacy.ml.clustering; 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.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; 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.math4.legacy.util.Pair;
import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.ListSampler; import org.apache.commons.rng.sampling.ListSampler;
@ -105,7 +105,7 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
@Override @Override
public List<CentroidCluster<T>> cluster(final Collection<T> points) { public List<CentroidCluster<T>> cluster(final Collection<T> points) {
// Sanity check. // Sanity check.
MathUtils.checkNotNull(points); NullArgumentException.check(points);
if (points.size() < getNumberOfClusters()) { if (points.size() < getNumberOfClusters()) {
throw new NumberIsTooSmallException(points.size(), getNumberOfClusters(), false); throw new NumberIsTooSmallException(points.size(), getNumberOfClusters(), false);
} }
@ -228,7 +228,7 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
closestCentroidCluster = centroidCluster; closestCentroidCluster = centroidCluster;
} }
} }
MathUtils.checkNotNull(closestCentroidCluster); NullArgumentException.check(closestCentroidCluster);
closestCentroidCluster.addPoint(point); closestCentroidCluster.addPoint(point);
return minDistance; return minDistance;

View File

@ -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.UnivariateFunction;
import org.apache.commons.math4.legacy.analysis.function.Logit; import org.apache.commons.math4.legacy.analysis.function.Logit;
import org.apache.commons.math4.legacy.analysis.function.Sigmoid; 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.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.util.FastMath; import org.apache.commons.math4.legacy.util.FastMath;
import org.apache.commons.math4.legacy.util.MathUtils;
/** /**
* <p>Adapter for mapping bounded {@link MultivariateFunction} to unbounded ones.</p> * <p>Adapter for mapping bounded {@link MultivariateFunction} to unbounded ones.</p>
@ -98,8 +98,8 @@ public class MultivariateFunctionMappingAdapter
public MultivariateFunctionMappingAdapter(final MultivariateFunction bounded, public MultivariateFunctionMappingAdapter(final MultivariateFunction bounded,
final double[] lower, final double[] upper) { final double[] lower, final double[] upper) {
// safety checks // safety checks
MathUtils.checkNotNull(lower); NullArgumentException.check(lower);
MathUtils.checkNotNull(upper); NullArgumentException.check(upper);
if (lower.length != upper.length) { if (lower.length != upper.length) {
throw new DimensionMismatchException(lower.length, upper.length); throw new DimensionMismatchException(lower.length, upper.length);
} }

View File

@ -17,10 +17,10 @@
package org.apache.commons.math4.legacy.optim.nonlinear.scalar; package org.apache.commons.math4.legacy.optim.nonlinear.scalar;
import org.apache.commons.math4.legacy.analysis.MultivariateFunction; 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.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.util.FastMath; import org.apache.commons.math4.legacy.util.FastMath;
import org.apache.commons.math4.legacy.util.MathUtils;
/** /**
* <p>Adapter extending bounded {@link MultivariateFunction} to an unbouded * <p>Adapter extending bounded {@link MultivariateFunction} to an unbouded
@ -124,9 +124,9 @@ public class MultivariateFunctionPenaltyAdapter
final double offset, final double[] scale) { final double offset, final double[] scale) {
// safety checks // safety checks
MathUtils.checkNotNull(lower); NullArgumentException.check(lower);
MathUtils.checkNotNull(upper); NullArgumentException.check(upper);
MathUtils.checkNotNull(scale); NullArgumentException.check(scale);
if (lower.length != upper.length) { if (lower.length != upper.length) {
throw new DimensionMismatchException(lower.length, upper.length); throw new DimensionMismatchException(lower.length, upper.length);
} }

View File

@ -104,7 +104,7 @@ public class HaltonSequenceGenerator implements RandomVectorGenerator {
public HaltonSequenceGenerator(final int dimension, final int[] bases, final int[] weights) public HaltonSequenceGenerator(final int dimension, final int[] bases, final int[] weights)
throws NullArgumentException, OutOfRangeException, DimensionMismatchException { throws NullArgumentException, OutOfRangeException, DimensionMismatchException {
MathUtils.checkNotNull(bases); NullArgumentException.check(bases);
if (dimension < 1 || dimension > bases.length) { if (dimension < 1 || dimension > bases.length) {
throw new OutOfRangeException(dimension, 1, PRIMES.length); throw new OutOfRangeException(dimension, 1, PRIMES.length);

View File

@ -301,7 +301,7 @@ public class Frequency<T extends Comparable<T>> implements Serializable {
* @since 3.1 * @since 3.1
*/ */
public void merge(final Frequency<T> other) throws NullArgumentException { public void merge(final Frequency<T> other) throws NullArgumentException {
MathUtils.checkNotNull(other, LocalizedFormats.NULL_NOT_ALLOWED); NullArgumentException.check(other, LocalizedFormats.NULL_NOT_ALLOWED);
final Iterator<Map.Entry<T, Long>> iter = other.entrySetIterator(); final Iterator<Map.Entry<T, Long>> iter = other.entrySetIterator();
while (iter.hasNext()) { while (iter.hasNext()) {
@ -320,7 +320,7 @@ public class Frequency<T extends Comparable<T>> implements Serializable {
* @since 3.1 * @since 3.1
*/ */
public void merge(final Collection<Frequency<T>> others) throws NullArgumentException { public void merge(final Collection<Frequency<T>> others) throws NullArgumentException {
MathUtils.checkNotNull(others, LocalizedFormats.NULL_NOT_ALLOWED); NullArgumentException.check(others, LocalizedFormats.NULL_NOT_ALLOWED);
for (final Frequency<T> freq : others) { for (final Frequency<T> freq : others) {
merge(freq); merge(freq);

View File

@ -781,8 +781,8 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
*/ */
public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest) public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
// Copy data and window size // Copy data and window size
dest.eDA = source.eDA.copy(); dest.eDA = source.eDA.copy();
dest.windowSize = source.windowSize; dest.windowSize = source.windowSize;

View File

@ -699,8 +699,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
*/ */
public static void copy(SummaryStatistics source, SummaryStatistics dest) public static void copy(SummaryStatistics source, SummaryStatistics dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.maxImpl = source.maxImpl.copy(); dest.maxImpl = source.maxImpl.copy();
dest.minImpl = source.minImpl.copy(); dest.minImpl = source.minImpl.copy();
dest.sumImpl = source.sumImpl.copy(); dest.sumImpl = source.sumImpl.copy();

View File

@ -181,8 +181,8 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics {
public static void copy(SynchronizedDescriptiveStatistics source, public static void copy(SynchronizedDescriptiveStatistics source,
SynchronizedDescriptiveStatistics dest) SynchronizedDescriptiveStatistics dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
synchronized (source) { synchronized (source) {
synchronized (dest) { synchronized (dest) {
DescriptiveStatistics.copy(source, dest); DescriptiveStatistics.copy(source, dest);

View File

@ -354,8 +354,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
public static void copy(SynchronizedSummaryStatistics source, public static void copy(SynchronizedSummaryStatistics source,
SynchronizedSummaryStatistics dest) SynchronizedSummaryStatistics dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
synchronized (source) { synchronized (source) {
synchronized (dest) { synchronized (dest) {
SummaryStatistics.copy(source, dest); SummaryStatistics.copy(source, dest);

View File

@ -156,8 +156,8 @@ class FirstMoment extends AbstractStorelessUnivariateStatistic
*/ */
public static void copy(FirstMoment source, FirstMoment dest) public static void copy(FirstMoment source, FirstMoment dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.m1 = source.m1; dest.m1 = source.m1;
dest.dev = source.dev; dest.dev = source.dev;

View File

@ -142,8 +142,8 @@ class FourthMoment extends ThirdMoment implements Serializable{
*/ */
public static void copy(FourthMoment source, FourthMoment dest) public static void copy(FourthMoment source, FourthMoment dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
ThirdMoment.copy(source, dest); ThirdMoment.copy(source, dest);
dest.m4 = source.m4; dest.m4 = source.m4;
} }

View File

@ -189,8 +189,8 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
*/ */
public static void copy(GeometricMean source, GeometricMean dest) public static void copy(GeometricMean source, GeometricMean dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.sumOfLogs = source.sumOfLogs.copy(); dest.sumOfLogs = source.sumOfLogs.copy();
} }

View File

@ -217,8 +217,8 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S
*/ */
public static void copy(Kurtosis source, Kurtosis dest) public static void copy(Kurtosis source, Kurtosis dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.moment = source.moment.copy(); dest.moment = source.moment.copy();
dest.incMoment = source.incMoment; dest.incMoment = source.incMoment;
} }

View File

@ -280,8 +280,8 @@ public class Mean extends AbstractStorelessUnivariateStatistic
*/ */
public static void copy(Mean source, Mean dest) public static void copy(Mean source, Mean dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.incMoment = source.incMoment; dest.incMoment = source.incMoment;
dest.moment = source.moment.copy(); dest.moment = source.moment.copy();
} }

View File

@ -123,8 +123,8 @@ public class SecondMoment extends FirstMoment implements Serializable {
*/ */
public static void copy(SecondMoment source, SecondMoment dest) public static void copy(SecondMoment source, SecondMoment dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
FirstMoment.copy(source, dest); FirstMoment.copy(source, dest);
dest.m2 = source.m2; dest.m2 = source.m2;
} }

View File

@ -158,8 +158,8 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
*/ */
public static void copy(final SemiVariance source, SemiVariance dest) public static void copy(final SemiVariance source, SemiVariance dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.biasCorrected = source.biasCorrected; dest.biasCorrected = source.biasCorrected;
dest.varianceDirection = source.varianceDirection; dest.varianceDirection = source.varianceDirection;
} }

View File

@ -219,8 +219,8 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se
*/ */
public static void copy(Skewness source, Skewness dest) public static void copy(Skewness source, Skewness dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.moment = new ThirdMoment(source.moment.copy()); dest.moment = new ThirdMoment(source.moment.copy());
dest.incMoment = source.incMoment; dest.incMoment = source.incMoment;
} }

View File

@ -269,8 +269,8 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
* @throws NullArgumentException if either source or dest is null * @throws NullArgumentException if either source or dest is null
*/ */
public static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException { public static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.variance = source.variance.copy(); dest.variance = source.variance.copy();
} }

View File

@ -138,8 +138,8 @@ class ThirdMoment extends SecondMoment implements Serializable {
*/ */
public static void copy(ThirdMoment source, ThirdMoment dest) public static void copy(ThirdMoment source, ThirdMoment dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
SecondMoment.copy(source, dest); SecondMoment.copy(source, dest);
dest.m3 = source.m3; dest.m3 = source.m3;
dest.nDevSq = source.nDevSq; dest.nDevSq = source.nDevSq;

View File

@ -618,8 +618,8 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
*/ */
public static void copy(Variance source, Variance dest) public static void copy(Variance source, Variance dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.moment = source.moment.copy(); dest.moment = source.moment.copy();
dest.isBiasCorrected = source.isBiasCorrected; dest.isBiasCorrected = source.isBiasCorrected;
dest.incMoment = source.incMoment; dest.incMoment = source.incMoment;

View File

@ -162,8 +162,8 @@ public class Max extends AbstractStorelessUnivariateStatistic implements Seriali
*/ */
public static void copy(Max source, Max dest) public static void copy(Max source, Max dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.value = source.value; dest.value = source.value;
} }

View File

@ -162,8 +162,8 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali
*/ */
public static void copy(Min source, Min dest) public static void copy(Min source, Min dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.value = source.value; dest.value = source.value;
} }

View File

@ -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.analysis.interpolation.UnivariateInterpolator;
import org.apache.commons.math4.legacy.exception.InsufficientDataException; import org.apache.commons.math4.legacy.exception.InsufficientDataException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException; 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.exception.util.LocalizedFormats;
import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic;
import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic;
import org.apache.commons.math4.legacy.util.MathArrays; import org.apache.commons.math4.legacy.util.MathArrays;
import org.apache.commons.math4.legacy.util.MathUtils;
import org.apache.commons.numbers.core.Precision; import org.apache.commons.numbers.core.Precision;
/** /**
@ -341,7 +341,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
* @param theMarkerArray marker array to be used * @param theMarkerArray marker array to be used
*/ */
private Markers(final Marker[] theMarkerArray) { private Markers(final Marker[] theMarkerArray) {
MathUtils.checkNotNull(theMarkerArray); NullArgumentException.check(theMarkerArray);
markerArray = theMarkerArray; markerArray = theMarkerArray;
for (int i = 1; i < PSQUARE_CONSTANT; i++) { for (int i = 1; i < PSQUARE_CONSTANT; i++) {
markerArray[i].previous(markerArray[i - 1]) markerArray[i].previous(markerArray[i - 1])
@ -680,7 +680,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
* @return this instance * @return this instance
*/ */
private Marker previous(final Marker previousMarker) { private Marker previous(final Marker previousMarker) {
MathUtils.checkNotNull(previousMarker); NullArgumentException.check(previousMarker);
this.previous = previousMarker; this.previous = previousMarker;
return this; return this;
} }
@ -693,7 +693,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
* @return this instance * @return this instance
*/ */
private Marker next(final Marker nextMarker) { private Marker next(final Marker nextMarker) {
MathUtils.checkNotNull(nextMarker); NullArgumentException.check(nextMarker);
this.next = nextMarker; this.next = nextMarker;
return this; return this;
} }

View File

@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.BitSet; 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.MathIllegalArgumentException;
import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NotPositiveException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; 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.FastMath;
import org.apache.commons.math4.legacy.util.KthSelector; import org.apache.commons.math4.legacy.util.KthSelector;
import org.apache.commons.math4.legacy.util.MathArrays; 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.MedianOf3PivotingStrategy;
import org.apache.commons.math4.legacy.util.PivotingStrategyInterface; import org.apache.commons.math4.legacy.util.PivotingStrategyInterface;
import org.apache.commons.numbers.core.Precision; import org.apache.commons.numbers.core.Precision;
@ -163,7 +163,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa
* Cannot be {@code null}. * Cannot be {@code null}.
*/ */
public Percentile(final Percentile original) { public Percentile(final Percentile original) {
MathUtils.checkNotNull(original); NullArgumentException.check(original);
estimationType = original.getEstimationType(); estimationType = original.getEstimationType();
nanStrategy = original.getNaNStrategy(); nanStrategy = original.getNaNStrategy();
kthSelector = original.getKthSelector(); kthSelector = original.getKthSelector();
@ -193,9 +193,9 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa
final KthSelector kthSelector) { final KthSelector kthSelector) {
setQuantile(quantile); setQuantile(quantile);
cachedPivots = null; cachedPivots = null;
MathUtils.checkNotNull(estimationType); NullArgumentException.check(estimationType);
MathUtils.checkNotNull(nanStrategy); NullArgumentException.check(nanStrategy);
MathUtils.checkNotNull(kthSelector); NullArgumentException.check(kthSelector);
this.estimationType = estimationType; this.estimationType = estimationType;
this.nanStrategy = nanStrategy; this.nanStrategy = nanStrategy;
this.kthSelector = kthSelector; 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, protected double evaluate(final double[] work, final int[] pivotsHeap, final double p,
final KthSelector selector) { final KthSelector selector) {
MathUtils.checkNotNull(work); NullArgumentException.check(work);
if (p > 100 || p <= 0) { if (p > 100 || p <= 0) {
throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE,
p, 0, 100); p, 0, 100);

View File

@ -222,8 +222,8 @@ public class Product extends AbstractStorelessUnivariateStatistic implements Ser
*/ */
public static void copy(Product source, Product dest) public static void copy(Product source, Product dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.value = source.value; dest.value = source.value;
} }

View File

@ -216,8 +216,8 @@ public class Sum extends AbstractStorelessUnivariateStatistic implements Seriali
*/ */
public static void copy(Sum source, Sum dest) public static void copy(Sum source, Sum dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.value = source.value; dest.value = source.value;
} }

View File

@ -163,8 +163,8 @@ public class SumOfLogs extends AbstractStorelessUnivariateStatistic implements S
*/ */
public static void copy(SumOfLogs source, SumOfLogs dest) public static void copy(SumOfLogs source, SumOfLogs dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.value = source.value; dest.value = source.value;
} }

View File

@ -151,8 +151,8 @@ public class SumOfSquares extends AbstractStorelessUnivariateStatistic implement
*/ */
public static void copy(SumOfSquares source, SumOfSquares dest) public static void copy(SumOfSquares source, SumOfSquares dest)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(source); NullArgumentException.check(source);
MathUtils.checkNotNull(dest); NullArgumentException.check(dest);
dest.n = source.n; dest.n = source.n;
dest.value = source.value; dest.value = source.value;
} }

View File

@ -192,7 +192,7 @@ public class OneWayAnova {
private AnovaStats anovaStats(final Collection<double[]> categoryData) private AnovaStats anovaStats(final Collection<double[]> categoryData)
throws NullArgumentException, DimensionMismatchException { throws NullArgumentException, DimensionMismatchException {
MathUtils.checkNotNull(categoryData); NullArgumentException.check(categoryData);
final Collection<SummaryStatistics> categoryDataSummaryStatistics = final Collection<SummaryStatistics> categoryDataSummaryStatistics =
new ArrayList<>(categoryData.size()); new ArrayList<>(categoryData.size());
@ -275,7 +275,7 @@ public class OneWayAnova {
final boolean allowOneElementData) final boolean allowOneElementData)
throws NullArgumentException, DimensionMismatchException { throws NullArgumentException, DimensionMismatchException {
MathUtils.checkNotNull(categoryData); NullArgumentException.check(categoryData);
if (!allowOneElementData) { if (!allowOneElementData) {
// check if we have enough categories // check if we have enough categories

View File

@ -57,7 +57,7 @@ public class KthSelector implements Serializable {
*/ */
public KthSelector(final PivotingStrategyInterface pivotingStrategy) public KthSelector(final PivotingStrategyInterface pivotingStrategy)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(pivotingStrategy); NullArgumentException.check(pivotingStrategy);
this.pivotingStrategy = pivotingStrategy; this.pivotingStrategy = pivotingStrategy;
} }

View File

@ -545,7 +545,7 @@ public class MathArrays {
*/ */
public static void checkRectangular(final long[][] in) public static void checkRectangular(final long[][] in)
throws NullArgumentException, DimensionMismatchException { throws NullArgumentException, DimensionMismatchException {
MathUtils.checkNotNull(in); NullArgumentException.check(in);
for (int i = 1; i < in.length; i++) { for (int i = 1; i < in.length; i++) {
if (in[i].length != in[0].length) { if (in[i].length != in[0].length) {
throw new DimensionMismatchException( throw new DimensionMismatchException(
@ -993,8 +993,8 @@ public class MathArrays {
public static double[] convolve(double[] x, double[] h) public static double[] convolve(double[] x, double[] h)
throws NullArgumentException, throws NullArgumentException,
NoDataException { NoDataException {
MathUtils.checkNotNull(x); NullArgumentException.check(x);
MathUtils.checkNotNull(h); NullArgumentException.check(h);
final int xLen = x.length; final int xLen = x.length;
final int hLen = h.length; final int hLen = h.length;

View File

@ -54,65 +54,4 @@ public final class MathUtils {
final double p = FastMath.abs(period); final double p = FastMath.abs(period);
return a - p * FastMath.floor((a - offset) / p) - offset; 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();
}
}
} }

View File

@ -278,7 +278,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
initialCapacity); initialCapacity);
} }
checkContractExpand(contractionCriterion, expansionFactor); checkContractExpand(contractionCriterion, expansionFactor);
MathUtils.checkNotNull(expansionMode); NullArgumentException.check(expansionMode);
this.expansionFactor = expansionFactor; this.expansionFactor = expansionFactor;
this.contractionCriterion = contractionCriterion; this.contractionCriterion = contractionCriterion;
@ -304,7 +304,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
*/ */
public ResizableDoubleArray(final ResizableDoubleArray original) public ResizableDoubleArray(final ResizableDoubleArray original)
throws NullArgumentException { throws NullArgumentException {
MathUtils.checkNotNull(original); NullArgumentException.check(original);
this.contractionCriterion = original.contractionCriterion; this.contractionCriterion = original.contractionCriterion;
this.expansionFactor = original.expansionFactor; this.expansionFactor = original.expansionFactor;
this.expansionMode = original.expansionMode; this.expansionMode = original.expansionMode;

View File

@ -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.
}
}
} }