MATH-1584: Move "MathUtils.check..." functions to associated exception class.
This commit is contained in:
parent
a4c8c52bd2
commit
23c029484f
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<>();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue