You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/05/26 02:36:47 UTC
[commons-math] 05/06: MATH-1584: Move "MathUtils.check..."
functions to associated exception class.
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch modularized_master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 23c029484fab88efe274fe409234e572741a876f
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Wed May 26 04:22:20 2021 +0200
MATH-1584: Move "MathUtils.check..." functions to associated exception class.
---
.../BaseAbstractUnivariateIntegrator.java | 6 +--
.../interpolation/FieldHermiteInterpolator.java | 6 +--
.../analysis/interpolation/LoessInterpolator.java | 2 +-
.../analysis/polynomials/PolynomialFunction.java | 8 +--
.../polynomials/PolynomialFunctionNewtonForm.java | 4 +-
.../solvers/BaseAbstractUnivariateSolver.java | 10 ++--
.../FieldBracketingNthOrderBrentSolver.java | 2 +-
.../legacy/distribution/EmpiricalDistribution.java | 6 +--
.../legacy/exception/NotFiniteNumberException.java | 31 +++++++++++
.../legacy/exception/NullArgumentException.java | 27 ++++++++++
.../commons/math4/legacy/filter/KalmanFilter.java | 14 ++---
.../math4/legacy/linear/AbstractRealMatrix.java | 2 +-
.../math4/legacy/linear/Array2DRowFieldMatrix.java | 2 +-
.../math4/legacy/linear/Array2DRowRealMatrix.java | 2 +-
.../math4/legacy/linear/ArrayFieldVector.java | 42 +++++++--------
.../math4/legacy/linear/BlockFieldMatrix.java | 2 +-
.../math4/legacy/linear/BlockRealMatrix.java | 2 +-
.../math4/legacy/linear/DiagonalMatrix.java | 2 +-
.../math4/legacy/linear/IterativeLinearSolver.java | 12 ++---
.../commons/math4/legacy/linear/MatrixUtils.java | 2 +-
.../PreconditionedIterativeLinearSolver.java | 8 +--
.../math4/legacy/linear/SparseFieldVector.java | 8 +--
.../apache/commons/math4/legacy/linear/SymmLQ.java | 12 ++---
.../legacy/ml/clustering/DBSCANClusterer.java | 4 +-
.../legacy/ml/clustering/FuzzyKMeansClusterer.java | 4 +-
.../ml/clustering/KMeansPlusPlusClusterer.java | 4 +-
.../ml/clustering/MiniBatchKMeansClusterer.java | 6 +--
.../scalar/MultivariateFunctionMappingAdapter.java | 6 +--
.../scalar/MultivariateFunctionPenaltyAdapter.java | 8 +--
.../legacy/random/HaltonSequenceGenerator.java | 2 +-
.../commons/math4/legacy/stat/Frequency.java | 4 +-
.../stat/descriptive/DescriptiveStatistics.java | 4 +-
.../legacy/stat/descriptive/SummaryStatistics.java | 4 +-
.../SynchronizedDescriptiveStatistics.java | 4 +-
.../descriptive/SynchronizedSummaryStatistics.java | 4 +-
.../stat/descriptive/moment/FirstMoment.java | 4 +-
.../stat/descriptive/moment/FourthMoment.java | 4 +-
.../stat/descriptive/moment/GeometricMean.java | 4 +-
.../legacy/stat/descriptive/moment/Kurtosis.java | 4 +-
.../math4/legacy/stat/descriptive/moment/Mean.java | 4 +-
.../stat/descriptive/moment/SecondMoment.java | 4 +-
.../stat/descriptive/moment/SemiVariance.java | 4 +-
.../legacy/stat/descriptive/moment/Skewness.java | 4 +-
.../stat/descriptive/moment/StandardDeviation.java | 4 +-
.../stat/descriptive/moment/ThirdMoment.java | 4 +-
.../legacy/stat/descriptive/moment/Variance.java | 4 +-
.../math4/legacy/stat/descriptive/rank/Max.java | 4 +-
.../math4/legacy/stat/descriptive/rank/Min.java | 4 +-
.../stat/descriptive/rank/PSquarePercentile.java | 8 +--
.../legacy/stat/descriptive/rank/Percentile.java | 12 ++---
.../legacy/stat/descriptive/summary/Product.java | 4 +-
.../math4/legacy/stat/descriptive/summary/Sum.java | 4 +-
.../legacy/stat/descriptive/summary/SumOfLogs.java | 4 +-
.../stat/descriptive/summary/SumOfSquares.java | 4 +-
.../math4/legacy/stat/inference/OneWayAnova.java | 4 +-
.../commons/math4/legacy/util/KthSelector.java | 2 +-
.../commons/math4/legacy/util/MathArrays.java | 6 +--
.../commons/math4/legacy/util/MathUtils.java | 61 ----------------------
.../math4/legacy/util/ResizableDoubleArray.java | 4 +-
.../commons/math4/legacy/util/MathUtilsTest.java | 61 ----------------------
60 files changed, 213 insertions(+), 279 deletions(-)
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 0294749..dc89073 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 2dc2619..55db19e 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<T extends FieldElement<T>> {
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<T extends FieldElement<T>> {
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<T extends FieldElement<T>> {
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 8655585..5ebfc69 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 c7151e3..f99c61e 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 3ce1a22..e10bd42 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 a13e87b..5585beb 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<FUNC extends UnivariateFuncti
* @param max Upper bound for the interval.
* @param startValue Start value to use.
* @param maxEval Maximum number of evaluations.
- * @throws org.apache.commons.math4.legacy.exception.NullArgumentException
- * if {@code f} is {@code null}.
+ * @throws NullArgumentException if {@code f} is {@code null}.
*/
protected void setup(int maxEval,
FUNC f,
double min, double max,
double startValue) {
// Checks.
- MathUtils.checkNotNull(f);
+ NullArgumentException.check(f);
// Reset.
searchMin = min;
@@ -285,8 +284,7 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
*
* @param lower Lower endpoint.
* @param upper Upper endpoint.
- * @throws org.apache.commons.math4.legacy.exception.NullArgumentException
- * if the function has not been set.
+ * @throws NullArgumentException if the function has not been set.
* @throws org.apache.commons.math4.legacy.exception.NoBracketingException
* if the function has the same sign at the endpoints.
*/
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
index 5bd6d30..a6cc1ba 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
@@ -198,7 +198,7 @@ public class FieldBracketingNthOrderBrentSolver<T extends RealFieldElement<T>>
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 c52c4ce..cc2881b 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 dd315a8..ea87fec 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 fa9117c..2fec3fe 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 f6a749b..b49f869 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 9719e14..5b3cef4 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 9dcdf45..b8247db 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<T extends FieldElement<T>>
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 b17effd..d4d8cbd 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 c3baa2b..b2ff81d 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<T extends FieldElement<T>> 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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(Field<T> field, T[] d)
throws NullArgumentException {
- MathUtils.checkNotNull(d);
+ NullArgumentException.check(d);
this.field = field;
data = d.clone();
}
@@ -145,7 +145,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> 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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(Field<T> 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<T extends FieldElement<T>> 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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(Field<T> 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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(FieldVector<T> 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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(ArrayFieldVector<T> v)
throws NullArgumentException {
- MathUtils.checkNotNull(v);
+ NullArgumentException.check(v);
field = v.getField();
data = v.data.clone();
}
@@ -257,7 +257,7 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(ArrayFieldVector<T> 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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(FieldVector<T> v1, FieldVector<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<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)
throws NullArgumentException {
- MathUtils.checkNotNull(v1);
- MathUtils.checkNotNull(v2);
+ NullArgumentException.check(v1);
+ NullArgumentException.check(v2);
field = v1.getField();
final T[] v1Data =
(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)
throws NullArgumentException {
- MathUtils.checkNotNull(v1);
- MathUtils.checkNotNull(v2);
+ NullArgumentException.check(v1);
+ NullArgumentException.check(v2);
field = v2.getField();
final T[] v2Data =
(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)
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<T extends FieldElement<T>> implements FieldVector<
*/
public ArrayFieldVector(Field<T> 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<T extends FieldElement<T>> implements FieldVector<
@Override
public FieldVector<T> 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<T extends FieldElement<T>> implements FieldVector<
@Override
public FieldVector<T> 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 e5641ed..332731f 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<T extends FieldElement<T>> 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 8adea51..0fa9a79 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 328b3b6..e2302d0 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 d926d21..6d83cd2 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 b56553e..d8eb3c5 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 553382c..94d94de 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 7cd2b3e..0518538 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<T extends FieldElement<T>> implements FieldVector
* @exception NullArgumentException if values is null
*/
public SparseFieldVector(Field<T> 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<T extends FieldElement<T>> implements FieldVector
*/
@Override
public FieldVector<T> append(T d) throws NullArgumentException {
- MathUtils.checkNotNull(d);
+ NullArgumentException.check(d);
FieldVector<T> res = new SparseFieldVector<>(this, 1);
res.setEntry(virtualSize, d);
return res;
@@ -434,7 +434,7 @@ public class SparseFieldVector<T extends FieldElement<T>> 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<T extends FieldElement<T>> 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 8c4864a..6e16c1d 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 3e88c0d..0687b6e 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<T extends Clusterable> extends Clusterer<T> {
@Override
public List<Cluster<T>> cluster(final Collection<T> points) {
// sanity checks
- MathUtils.checkNotNull(points);
+ NullArgumentException.check(points);
final List<Cluster<T>> clusters = new ArrayList<>();
final Map<Clusterable, PointStatus> 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 7f27065..b5cc1b2 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<T extends Clusterable> extends Clusterer<T> {
@Override
public List<CentroidCluster<T>> cluster(final Collection<T> 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 27d93cf..4fcdda4 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<T extends Clusterable> extends Clusterer<T>
@Override
public List<CentroidCluster<T>> cluster(final Collection<T> 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 6cfba24..a18b892 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<T extends Clusterable>
@Override
public List<CentroidCluster<T>> cluster(final Collection<T> 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<T extends Clusterable>
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 092e1ce..afaff83 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;
/**
* <p>Adapter for mapping bounded {@link MultivariateFunction} to unbounded ones.</p>
@@ -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 f405d82..6a3e51e 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;
/**
* <p>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 9510395..3671b05 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 4f2686a..2719d12 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<T extends Comparable<T>> implements Serializable {
* @since 3.1
*/
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();
while (iter.hasNext()) {
@@ -320,7 +320,7 @@ public class Frequency<T extends Comparable<T>> implements Serializable {
* @since 3.1
*/
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) {
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 cdb4d82..a1abfd4 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 ef817d7..dc53c1e 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 37e3e0d..8d31880 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 39fea78..f421751 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 d675241..90fb0fa 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 fe4e13e..d4ab86d 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 5d1cb23..895b247 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 a33b8d9..4d53247 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 e7c4702..c5fb2de 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 347b90b..12ac493 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 398d415..a47cb58 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 d08b0a9..55d047c 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 e8078d7..e98c593 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 7cb4fd4..7f647b4 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 55b940f..0415f6d 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 1f89aea..cda6956 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 11ea261..7f8f56e 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 c4ea093..ee06b41 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 24d9c37..1beb937 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 fbbf4eb..833186c 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 6fd8e53..7935892 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 33d94da..be1938d 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 77a3f56..54083f2 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 a367f98..b4d41ea 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<double[]> categoryData)
throws NullArgumentException, DimensionMismatchException {
- MathUtils.checkNotNull(categoryData);
+ NullArgumentException.check(categoryData);
final Collection<SummaryStatistics> 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 ab21dfe..5b6138c 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 e7a1e3c..2ab470d 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 6b77135..47cf8bf 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 99eadf8..c0036b0 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 91b5d62..0cd5dc5 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.
- }
- }
}