replaced duplicated strings by a single static string in many classes

this will later allow enabling the MultipleStringLiterals rule in checkstyle
(there are many other duplicated strings, so this cannot be enabled yet, I'll
do another pass on it later on)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@885278 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-11-29 21:47:51 +00:00
parent 9a324dc546
commit 93dbc5a0c3
20 changed files with 292 additions and 180 deletions

View File

@ -31,6 +31,10 @@ public class FunctionEvaluationException extends MathException {
/** Serializable version identifier. */
private static final long serialVersionUID = -4305020489115478365L;
/** Message for failed evaluation. */
private static final String FAILED_EVALUATION_MESSAGE =
"evaluation failed for argument = {0}";
/** Argument causing function evaluation failure */
private double[] argument;
@ -41,7 +45,7 @@ public class FunctionEvaluationException extends MathException {
* @param argument the failing function argument
*/
public FunctionEvaluationException(double argument) {
super("evaluation failed for argument = {0}", argument);
super(FAILED_EVALUATION_MESSAGE, argument);
this.argument = new double[] { argument };
}
@ -53,7 +57,7 @@ public class FunctionEvaluationException extends MathException {
* @since 2.0
*/
public FunctionEvaluationException(double[] argument) {
super("evaluation failed for argument = {0}", new ArrayRealVector(argument));
super(FAILED_EVALUATION_MESSAGE, new ArrayRealVector(argument));
this.argument = argument.clone();
}

View File

@ -43,10 +43,8 @@ public class MessagesResources_fr
{ "cannot raise an integral value to a negative power ({0}^{1})",
"impossible d''\u00e9lever une valeur enti\u00e8re " +
"\u00e0 une puissance n\u00e9gative ({0}^{1})" },
{ "invalid rounding method {0}, valid methods: {1} ({2}), {3} ({4})," +
" {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})",
"m\u00e9thode d''arondi {0} invalide, m\u00e9thodes valides : {1} ({2}), {3} ({4})," +
" {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})" },
{ "invalid rounding method {0}, valid methods: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})",
"m\u00e9thode d''arondi {0} invalide, m\u00e9thodes valides : {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})" },
{ "Cannot normalize to an infinite value",
"impossible de normaliser vers une valeur infinie" },
{ "Cannot normalize to NaN",
@ -225,7 +223,7 @@ public class MessagesResources_fr
// org.apache.commons.math.optimization.direct.DirectSearchOptimizer
{ "simplex must contain at least one point",
"le simplex doit contenir au moins un point" },
{ "equals vertices {0} and {1} in simplex configuration",
{ "equal vertices {0} and {1} in simplex configuration",
"sommets {0} et {1} \u00e9gaux dans la configuration du simplex" },
// org.apache.commons.math.estimation.AbstractEstimation
@ -289,25 +287,17 @@ public class MessagesResources_fr
// org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator
{ "minimal step size ({0,number,0.00E00}) reached, integration needs {1,number,0.00E00}",
"pas minimal ({0,number,0.00E00}) atteint, l''int\u00e9gration n\u00e9cessite {1,number,0.00E00}" },
{ "dimensions mismatch: state vector has dimension {0}," +
" absolute tolerance vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le vecteur d''\u00e9tat ({0})," +
" et le vecteur de tol\u00e9rance absolue ({1})" },
{ "dimensions mismatch: state vector has dimension {0}," +
" relative tolerance vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le vecteur d''\u00e9tat ({0})," +
" et le vecteur de tol\u00e9rance relative ({1})" },
{ "dimensions mismatch: state vector has dimension {0}, absolute tolerance vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le vecteur d''\u00e9tat ({0}), et le vecteur de tol\u00e9rance absolue ({1})" },
{ "dimensions mismatch: state vector has dimension {0}, relative tolerance vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le vecteur d''\u00e9tat ({0}), et le vecteur de tol\u00e9rance relative ({1})" },
// org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator,
// org.apache.commons.math.ode.nonstiff.RungeKuttaIntegrator
{ "dimensions mismatch: ODE problem has dimension {0}," +
" initial state vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0})," +
" et le vecteur d''\u00e9tat initial ({1})" },
{ "dimensions mismatch: ODE problem has dimension {0}," +
" final state vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0})," +
" et le vecteur d''\u00e9tat final ({1})" },
{ "dimensions mismatch: ODE problem has dimension {0}, initial state vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0}), et le vecteur d''\u00e9tat initial ({1})" },
{ "dimensions mismatch: ODE problem has dimension {0}, final state vector has dimension {1}",
"incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0}), et le vecteur d''\u00e9tat final ({1})" },
{ "too small integration interval: length = {0}",
"intervalle d''int\u00e9gration trop petit : {0}" },
@ -392,7 +382,7 @@ public class MessagesResources_fr
// org.apache.commons.math.linear.decomposition.QRDecompositionImpl
// org.apache.commons.math.linear.decomposition.SingularValueDecompositionImpl
{ "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
"dimensions erronn\u00e9es : {0}x{1} \u00e0 la place de {2}x{3}" },
"dimensions incoh\u00e9rentes : {0}x{1} \u00e0 la place de {2}x{3}" },
// org.apache.commons.math.linear.decomposition.CholeskyDecompositionImpl
// org.apache.commons.math.linear.decomposition.EigenDecompositionImpl
@ -402,7 +392,7 @@ public class MessagesResources_fr
// org.apache.commons.math.linear.ArrayRealVector
// org.apache.commons.math.linear.SparseRealVector
{ "vector length mismatch: got {0} but expected {1}",
"dimension de vecteur erronn\u00e9e : {0} \u00e0 la place de {1}" },
"taille de vecteur invalide : {0} au lieu de {1} attendue" },
// org.apache.commons.math.linear.ArrayRealVector
// org.apache.commons.math.linear.ArrayFieldVector
@ -420,10 +410,6 @@ public class MessagesResources_fr
"nombre de lignes invalide : {0} (doit \u00eatre positif)" },
{ "invalid column dimension: {0} (must be positive)",
"nombre de colonnes invalide : {0} (doit \u00eatre positif)" },
{ "vector length mismatch: got {0} but expected {1}",
"taille de vecteur invalide : {0} au lieu de {1} attendue" },
{ "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
"dimensions incoh\u00e9rentes : {0}x{1} \u00e0 la place de {2}x{3}" },
{ "matrix must have at least one row",
"une matrice doit comporter au moins une ligne" },
{ "matrix must have at least one column",
@ -648,11 +634,11 @@ public class MessagesResources_fr
// org.apache.commons.math.stat.descriptive.DescriptiveStatistics
{ "window size must be positive ({0})",
"la taille de la fen\u00eatre doit \u00eatre positive ({0})" },
{ "percentile implementation {0} does not support setQuantile",
"l''implantation de pourcentage {0} ne dispose pas de la m\u00e9thode setQuantile" },
{ "cannot access setQuantile method in percentile implementation {0}",
"acc\u00e8s impossible \u00e0 la m\u00e9thode setQuantile" +
" dans l''implantation de pourcentage {0}" },
{ "percentile implementation {0} does not support {1}",
"l''implantation de pourcentage {0} ne dispose pas de la m\u00e9thode {1}" },
{ "cannot access {0} method in percentile implementation {1}",
"acc\u00e8s impossible \u00e0 la m\u00e9thode {0}" +
" dans l''implantation de pourcentage {1}" },
{ "out of bounds quantile value: {0}, must be in (0, 100]",
"valeur de quantile {0} hors bornes, doit \u00eatre dans l''intervalle ]0, 100]" },
@ -679,11 +665,9 @@ public class MessagesResources_fr
// org.apache.commons.math.stat.descriptive.moment.Kurtosis
{ "statistics constructed from external moments cannot be incremented",
"les statistiques bas\u00e9es sur des moments externes " +
"ne peuvent pas \u00eatre incr\u00e9ment\u00e9es" },
"les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre incr\u00e9ment\u00e9es" },
{ "statistics constructed from external moments cannot be cleared",
"les statistiques bas\u00e9es sur des moments externes " +
"ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
"les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
{ "expected array length = {0}, must be at least 2",

View File

@ -33,8 +33,12 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
*/
public class PolynomialFunction implements DifferentiableUnivariateRealFunction, Serializable {
/** Message for empty coefficients array. */
private static final String EMPTY_ARRAY_MESSAGE =
"empty polynomials coefficients array";
/**
* Serializtion identifier
* Serialization identifier
*/
private static final long serialVersionUID = -7726511984200295583L;
@ -62,7 +66,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
public PolynomialFunction(double c[]) {
super();
if (c.length < 1) {
throw MathRuntimeException.createIllegalArgumentException("empty polynomials coefficients array");
throw MathRuntimeException.createIllegalArgumentException(EMPTY_ARRAY_MESSAGE);
}
int l = c.length;
while ((l > 1) && (c[l - 1] == 0)) {
@ -122,7 +126,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
protected static double evaluate(double[] coefficients, double argument) {
int n = coefficients.length;
if (n < 1) {
throw MathRuntimeException.createIllegalArgumentException("empty polynomials coefficients array");
throw MathRuntimeException.createIllegalArgumentException(EMPTY_ARRAY_MESSAGE);
}
double result = coefficients[n - 1];
for (int j = n -2; j >=0; j--) {
@ -231,7 +235,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
protected static double[] differentiate(double[] coefficients) {
int n = coefficients.length;
if (n < 1) {
throw MathRuntimeException.createIllegalArgumentException("empty polynomials coefficients array");
throw MathRuntimeException.createIllegalArgumentException(EMPTY_ARRAY_MESSAGE);
}
if (n == 1) {
return new double[]{0};

View File

@ -37,6 +37,15 @@ import org.apache.commons.math.complex.Complex;
* @since 1.2
*/
public class LaguerreSolver extends UnivariateRealSolverImpl {
/** Message for non-polynomial function. */
private static final String NON_POLYNOMIAL_FUNCTION_MESSAGE =
"function is not polynomial";
/** Message for non-positive degree. */
private static final String NON_POSITIVE_DEGREE_MESSAGE =
"polynomial degree must be positive: degree={0}";
/** polynomial function to solve.
* @deprecated as of 2.0 the function is not stored anymore in the instance
*/
@ -60,7 +69,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
if (f instanceof PolynomialFunction) {
p = (PolynomialFunction) f;
} else {
throw MathRuntimeException.createIllegalArgumentException("function is not polynomial");
throw MathRuntimeException.createIllegalArgumentException(NON_POLYNOMIAL_FUNCTION_MESSAGE);
}
}
@ -162,7 +171,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
// check function type
if (!(f instanceof PolynomialFunction)) {
throw MathRuntimeException.createIllegalArgumentException("function is not polynomial");
throw MathRuntimeException.createIllegalArgumentException(NON_POLYNOMIAL_FUNCTION_MESSAGE);
}
// check for zeros before verifying bracketing
@ -255,7 +264,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
int iterationCount = 0;
if (n < 1) {
throw MathRuntimeException.createIllegalArgumentException(
"polynomial degree must be positive: degree={0}", n);
NON_POSITIVE_DEGREE_MESSAGE, n);
}
Complex c[] = new Complex[n+1]; // coefficients for deflated polynomial
for (int i = 0; i <= n; i++) {
@ -303,7 +312,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
int n = coefficients.length - 1;
if (n < 1) {
throw MathRuntimeException.createIllegalArgumentException(
"polynomial degree must be positive: degree={0}", n);
NON_POSITIVE_DEGREE_MESSAGE, n);
}
Complex N = new Complex(n, 0.0);
Complex N1 = new Complex(n - 1, 0.0);

View File

@ -27,6 +27,11 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* @version $Revision$ $Date$
*/
public class UnivariateRealSolverUtils {
/** Message for null function.*/
private static final String NULL_FUNCTION_MESSAGE =
"function is null";
/**
* Default constructor.
*/
@ -168,7 +173,7 @@ public class UnivariateRealSolverUtils {
FunctionEvaluationException {
if (function == null) {
throw MathRuntimeException.createIllegalArgumentException("function is null");
throw MathRuntimeException.createIllegalArgumentException(NULL_FUNCTION_MESSAGE);
}
if (maximumIterations <= 0) {
throw MathRuntimeException.createIllegalArgumentException(
@ -225,7 +230,7 @@ public class UnivariateRealSolverUtils {
*/
private static void setup(UnivariateRealFunction f) {
if (f == null) {
throw MathRuntimeException.createIllegalArgumentException("function is null");
throw MathRuntimeException.createIllegalArgumentException(NULL_FUNCTION_MESSAGE);
}
}

View File

@ -32,6 +32,14 @@ import org.apache.commons.math.MathRuntimeException;
public abstract class AbstractIntegerDistribution extends AbstractDistribution
implements IntegerDistribution, Serializable {
/** Message for endpoints in wrong order. */
private static final String WRONG_ORDER_ENDPOINTS_MESSAGE =
"lower endpoint ({0}) must be less than or equal to upper endpoint ({1})";
/** Message for out of range point. */
private static final String OUT_OF_RANGE_POINT =
"{0} out of [{1}, {2}] range";
/** Serializable version identifier */
private static final long serialVersionUID = -1146319659338487221L;
@ -79,8 +87,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
throws MathException {
if (x0 > x1) {
throw MathRuntimeException.createIllegalArgumentException(
"lower endpoint ({0}) must be less than or equal to upper endpoint ({1})",
x0, x1);
WRONG_ORDER_ENDPOINTS_MESSAGE, x0, x1);
}
if (Math.floor(x0) < x0) {
return cumulativeProbability(((int) Math.floor(x0)) + 1,
@ -137,8 +144,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
public double cumulativeProbability(int x0, int x1) throws MathException {
if (x0 > x1) {
throw MathRuntimeException.createIllegalArgumentException(
"lower endpoint ({0}) must be less than or equal to upper endpoint ({1})",
x0, x1);
WRONG_ORDER_ENDPOINTS_MESSAGE, x0, x1);
}
return cumulativeProbability(x1) - cumulativeProbability(x0 - 1);
}
@ -157,7 +163,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
public int inverseCumulativeProbability(final double p) throws MathException{
if (p < 0.0 || p > 1.0) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} out of [{1}, {2}] range", p, 0.0, 1.0);
OUT_OF_RANGE_POINT, p, 0.0, 1.0);
}
// by default, do simple bisection.

View File

@ -32,6 +32,10 @@ public class FDistributionImpl
extends AbstractContinuousDistribution
implements FDistribution, Serializable {
/** Message for non positive degrees of freddom. */
private static final String NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE =
"degrees of freedom must be positive ({0})";
/** Serializable version identifier */
private static final long serialVersionUID = -8516354193418641566L;
@ -164,8 +168,7 @@ public class FDistributionImpl
public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
"degrees of freedom must be positive ({0})",
degreesOfFreedom);
NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE, degreesOfFreedom);
}
this.numeratorDegreesOfFreedom = degreesOfFreedom;
}
@ -187,8 +190,7 @@ public class FDistributionImpl
public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
"degrees of freedom must be positive ({0})",
degreesOfFreedom);
NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE, degreesOfFreedom);
}
this.denominatorDegreesOfFreedom = degreesOfFreedom;
}

View File

@ -80,6 +80,10 @@ public class BigFraction
/** Serializable version identifier. */
private static final long serialVersionUID = -5630213147331578515L;
/** Message for zero denominator. */
private static final String FORBIDDEN_ZERO_DENOMINATOR =
"denominator must be different from 0";
/** <code>BigInteger</code> representation of 100. */
private static final BigInteger ONE_HUNDRED_DOUBLE = BigInteger.valueOf(100);
@ -125,7 +129,7 @@ public class BigFraction
throw MathRuntimeException.createNullPointerException("denominator is null");
}
if (BigInteger.ZERO.equals(den)) {
throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
}
if (BigInteger.ZERO.equals(num)) {
numerator = BigInteger.ZERO;
@ -615,7 +619,7 @@ public class BigFraction
*/
public BigFraction divide(final BigInteger bg) {
if (BigInteger.ZERO.equals(bg)) {
throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
}
return new BigFraction(numerator, denominator.multiply(bg));
}
@ -668,7 +672,7 @@ public class BigFraction
*/
public BigFraction divide(final BigFraction fraction) {
if (BigInteger.ZERO.equals(fraction.numerator)) {
throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
}
return multiply(fraction.reciprocal());

View File

@ -77,6 +77,18 @@ public class Fraction
/** A fraction representing "-1 / 1". */
public static final Fraction MINUS_ONE = new Fraction(-1, 1);
/** Message for zero denominator. */
private static final String ZERO_DENOMINATOR_MESSAGE =
"zero denominator in fraction {0}/{1}";
/** Message for overflow. */
private static final String OVERFLOW_MESSAGE =
"overflow in fraction {0}/{1}, cannot negate";
/** Message for null fraction. */
private static final String NULL_FRACTION =
"null fraction";
/** Serializable version identifier */
private static final long serialVersionUID = 3698073679419233275L;
@ -252,13 +264,13 @@ public class Fraction
*/
public Fraction(int num, int den) {
if (den == 0) {
throw MathRuntimeException.createArithmeticException("zero denominator in fraction {0}/{1}",
num, den);
throw MathRuntimeException.createArithmeticException(
ZERO_DENOMINATOR_MESSAGE, num, den);
}
if (den < 0) {
if (num == Integer.MIN_VALUE || den == Integer.MIN_VALUE) {
throw MathRuntimeException.createArithmeticException("overflow in fraction {0}/{1}, cannot negate",
num, den);
throw MathRuntimeException.createArithmeticException(
OVERFLOW_MESSAGE, num, den);
}
num = -num;
den = -den;
@ -409,8 +421,8 @@ public class Fraction
*/
public Fraction negate() {
if (numerator==Integer.MIN_VALUE) {
throw MathRuntimeException.createArithmeticException("overflow in fraction {0}/{1}, cannot negate",
numerator, denominator);
throw MathRuntimeException.createArithmeticException(
OVERFLOW_MESSAGE, numerator, denominator);
}
return new Fraction(-numerator, denominator);
}
@ -481,7 +493,7 @@ public class Fraction
*/
private Fraction addSub(Fraction fraction, boolean isAdd) {
if (fraction == null) {
throw MathRuntimeException.createIllegalArgumentException("null fraction");
throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION);
}
// zero is identity for addition.
if (numerator == 0) {
@ -538,7 +550,7 @@ public class Fraction
*/
public Fraction multiply(Fraction fraction) {
if (fraction == null) {
throw MathRuntimeException.createIllegalArgumentException("null fraction");
throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION);
}
if (numerator == 0 || fraction.numerator == 0) {
return ZERO;
@ -573,7 +585,7 @@ public class Fraction
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
throw MathRuntimeException.createIllegalArgumentException("null fraction");
throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION);
}
if (fraction.numerator == 0) {
throw MathRuntimeException.createArithmeticException(
@ -606,8 +618,7 @@ public class Fraction
public static Fraction getReducedFraction(int numerator, int denominator) {
if (denominator == 0) {
throw MathRuntimeException.createArithmeticException(
"zero denominator in fraction {0}/{1}",
numerator, denominator);
ZERO_DENOMINATOR_MESSAGE, numerator, denominator);
}
if (numerator==0) {
return ZERO; // normalize zero.
@ -620,8 +631,7 @@ public class Fraction
if (numerator==Integer.MIN_VALUE ||
denominator==Integer.MIN_VALUE) {
throw MathRuntimeException.createArithmeticException(
"overflow in fraction {0}/{1}, cannot negate",
numerator, denominator);
OVERFLOW_MESSAGE, numerator, denominator);
}
numerator = -numerator;
denominator = -denominator;

View File

@ -39,6 +39,26 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
/** Serializable version identifier */
private static final long serialVersionUID = 7260756672015356458L;
/** Message for at least one row. */
private static final String AT_LEAST_ONE_ROW_MESSAGE =
"matrix must have at least one row";
/** Message for at least one column. */
private static final String AT_LEAST_ONE_COLUMN_MESSAGE =
"matrix must have at least one column";
/** Message for different rows lengths. */
private static final String DIFFERENT_ROWS_LENGTHS_MESSAGE =
"some rows have length {0} while others have length {1}";
/** Message for no entry at selected indices. */
private static final String NO_ENTRY_MESSAGE =
"no entry at indices ({0}, {1}) in a {2}x{3} matrix";
/** Message for vector lengths mismatch. */
private static final String VECTOR_LENGTHS_MISMATCH =
"vector length mismatch: got {0} but expected {1}";
/** Entries of the matrix */
protected T[][] data;
@ -111,17 +131,18 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
}
final int nRows = d.length;
if (nRows == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_ROW_MESSAGE);
}
final int nCols = d[0].length;
if (nCols == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_COLUMN_MESSAGE);
}
for (int r = 1; r < nRows; r++) {
if (d[r].length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"some rows have length {0} while others have length {1}",
nCols, d[r].length);
DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, d[r].length);
}
}
data = d;
@ -306,29 +327,28 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
if (data == null) {
if (row > 0) {
throw MathRuntimeException.createIllegalStateException(
"first {0} rows are not initialized yet",
row);
"first {0} rows are not initialized yet", row);
}
if (column > 0) {
throw MathRuntimeException.createIllegalStateException(
"first {0} columns are not initialized yet",
column);
"first {0} columns are not initialized yet", column);
}
final int nRows = subMatrix.length;
if (nRows == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_ROW_MESSAGE);
}
final int nCols = subMatrix[0].length;
if (nCols == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_COLUMN_MESSAGE);
}
data = buildArray(getField(), subMatrix.length, nCols);
for (int i = 0; i < data.length; ++i) {
if (subMatrix[i].length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"some rows have length {0} while others have length {1}",
nCols, subMatrix[i].length);
DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, subMatrix[i].length);
}
System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
}
@ -346,8 +366,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
return data[row][column];
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -359,8 +378,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
data[row][column] = value;
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -372,8 +390,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
data[row][column] = data[row][column].add(increment);
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -385,8 +402,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
data[row][column] = data[row][column].multiply(factor);
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -410,8 +426,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
final int nCols = this.getColumnDimension();
if (v.length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
v.length, nCols);
VECTOR_LENGTHS_MISMATCH, v.length, nCols);
}
final T[] out = buildArray(getField(), nRows);
for (int row = 0; row < nRows; row++) {
@ -434,8 +449,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
final int nCols = getColumnDimension();
if (v.length != nRows) {
throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
v.length, nRows);
VECTOR_LENGTHS_MISMATCH, v.length, nRows);
}
final T[] out = buildArray(getField(), nCols);

View File

@ -54,6 +54,26 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** Serializable version identifier */
private static final long serialVersionUID = -1067294169172445528L;
/** Message for at least one row. */
private static final String AT_LEAST_ONE_ROW_MESSAGE =
"matrix must have at least one row";
/** Message for at least one column. */
private static final String AT_LEAST_ONE_COLUMN_MESSAGE =
"matrix must have at least one column";
/** Message for different rows lengths. */
private static final String DIFFERENT_ROWS_LENGTHS_MESSAGE =
"some rows have length {0} while others have length {1}";
/** Message for no entry at selected indices. */
private static final String NO_ENTRY_MESSAGE =
"no entry at indices ({0}, {1}) in a {2}x{3} matrix";
/** Message for vector lengths mismatch. */
private static final String VECTOR_LENGTHS_MISMATCH =
"vector length mismatch: got {0} but expected {1}";
/** Entries of the matrix */
protected double data[][];
@ -120,17 +140,18 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
}
final int nRows = d.length;
if (nRows == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_ROW_MESSAGE);
}
final int nCols = d[0].length;
if (nCols == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_COLUMN_MESSAGE);
}
for (int r = 1; r < nRows; r++) {
if (d[r].length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"some rows have length {0} while others have length {1}",
nCols, d[r].length);
DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, d[r].length);
}
}
data = d;
@ -314,29 +335,28 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
if (data == null) {
if (row > 0) {
throw MathRuntimeException.createIllegalStateException(
"first {0} rows are not initialized yet",
row);
"first {0} rows are not initialized yet", row);
}
if (column > 0) {
throw MathRuntimeException.createIllegalStateException(
"first {0} columns are not initialized yet",
column);
"first {0} columns are not initialized yet", column);
}
final int nRows = subMatrix.length;
if (nRows == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_ROW_MESSAGE);
}
final int nCols = subMatrix[0].length;
if (nCols == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
throw MathRuntimeException.createIllegalArgumentException(
AT_LEAST_ONE_COLUMN_MESSAGE);
}
data = new double[subMatrix.length][nCols];
for (int i = 0; i < data.length; ++i) {
if (subMatrix[i].length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"some rows have length {0} while others have length {1}",
nCols, subMatrix[i].length);
DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, subMatrix[i].length);
}
System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
}
@ -354,8 +374,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
return data[row][column];
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -367,8 +386,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
data[row][column] = value;
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -380,8 +398,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
data[row][column] += increment;
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -393,8 +410,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
data[row][column] *= factor;
} catch (ArrayIndexOutOfBoundsException e) {
throw new MatrixIndexException(
"no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, getRowDimension(), getColumnDimension());
NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension());
}
}
@ -418,8 +434,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
final int nCols = this.getColumnDimension();
if (v.length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
v.length, nCols);
VECTOR_LENGTHS_MISMATCH, v.length, nCols);
}
final double[] out = new double[nRows];
for (int row = 0; row < nRows; row++) {
@ -442,8 +457,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
final int nCols = getColumnDimension();
if (v.length != nRows) {
throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
v.length, nRows);
VECTOR_LENGTHS_MISMATCH, v.length, nRows);
}
final double[] out = new double[nCols];

View File

@ -29,6 +29,10 @@ import org.apache.commons.math.util.MathUtils;
*/
public class ArrayRealVector implements RealVector, Serializable {
/** Message for non fitting position and size. */
private static final String NON_FITTING_POSITION_AND_SIZE_MESSAGE =
"position {0} and size {1} don't fit to the size of the input array {2}";
/** Serializable version identifier. */
private static final long serialVersionUID = -1097961340710804027L;
@ -112,8 +116,7 @@ public class ArrayRealVector implements RealVector, Serializable {
public ArrayRealVector(double[] d, int pos, int size) {
if (d.length < pos + size) {
throw MathRuntimeException.createIllegalArgumentException(
"position {0} and size {1} don't fit to the size of the input array {2}",
pos, size, d.length);
NON_FITTING_POSITION_AND_SIZE_MESSAGE, pos, size, d.length);
}
data = new double[size];
System.arraycopy(d, pos, data, 0, size);
@ -139,8 +142,7 @@ public class ArrayRealVector implements RealVector, Serializable {
public ArrayRealVector(Double[] d, int pos, int size) {
if (d.length < pos + size) {
throw MathRuntimeException.createIllegalArgumentException(
"position {0} and size {1} don't fit to the size of the input array {2}",
pos, size, d.length);
NON_FITTING_POSITION_AND_SIZE_MESSAGE, pos, size, d.length);
}
data = new double[size];
for (int i = pos; i < pos + size; i++) {

View File

@ -36,6 +36,10 @@ public class LUDecompositionImpl implements LUDecomposition {
/** Default bound to determine effective singularity in LU decomposition */
private static final double DEFAULT_TOO_SMALL = 10E-12;
/** Message for vector length mismatch. */
private static final String VECTOR_LENGTH_MISMATCH_MESSAGE =
"vector length mismatch: got {0} but expected {1}";
/** Entries of LU decomposition. */
private double lu[][];
@ -262,8 +266,7 @@ public class LUDecompositionImpl implements LUDecomposition {
final int m = pivot.length;
if (b.length != m) {
throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
b.length, m);
VECTOR_LENGTH_MISMATCH_MESSAGE, b.length, m);
}
if (singular) {
throw new SingularMatrixException();
@ -307,8 +310,7 @@ public class LUDecompositionImpl implements LUDecomposition {
final int m = pivot.length;
if (b.getDimension() != m) {
throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
b.getDimension(), m);
VECTOR_LENGTH_MISMATCH_MESSAGE, b.getDimension(), m);
}
if (singular) {
throw new SingularMatrixException();

View File

@ -87,6 +87,14 @@ import org.apache.commons.math.optimization.SimpleScalarValueChecker;
*/
public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer {
/** Message for equal vertices. */
private static final String EQUAL_VERTICES_MESSAGE =
"equal vertices {0} and {1} in simplex configuration";
/** Message for dimension mismatch. */
private static final String DIMENSION_MISMATCH_MESSAGE =
"dimension mismatch {0} != {1}";
/** Simplex. */
protected RealPointValuePair[] simplex;
@ -146,8 +154,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
for (int j = 0; j < i + 1; ++j) {
if (steps[j] == 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
"equals vertices {0} and {1} in simplex configuration",
j, j + 1);
EQUAL_VERTICES_MESSAGE, j, j + 1);
}
System.arraycopy(steps, 0, vertexI, 0, j + 1);
}
@ -184,8 +191,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
// safety checks
if (refI.length != n) {
throw MathRuntimeException.createIllegalArgumentException(
"dimension mismatch {0} != {1}",
refI.length, n);
DIMENSION_MISMATCH_MESSAGE, refI.length, n);
}
for (int j = 0; j < i; ++j) {
final double[] refJ = referenceSimplex[j];
@ -198,8 +204,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
}
if (allEquals) {
throw MathRuntimeException.createIllegalArgumentException(
"equals vertices {0} and {1} in simplex configuration",
i, j);
EQUAL_VERTICES_MESSAGE, i, j);
}
}
@ -360,8 +365,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
final int n = startPoint.length;
if (n != startConfiguration.length) {
throw MathRuntimeException.createIllegalArgumentException(
"dimension mismatch {0} != {1}",
n, startConfiguration.length);
DIMENSION_MISMATCH_MESSAGE, n, startConfiguration.length);
}
// set first vertex

View File

@ -62,6 +62,9 @@ import org.apache.commons.math.util.MathUtils;
*/
class SimplexTableau implements Serializable {
/** Column label for negative vars. */
private static final String NEGATIVE_VAR_COLUMN_LABEL = "x-";
/** Serializable version identifier. */
private static final long serialVersionUID = -1369660067587938365L;
@ -131,7 +134,7 @@ class SimplexTableau implements Serializable {
columnLabels.add("x" + i);
}
if (!restrictToNonNegative) {
columnLabels.add("x-");
columnLabels.add(NEGATIVE_VAR_COLUMN_LABEL);
}
for (int i = 0; i < getNumSlackVariables(); i++) {
columnLabels.add("s" + i);
@ -363,7 +366,7 @@ class SimplexTableau implements Serializable {
* @return current solution
*/
protected RealPointValuePair getSolution() {
int negativeVarColumn = columnLabels.indexOf("x-");
int negativeVarColumn = columnLabels.indexOf(NEGATIVE_VAR_COLUMN_LABEL);
Integer negativeVarBasicRow = negativeVarColumn > 0 ? getBasicRow(negativeVarColumn) : null;
double mostNegative = negativeVarBasicRow == null ? 0 : getEntry(negativeVarBasicRow, getRhsOffset());

View File

@ -65,6 +65,17 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
/** Serialization UID */
private static final long serialVersionUID = 4133067267405273064L;
/** Name of the setQuantile method. */
private static final String SET_QUANTILE_METHOD_NAME = "setQuantile";
/** Message for unsupported setQuantile. */
private static final String UNSUPPORTED_METHOD_MESSAGE =
"percentile implementation {0} does not support {1}";
/** Message for illegal accesson setquantile. */
private static final String ILLEGAL_ACCESS_MESSAGE =
"cannot access {0} method in percentile implementation {1}";
/** hold the window size **/
protected int windowSize = INFINITE_WINDOW;
@ -377,17 +388,17 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
((Percentile) percentileImpl).setQuantile(p);
} else {
try {
percentileImpl.getClass().getMethod("setQuantile",
percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME,
new Class[] {Double.TYPE}).invoke(percentileImpl,
new Object[] {Double.valueOf(p)});
} catch (NoSuchMethodException e1) { // Setter guard should prevent
throw MathRuntimeException.createIllegalArgumentException(
"percentile implementation {0} does not support setQuantile",
percentileImpl.getClass().getName());
UNSUPPORTED_METHOD_MESSAGE,
percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME);
} catch (IllegalAccessException e2) {
throw MathRuntimeException.createIllegalArgumentException(
"cannot access setQuantile method in percentile implementation {0}",
percentileImpl.getClass().getName());
ILLEGAL_ACCESS_MESSAGE,
SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName());
} catch (InvocationTargetException e3) {
throw MathRuntimeException.createIllegalArgumentException(e3.getCause());
}
@ -560,7 +571,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
public synchronized void setPercentileImpl(
UnivariateStatistic percentileImpl) {
try {
percentileImpl.getClass().getMethod("setQuantile",
percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME,
new Class[] {Double.TYPE}).invoke(percentileImpl,
new Object[] {Double.valueOf(50.0d)});
} catch (NoSuchMethodException e1) {
@ -569,8 +580,8 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
percentileImpl.getClass().getName());
} catch (IllegalAccessException e2) {
throw MathRuntimeException.createIllegalArgumentException(
"cannot access setQuantile method in percentile implementation {0}",
percentileImpl.getClass().getName());
ILLEGAL_ACCESS_MESSAGE,
SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName());
} catch (InvocationTargetException e3) {
throw MathRuntimeException.createIllegalArgumentException(e3.getCause());
}

View File

@ -33,6 +33,10 @@ import org.apache.commons.math.stat.descriptive.StatisticalSummary;
*/
public class TTestImpl implements TTest {
/** Message for insufficient data. */
private static final String INSUFFICIENT_DATA_MESSAGE =
"insufficient data for t statistic, needs at least 2, got {0}";
/** Distribution used to compute inference statistics. */
private TDistribution distribution;
@ -1039,7 +1043,7 @@ public class TTestImpl implements TTest {
throws IllegalArgumentException {
if ((data == null) || (data.length < 2)) {
throw MathRuntimeException.createIllegalArgumentException(
"insufficient data for t statistic, needs at least 2, got {0}",
INSUFFICIENT_DATA_MESSAGE,
(data == null) ? 0 : data.length);
}
}
@ -1052,7 +1056,7 @@ public class TTestImpl implements TTest {
throws IllegalArgumentException {
if ((stat == null) || (stat.getN() < 2)) {
throw MathRuntimeException.createIllegalArgumentException(
"insufficient data for t statistic, needs at least 2, got {0}",
INSUFFICIENT_DATA_MESSAGE,
(stat == null) ? 0 : stat.getN());
}
}

View File

@ -48,6 +48,22 @@ public class FastFourierTransformer implements Serializable {
/** Serializable version identifier. */
static final long serialVersionUID = 5138259215438106000L;
/** Message for not power of 2. */
private static final String NOT_POWER_OF_TWO_MESSAGE =
"{0} is not a power of 2, consider padding for fix";
/** Message for dimension mismatch. */
private static final String DIMENSION_MISMATCH_MESSAGE =
"some dimensions don't match: {0} != {1}";
/** Message for not computed roots of unity. */
private static final String MISSING_ROOTS_OF_UNITY_MESSAGE =
"roots of unity have not been computed yet";
/** Message for out of range root index. */
private static final String OUT_OF_RANGE_ROOT_INDEX_MESSAGE =
"out of range root of unity index {0} (must be in [{1};{2}])";
/** roots of unity */
private RootsOfUnity roots = new RootsOfUnity();
@ -494,8 +510,7 @@ public class FastFourierTransformer implements Serializable {
public static void verifyDataSet(double d[]) throws IllegalArgumentException {
if (!isPowerOf2(d.length)) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} is not a power of 2, consider padding for fix",
d.length);
NOT_POWER_OF_TWO_MESSAGE, d.length);
}
}
@ -508,8 +523,7 @@ public class FastFourierTransformer implements Serializable {
public static void verifyDataSet(Object o[]) throws IllegalArgumentException {
if (!isPowerOf2(o.length)) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} is not a power of 2, consider padding for fix",
o.length);
NOT_POWER_OF_TWO_MESSAGE, o.length);
}
}
@ -663,15 +677,13 @@ public class FastFourierTransformer implements Serializable {
if (vector == null) {
if (dimensionSize.length > 0) {
throw MathRuntimeException.createIllegalArgumentException(
"some dimensions don't match: {0} != {1}",
0, dimensionSize.length);
DIMENSION_MISMATCH_MESSAGE, 0, dimensionSize.length);
}
return null;
}
if (vector.length != dimensionSize.length) {
throw MathRuntimeException.createIllegalArgumentException(
"some dimensions don't match: {0} != {1}",
vector.length, dimensionSize.length);
DIMENSION_MISMATCH_MESSAGE, vector.length, dimensionSize.length);
}
Object lastDimension = multiDimensionalComplexArray;
@ -694,15 +706,13 @@ public class FastFourierTransformer implements Serializable {
if (vector == null) {
if (dimensionSize.length > 0) {
throw MathRuntimeException.createIllegalArgumentException(
"some dimensions don't match: {0} != {1}",
0, dimensionSize.length);
DIMENSION_MISMATCH_MESSAGE, 0, dimensionSize.length);
}
return null;
}
if (vector.length != dimensionSize.length) {
throw MathRuntimeException.createIllegalArgumentException(
"some dimensions don't match: {0} != {1}",
vector.length,dimensionSize.length);
DIMENSION_MISMATCH_MESSAGE, vector.length,dimensionSize.length);
}
Object[] lastDimension = (Object[]) multiDimensionalComplexArray;
@ -818,7 +828,7 @@ public class FastFourierTransformer implements Serializable {
if (omegaCount == 0) {
throw MathRuntimeException.createIllegalStateException(
"roots of unity have not been computed yet");
MISSING_ROOTS_OF_UNITY_MESSAGE);
}
return isForward;
@ -882,12 +892,11 @@ public class FastFourierTransformer implements Serializable {
if (omegaCount == 0) {
throw MathRuntimeException.createIllegalStateException(
"roots of unity have not been computed yet");
MISSING_ROOTS_OF_UNITY_MESSAGE);
}
if ((k < 0) || (k >= omegaCount)) {
throw MathRuntimeException.createIllegalArgumentException(
"out of range root of unity index {0} (must be in [{1};{2}])",
k, 0, omegaCount - 1);
OUT_OF_RANGE_ROOT_INDEX_MESSAGE, k, 0, omegaCount - 1);
}
return omegaReal[k];
@ -906,12 +915,11 @@ public class FastFourierTransformer implements Serializable {
if (omegaCount == 0) {
throw MathRuntimeException.createIllegalStateException(
"roots of unity have not been computed yet");
MISSING_ROOTS_OF_UNITY_MESSAGE);
}
if ((k < 0) || (k >= omegaCount)) {
throw MathRuntimeException.createIllegalArgumentException(
"out of range root of unity index {0} (must be in [{1};{2}])",
k, 0, omegaCount - 1);
OUT_OF_RANGE_ROOT_INDEX_MESSAGE, k, 0, omegaCount - 1);
}
return isForward ? omegaImaginaryForward[k] : omegaImaginaryInverse[k];

View File

@ -50,6 +50,14 @@ public class OpenIntToDoubleHashMap implements Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -3646337053166149105L;
/** Message for map modification during iteration. */
private static final String CONCURRENT_MODIFICATION_MESSAGE =
"map has been modified while iterating";
/** Message for exhausted iterator. */
private static final String EXHAUSTED_ITERATOR_MESSAGE =
"iterator exhausted";
/** Load factor for the map. */
private static final float LOAD_FACTOR = 0.5f;
@ -526,10 +534,11 @@ public class OpenIntToDoubleHashMap implements Serializable {
public int key()
throws ConcurrentModificationException, NoSuchElementException {
if (referenceCount != count) {
throw MathRuntimeException.createConcurrentModificationException("map has been modified while iterating");
throw MathRuntimeException.createConcurrentModificationException(
CONCURRENT_MODIFICATION_MESSAGE);
}
if (current < 0) {
throw MathRuntimeException.createNoSuchElementException("iterator exhausted");
throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
}
return keys[current];
}
@ -543,10 +552,11 @@ public class OpenIntToDoubleHashMap implements Serializable {
public double value()
throws ConcurrentModificationException, NoSuchElementException {
if (referenceCount != count) {
throw MathRuntimeException.createConcurrentModificationException("map has been modified while iterating");
throw MathRuntimeException.createConcurrentModificationException(
CONCURRENT_MODIFICATION_MESSAGE);
}
if (current < 0) {
throw MathRuntimeException.createNoSuchElementException("iterator exhausted");
throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
}
return values[current];
}
@ -560,7 +570,8 @@ public class OpenIntToDoubleHashMap implements Serializable {
throws ConcurrentModificationException, NoSuchElementException {
if (referenceCount != count) {
throw MathRuntimeException.createConcurrentModificationException("map has been modified while iterating");
throw MathRuntimeException.createConcurrentModificationException(
CONCURRENT_MODIFICATION_MESSAGE);
}
// advance on step
@ -574,7 +585,7 @@ public class OpenIntToDoubleHashMap implements Serializable {
} catch (ArrayIndexOutOfBoundsException e) {
next = -2;
if (current < 0) {
throw MathRuntimeException.createNoSuchElementException("iterator exhausted");
throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
}
}

View File

@ -53,6 +53,14 @@ public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Seriali
/** Serializable version identifier. */
private static final long serialVersionUID = -9179080286849120720L;
/** Message for map modification during iteration. */
private static final String CONCURRENT_MODIFICATION_MESSAGE =
"map has been modified while iterating";
/** Message for exhausted iterator. */
private static final String EXHAUSTED_ITERATOR_MESSAGE =
"iterator exhausted";
/** Load factor for the map. */
private static final float LOAD_FACTOR = 0.5f;
@ -538,10 +546,11 @@ public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Seriali
public int key()
throws ConcurrentModificationException, NoSuchElementException {
if (referenceCount != count) {
throw MathRuntimeException.createConcurrentModificationException("map has been modified while iterating");
throw MathRuntimeException.createConcurrentModificationException(
CONCURRENT_MODIFICATION_MESSAGE);
}
if (current < 0) {
throw MathRuntimeException.createNoSuchElementException("iterator exhausted");
throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
}
return keys[current];
}
@ -555,10 +564,11 @@ public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Seriali
public T value()
throws ConcurrentModificationException, NoSuchElementException {
if (referenceCount != count) {
throw MathRuntimeException.createConcurrentModificationException("map has been modified while iterating");
throw MathRuntimeException.createConcurrentModificationException(
CONCURRENT_MODIFICATION_MESSAGE);
}
if (current < 0) {
throw MathRuntimeException.createNoSuchElementException("iterator exhausted");
throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
}
return values[current];
}
@ -572,7 +582,8 @@ public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Seriali
throws ConcurrentModificationException, NoSuchElementException {
if (referenceCount != count) {
throw MathRuntimeException.createConcurrentModificationException("map has been modified while iterating");
throw MathRuntimeException.createConcurrentModificationException(
CONCURRENT_MODIFICATION_MESSAGE);
}
// advance on step
@ -586,7 +597,7 @@ public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Seriali
} catch (ArrayIndexOutOfBoundsException e) {
next = -2;
if (current < 0) {
throw MathRuntimeException.createNoSuchElementException("iterator exhausted");
throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
}
}