From 92a9c20dc56dddc8710226d40c079fc13ab5331d Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Wed, 16 Jun 2010 23:03:38 +0000 Subject: [PATCH] changed the localization mechanism for error messages. The new system is based on an enum rather than on duplicated string literals. JIRA: MATH-361 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@955423 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/ConvergenceException.java | 35 +- .../math/DimensionMismatchException.java | 4 +- .../DuplicateSampleAbscissaException.java | 4 +- .../math/FunctionEvaluationException.java | 69 +- .../math/MathConfigurationException.java | 26 + .../apache/commons/math/MathException.java | 93 +- .../commons/math/MathRuntimeException.java | 238 ++++- .../math/MaxEvaluationsExceededException.java | 23 +- .../math/MaxIterationsExceededException.java | 23 +- .../commons/math/MessagesResources_fr.java | 880 ------------------ .../integration/RombergIntegrator.java | 3 +- .../integration/SimpsonIntegrator.java | 3 +- .../integration/TrapezoidIntegrator.java | 3 +- .../UnivariateRealIntegratorImpl.java | 7 +- .../BicubicSplineInterpolatingFunction.java | 21 +- .../BicubicSplineInterpolator.java | 3 +- .../interpolation/LoessInterpolator.java | 47 +- .../MicrosphereInterpolatingFunction.java | 3 +- .../MicrosphereInterpolator.java | 5 +- .../SmoothingBicubicSplineInterpolator.java | 3 +- ...ngPolynomialBicubicSplineInterpolator.java | 3 +- .../interpolation/SplineInterpolator.java | 7 +- .../TricubicSplineInterpolatingFunction.java | 24 +- .../TricubicSplineInterpolator.java | 3 +- .../polynomials/PolynomialFunction.java | 11 +- .../PolynomialFunctionLagrangeForm.java | 7 +- .../PolynomialFunctionNewtonForm.java | 5 +- .../polynomials/PolynomialSplineFunction.java | 7 +- .../math/analysis/solvers/BrentSolver.java | 12 +- .../math/analysis/solvers/LaguerreSolver.java | 17 +- .../math/analysis/solvers/NewtonSolver.java | 3 +- .../math/analysis/solvers/SecantSolver.java | 5 +- .../solvers/UnivariateRealSolverImpl.java | 10 +- .../solvers/UnivariateRealSolverUtils.java | 17 +- .../apache/commons/math/complex/Complex.java | 3 +- .../commons/math/complex/ComplexFormat.java | 9 +- .../commons/math/complex/ComplexUtils.java | 3 +- .../AbstractContinuousDistribution.java | 11 +- .../distribution/AbstractDistribution.java | 3 +- .../AbstractIntegerDistribution.java | 23 +- .../BinomialDistributionImpl.java | 5 +- .../distribution/CauchyDistributionImpl.java | 5 +- .../ExponentialDistributionImpl.java | 5 +- .../math/distribution/FDistributionImpl.java | 9 +- .../distribution/GammaDistributionImpl.java | 5 +- .../HypergeometricDistributionImpl.java | 11 +- .../distribution/NormalDistributionImpl.java | 3 +- .../distribution/PascalDistributionImpl.java | 5 +- .../distribution/PoissonDistributionImpl.java | 3 +- .../math/distribution/TDistributionImpl.java | 3 +- .../distribution/WeibullDistributionImpl.java | 7 +- .../distribution/ZipfDistributionImpl.java | 6 +- .../math/estimation/AbstractEstimator.java | 7 +- .../math/estimation/EstimationException.java | 12 + .../math/estimation/GaussNewtonEstimator.java | 3 +- .../LevenbergMarquardtEstimator.java | 4 +- .../commons/math/fraction/AbstractFormat.java | 5 +- .../commons/math/fraction/BigFraction.java | 19 +- .../math/fraction/BigFractionFormat.java | 3 +- .../commons/math/fraction/Fraction.java | 33 +- .../fraction/FractionConversionException.java | 5 +- .../commons/math/fraction/FractionFormat.java | 5 +- .../fraction/ProperBigFractionFormat.java | 3 +- .../math/fraction/ProperFractionFormat.java | 3 +- .../CardanEulerSingularityException.java | 3 +- .../geometry/NotARotationMatrixException.java | 14 + .../commons/math/geometry/Rotation.java | 13 +- .../commons/math/geometry/Vector3D.java | 7 +- .../commons/math/geometry/Vector3DFormat.java | 3 +- .../math/linear/AbstractFieldMatrix.java | 61 +- .../math/linear/AbstractRealMatrix.java | 39 +- .../math/linear/AbstractRealVector.java | 4 +- .../math/linear/Array2DRowFieldMatrix.java | 49 +- .../math/linear/Array2DRowRealMatrix.java | 49 +- .../commons/math/linear/ArrayFieldVector.java | 11 +- .../commons/math/linear/ArrayRealVector.java | 17 +- .../commons/math/linear/BigMatrixImpl.java | 57 +- .../commons/math/linear/BlockFieldMatrix.java | 27 +- .../commons/math/linear/BlockRealMatrix.java | 29 +- .../linear/CholeskyDecompositionImpl.java | 7 +- .../math/linear/EigenDecompositionImpl.java | 9 +- .../math/linear/FieldLUDecompositionImpl.java | 7 +- .../math/linear/InvalidMatrixException.java | 14 +- .../math/linear/LUDecompositionImpl.java | 11 +- .../math/linear/MatrixIndexException.java | 14 +- .../commons/math/linear/MatrixUtils.java | 19 +- .../math/linear/MatrixVisitorException.java | 13 + .../math/linear/NonSquareMatrixException.java | 5 +- .../NotPositiveDefiniteMatrixException.java | 3 +- .../linear/NotSymmetricMatrixException.java | 3 +- .../math/linear/OpenMapRealVector.java | 3 +- .../math/linear/QRDecompositionImpl.java | 5 +- .../commons/math/linear/RealMatrixImpl.java | 29 +- .../commons/math/linear/RealVectorFormat.java | 3 +- .../math/linear/SingularMatrixException.java | 4 +- .../SingularValueDecompositionImpl.java | 3 +- .../math/linear/SparseFieldVector.java | 3 +- .../commons/math/ode/AbstractIntegrator.java | 11 +- .../math/ode/ContinuousOutputModel.java | 7 +- .../commons/math/ode/DerivativeException.java | 15 +- .../commons/math/ode/IntegratorException.java | 28 +- .../commons/math/ode/MultistepIntegrator.java | 3 +- .../math/ode/events/EventException.java | 13 + .../FirstOrderIntegratorWithJacobians.java | 3 +- .../nonstiff/AdaptiveStepsizeIntegrator.java | 11 +- .../optimization/LeastSquaresConverter.java | 7 +- ...fferentiableMultivariateRealOptimizer.java | 5 +- ...ntiableMultivariateVectorialOptimizer.java | 5 +- .../MultiStartMultivariateRealOptimizer.java | 5 +- .../MultiStartUnivariateRealOptimizer.java | 7 +- .../optimization/OptimizationException.java | 17 +- .../direct/DirectSearchOptimizer.java | 19 +- .../fitting/HarmonicCoefficientsGuesser.java | 3 +- .../optimization/fitting/HarmonicFitter.java | 3 +- .../AbstractLeastSquaresOptimizer.java | 11 +- .../general/GaussNewtonOptimizer.java | 3 +- .../general/LevenbergMarquardtOptimizer.java | 15 +- .../NonLinearConjugateGradientOptimizer.java | 3 +- .../linear/NoFeasibleSolutionException.java | 3 +- .../linear/UnboundedSolutionException.java | 3 +- .../AbstractUnivariateRealOptimizer.java | 3 +- .../math/random/AbstractRandomGenerator.java | 3 +- .../math/random/BitsStreamGenerator.java | 3 +- .../random/EmpiricalDistributionImpl.java | 7 +- .../commons/math/random/RandomDataImpl.java | 29 +- .../UncorrelatedRandomVectorGenerator.java | 3 +- .../commons/math/random/ValueServer.java | 5 +- .../apache/commons/math/stat/Frequency.java | 5 +- .../apache/commons/math/stat/StatUtils.java | 19 +- .../math/stat/correlation/Covariance.java | 17 +- .../stat/correlation/PearsonsCorrelation.java | 18 +- .../correlation/SpearmansCorrelation.java | 14 +- .../AbstractStorelessUnivariateStatistic.java | 5 +- .../AbstractUnivariateStatistic.java | 9 +- .../descriptive/DescriptiveStatistics.java | 17 +- .../MultivariateSummaryStatistics.java | 3 +- .../stat/descriptive/SummaryStatistics.java | 3 +- .../descriptive/moment/GeometricMean.java | 3 +- .../stat/descriptive/moment/Kurtosis.java | 5 +- .../stat/descriptive/moment/SemiVariance.java | 3 +- .../stat/descriptive/moment/Variance.java | 3 +- .../stat/descriptive/rank/Percentile.java | 5 +- .../stat/inference/ChiSquareTestImpl.java | 37 +- .../math/stat/inference/OneWayAnovaImpl.java | 7 +- .../math/stat/inference/TTestImpl.java | 11 +- .../AbstractMultipleLinearRegression.java | 9 +- .../stat/regression/SimpleRegression.java | 3 +- .../math/transform/FastCosineTransformer.java | 3 +- .../transform/FastFourierTransformer.java | 38 +- .../transform/FastHadamardTransformer.java | 5 +- .../math/transform/FastSineTransformer.java | 3 +- .../commons/math/util/ContinuedFraction.java | 8 +- .../commons/math/util/DefaultTransformer.java | 4 +- .../commons/math/util/DummyLocalizable.java | 55 ++ .../apache/commons/math/util/Localizable.java | 43 + .../commons/math/util/LocalizedFormats.java | 314 +++++++ .../apache/commons/math/util/MathUtils.java | 50 +- .../math/util/OpenIntToDoubleHashMap.java | 23 +- .../math/util/OpenIntToFieldHashMap.java | 23 +- .../math/util/ResizableDoubleArray.java | 20 +- .../LocalizedFormats_fr.properties | 230 +++++ src/site/xdoc/changes.xml | 3 + .../math/ConvergenceExceptionTest.java | 10 +- .../math/FunctionEvaluationExceptionTest.java | 18 +- .../math/MathConfigurationExceptionTest.java | 10 +- .../commons/math/MathExceptionTest.java | 22 +- .../MaxIterationsExceededExceptionTest.java | 4 +- .../nonstiff/HighamHall54IntegratorTest.java | 5 +- .../apache/commons/math/util/TestBean.java | 2 +- 169 files changed, 1938 insertions(+), 1787 deletions(-) delete mode 100644 src/main/java/org/apache/commons/math/MessagesResources_fr.java create mode 100644 src/main/java/org/apache/commons/math/util/DummyLocalizable.java create mode 100644 src/main/java/org/apache/commons/math/util/Localizable.java create mode 100644 src/main/java/org/apache/commons/math/util/LocalizedFormats.java create mode 100644 src/main/resources/META-INF/localization/LocalizedFormats_fr.properties diff --git a/src/main/java/org/apache/commons/math/ConvergenceException.java b/src/main/java/org/apache/commons/math/ConvergenceException.java index 532bbb845..0c7f9255c 100644 --- a/src/main/java/org/apache/commons/math/ConvergenceException.java +++ b/src/main/java/org/apache/commons/math/ConvergenceException.java @@ -16,6 +16,10 @@ */ package org.apache.commons.math; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; + /** * Error thrown when a numerical computation can not be performed because the * numerical result failed to converge to a finite value. @@ -25,13 +29,13 @@ package org.apache.commons.math; public class ConvergenceException extends MathException { /** Serializable version identifier */ - private static final long serialVersionUID = 4883703247677159141L; + private static final long serialVersionUID = -1111352570797662604L; /** * Default constructor. */ public ConvergenceException() { - super("Convergence failed"); + super(LocalizedFormats.CONVERGENCE_FAILED); } /** @@ -40,8 +44,21 @@ public class ConvergenceException extends MathException { * @param pattern format specifier * @param arguments format arguments * @since 1.2 + * @deprecated as of 2.2 replaced by {@link #ConvergenceException(Localizable, Object...)} */ + @Deprecated public ConvergenceException(String pattern, Object ... arguments) { + this(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public ConvergenceException(Localizable pattern, Object ... arguments) { super(pattern, arguments); } @@ -60,8 +77,22 @@ public class ConvergenceException extends MathException { * @param pattern format specifier * @param arguments format arguments * @since 1.2 + * @deprecated as of 2.2 replaced by {@link #ConvergenceException(Throwable, Localizable, Object...)} */ + @Deprecated public ConvergenceException(Throwable cause, String pattern, Object ... arguments) { + this(cause, new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs an exception with specified formatted detail message and root cause. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param cause the exception or error that caused this exception to be thrown + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public ConvergenceException(Throwable cause, Localizable pattern, Object ... arguments) { super(cause, pattern, arguments); } diff --git a/src/main/java/org/apache/commons/math/DimensionMismatchException.java b/src/main/java/org/apache/commons/math/DimensionMismatchException.java index 6cc51d165..c3db815c8 100644 --- a/src/main/java/org/apache/commons/math/DimensionMismatchException.java +++ b/src/main/java/org/apache/commons/math/DimensionMismatchException.java @@ -16,6 +16,8 @@ */ package org.apache.commons.math; +import org.apache.commons.math.util.LocalizedFormats; + /** * Error thrown when two dimensions differ. * @@ -39,7 +41,7 @@ public class DimensionMismatchException extends MathException { * @param dimension2 second dimension */ public DimensionMismatchException(final int dimension1, final int dimension2) { - super("dimension mismatch {0} != {1}", dimension1, dimension2); + super(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, dimension1, dimension2); this.dimension1 = dimension1; this.dimension2 = dimension2; } diff --git a/src/main/java/org/apache/commons/math/DuplicateSampleAbscissaException.java b/src/main/java/org/apache/commons/math/DuplicateSampleAbscissaException.java index e4492200a..3ce78a091 100644 --- a/src/main/java/org/apache/commons/math/DuplicateSampleAbscissaException.java +++ b/src/main/java/org/apache/commons/math/DuplicateSampleAbscissaException.java @@ -16,6 +16,8 @@ */ package org.apache.commons.math; +import org.apache.commons.math.util.LocalizedFormats; + /** * Exception thrown when a sample contains several entries at the same abscissa. * @@ -34,7 +36,7 @@ public class DuplicateSampleAbscissaException extends MathException { * @param i2 index of another entry having the duplicate abscissa */ public DuplicateSampleAbscissaException(double abscissa, int i1, int i2) { - super("Abscissa {0} is duplicated at both indices {1} and {2}", + super(LocalizedFormats.DUPLICATED_ABSCISSA, abscissa, i1, i2); } diff --git a/src/main/java/org/apache/commons/math/FunctionEvaluationException.java b/src/main/java/org/apache/commons/math/FunctionEvaluationException.java index a37c7e629..8352d6620 100644 --- a/src/main/java/org/apache/commons/math/FunctionEvaluationException.java +++ b/src/main/java/org/apache/commons/math/FunctionEvaluationException.java @@ -17,6 +17,9 @@ package org.apache.commons.math; import org.apache.commons.math.linear.ArrayRealVector; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; /** * Exception thrown when an error occurs evaluating a function. @@ -29,11 +32,7 @@ import org.apache.commons.math.linear.ArrayRealVector; 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}"; + private static final long serialVersionUID = 1384427981840836868L; /** Argument causing function evaluation failure */ private double[] argument; @@ -45,7 +44,7 @@ public class FunctionEvaluationException extends MathException { * @param argument the failing function argument */ public FunctionEvaluationException(double argument) { - super(FAILED_EVALUATION_MESSAGE, argument); + super(LocalizedFormats.EVALUATION_FAILED, argument); this.argument = new double[] { argument }; } @@ -57,7 +56,7 @@ public class FunctionEvaluationException extends MathException { * @since 2.0 */ public FunctionEvaluationException(double[] argument) { - super(FAILED_EVALUATION_MESSAGE, new ArrayRealVector(argument)); + super(LocalizedFormats.EVALUATION_FAILED, new ArrayRealVector(argument)); this.argument = argument.clone(); } @@ -71,6 +70,19 @@ public class FunctionEvaluationException extends MathException { */ public FunctionEvaluationException(double argument, String pattern, Object ... arguments) { + this(argument, new DummyLocalizable(pattern), argument); + } + + /** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param argument the failing function argument + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public FunctionEvaluationException(double argument, + Localizable pattern, Object ... arguments) { super(pattern, arguments); this.argument = new double[] { argument }; } @@ -85,6 +97,19 @@ public class FunctionEvaluationException extends MathException { */ public FunctionEvaluationException(double[] argument, String pattern, Object ... arguments) { + this(argument, new DummyLocalizable(pattern), argument); + } + + /** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param argument the failing function argument + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public FunctionEvaluationException(double[] argument, + Localizable pattern, Object ... arguments) { super(pattern, arguments); this.argument = argument.clone(); } @@ -125,6 +150,21 @@ public class FunctionEvaluationException extends MathException { public FunctionEvaluationException(Throwable cause, double argument, String pattern, Object ... arguments) { + this(cause, argument, new DummyLocalizable(pattern), argument); + } + + /** + * Constructs an exception with specified formatted detail message and root cause. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param cause the exception or error that caused this exception to be thrown + * @param argument the failing function argument + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public FunctionEvaluationException(Throwable cause, + double argument, Localizable pattern, + Object ... arguments) { super(cause, pattern, arguments); this.argument = new double[] { argument }; } @@ -141,6 +181,21 @@ public class FunctionEvaluationException extends MathException { public FunctionEvaluationException(Throwable cause, double[] argument, String pattern, Object ... arguments) { + this(cause, argument, new DummyLocalizable(pattern), argument); + } + + /** + * Constructs an exception with specified formatted detail message and root cause. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param cause the exception or error that caused this exception to be thrown + * @param argument the failing function argument + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public FunctionEvaluationException(Throwable cause, + double[] argument, Localizable pattern, + Object ... arguments) { super(cause, pattern, arguments); this.argument = argument.clone(); } diff --git a/src/main/java/org/apache/commons/math/MathConfigurationException.java b/src/main/java/org/apache/commons/math/MathConfigurationException.java index ed5f983be..42e8f4b6f 100644 --- a/src/main/java/org/apache/commons/math/MathConfigurationException.java +++ b/src/main/java/org/apache/commons/math/MathConfigurationException.java @@ -18,6 +18,9 @@ package org.apache.commons.math; import java.io.Serializable; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; + /** * Signals a configuration problem with any of the factory methods. * @version $Revision$ $Date$ @@ -42,6 +45,17 @@ public class MathConfigurationException extends MathException implements Seriali * @since 1.2 */ public MathConfigurationException(String pattern, Object ... arguments) { + this(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public MathConfigurationException(Localizable pattern, Object ... arguments) { super(pattern, arguments); } @@ -62,6 +76,18 @@ public class MathConfigurationException extends MathException implements Seriali * @since 1.2 */ public MathConfigurationException(Throwable cause, String pattern, Object ... arguments) { + this(cause, new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs an exception with specified formatted detail message and root cause. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param cause the exception or error that caused this exception to be thrown + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public MathConfigurationException(Throwable cause, Localizable pattern, Object ... arguments) { super(cause, pattern, arguments); } diff --git a/src/main/java/org/apache/commons/math/MathException.java b/src/main/java/org/apache/commons/math/MathException.java index 80dbe5151..85e0579d1 100644 --- a/src/main/java/org/apache/commons/math/MathException.java +++ b/src/main/java/org/apache/commons/math/MathException.java @@ -20,8 +20,10 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.text.MessageFormat; import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; + +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -36,12 +38,12 @@ import java.util.ResourceBundle; public class MathException extends Exception { /** Serializable version identifier. */ - private static final long serialVersionUID = -9004610152740737812L; + private static final long serialVersionUID = 7428019509644517071L; /** * Pattern used to build the message. */ - private final String pattern; + private final Localizable pattern; /** * Arguments used to build the message. @@ -53,8 +55,21 @@ public class MathException extends Exception { * detail message. */ public MathException() { - this.pattern = null; - this.arguments = new Object[0]; + this.pattern = LocalizedFormats.SIMPLE_MESSAGE; + this.arguments = new Object[] { "" }; + } + + /** + * Constructs a new MathException with specified + * formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @deprecated as of 2.2 replaced by {@link #MathException(Localizable, Object...)} + */ + @Deprecated + public MathException(String pattern, Object ... arguments) { + this(new DummyLocalizable(pattern), arguments); } /** @@ -64,7 +79,7 @@ public class MathException extends Exception { * @param pattern format specifier * @param arguments format arguments */ - public MathException(String pattern, Object ... arguments) { + public MathException(Localizable pattern, Object ... arguments) { this.pattern = pattern; this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); } @@ -78,8 +93,24 @@ public class MathException extends Exception { */ public MathException(Throwable rootCause) { super(rootCause); - this.pattern = getMessage(); - this.arguments = new Object[0]; + this.pattern = LocalizedFormats.SIMPLE_MESSAGE; + this.arguments = new Object[] { (rootCause == null) ? "" : rootCause.getMessage() }; + } + + /** + * Constructs a new MathException with specified + * formatted detail message and nested Throwable root cause. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param rootCause the exception or error that caused this exception + * to be thrown. + * @param pattern format specifier + * @param arguments format arguments + * @since 1.2 + * @deprecated as of 2.2 replaced by {@link #MathException(Throwable, Localizable, Object...)} + */ + @Deprecated + public MathException(Throwable rootCause, String pattern, Object ... arguments) { + this(rootCause, new DummyLocalizable(pattern), arguments); } /** @@ -92,44 +123,29 @@ public class MathException extends Exception { * @param arguments format arguments * @since 1.2 */ - public MathException(Throwable rootCause, String pattern, Object ... arguments) { + public MathException(Throwable rootCause, Localizable pattern, Object ... arguments) { super(rootCause); this.pattern = pattern; this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); } - /** - * Translate a string to a given locale. - * @param s string to translate - * @param locale locale into which to translate the string - * @return translated string or original string - * for unsupported locales or unknown strings - */ - private static String translate(String s, Locale locale) { - try { - ResourceBundle bundle = - ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale); - if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) { - // the value of the resource is the translated string - return bundle.getString(s); - } - - } catch (MissingResourceException mre) { - // do nothing here - } - - // the locale is not supported or the resource is unknown - // don't translate and fall back to using the string as is - return s; - - } - /** Gets the pattern used to build the message of this throwable. * * @return the pattern used to build the message of this throwable * @since 1.2 + * @deprecated as of 2.2 replaced by {@link #getLocalizablePattern()} */ + @Deprecated public String getPattern() { + return pattern.getSourceString(); + } + + /** Gets the localizable pattern used to build the message of this throwable. + * + * @return the localizable pattern used to build the message of this throwable + * @since 2.2 + */ + public Localizable getLocalizablePattern() { return pattern; } @@ -150,7 +166,10 @@ public class MathException extends Exception { * @since 1.2 */ public String getMessage(final Locale locale) { - return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments); + if (pattern != null) { + return new MessageFormat(pattern.getLocalizedString(locale), locale).format(arguments); + } + return ""; } /** {@inheritDoc} */ diff --git a/src/main/java/org/apache/commons/math/MathRuntimeException.java b/src/main/java/org/apache/commons/math/MathRuntimeException.java index 17e901e10..744a5e9f6 100644 --- a/src/main/java/org/apache/commons/math/MathRuntimeException.java +++ b/src/main/java/org/apache/commons/math/MathRuntimeException.java @@ -24,9 +24,11 @@ import java.text.MessageFormat; import java.text.ParseException; import java.util.ConcurrentModificationException; import java.util.Locale; -import java.util.MissingResourceException; import java.util.NoSuchElementException; -import java.util.ResourceBundle; + +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; /** * Base class for commons-math unchecked exceptions. @@ -37,12 +39,12 @@ import java.util.ResourceBundle; public class MathRuntimeException extends RuntimeException { /** Serializable version identifier. */ - private static final long serialVersionUID = -5128983364075381060L; + private static final long serialVersionUID = 9058794795027570002L; /** * Pattern used to build the message. */ - private final String pattern; + private final Localizable pattern; /** * Arguments used to build the message. @@ -55,8 +57,22 @@ public class MathRuntimeException extends RuntimeException { * Message formatting is delegated to {@link java.text.MessageFormat}. * @param pattern format specifier * @param arguments format arguments + * @deprecated as of 2.2 replaced by {@link #MathRuntimeException(Localizable, Object...)} */ + @Deprecated public MathRuntimeException(final String pattern, final Object ... arguments) { + this(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new MathRuntimeException with specified + * formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public MathRuntimeException(final Localizable pattern, final Object ... arguments) { this.pattern = pattern; this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); } @@ -70,8 +86,8 @@ public class MathRuntimeException extends RuntimeException { */ public MathRuntimeException(final Throwable rootCause) { super(rootCause); - this.pattern = getMessage(); - this.arguments = new Object[0]; + this.pattern = LocalizedFormats.SIMPLE_MESSAGE; + this.arguments = new Object[] { (rootCause == null) ? "" : rootCause.getMessage() }; } /** @@ -82,38 +98,29 @@ public class MathRuntimeException extends RuntimeException { * to be thrown. * @param pattern format specifier * @param arguments format arguments + * @deprecated as of 2.2 replaced by {@link #MathRuntimeException(Throwable, Localizable, Object...)} */ + @Deprecated public MathRuntimeException(final Throwable rootCause, final String pattern, final Object ... arguments) { - super(rootCause); - this.pattern = pattern; - this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); + this(rootCause, new DummyLocalizable(pattern), arguments); } /** - * Translate a string to a given locale. - * @param s string to translate - * @param locale locale into which to translate the string - * @return translated string or original string - * for unsupported locales or unknown strings + * Constructs a new MathRuntimeException with specified + * formatted detail message and nested Throwable root cause. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param rootCause the exception or error that caused this exception + * to be thrown. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 */ - private static String translate(final String s, final Locale locale) { - try { - ResourceBundle bundle = - ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale); - if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) { - // the value of the resource is the translated string - return bundle.getString(s); - } - - } catch (MissingResourceException mre) { - // do nothing here - } - - // the locale is not supported or the resource is unknown - // don't translate and fall back to using the string as is - return s; - + public MathRuntimeException(final Throwable rootCause, + final Localizable pattern, final Object ... arguments) { + super(rootCause); + this.pattern = pattern; + this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); } /** @@ -122,17 +129,29 @@ public class MathRuntimeException extends RuntimeException { * @param pattern format specifier * @param arguments format arguments * @return a message string + * @since 2.2 */ - private static String buildMessage(final Locale locale, final String pattern, + private static String buildMessage(final Locale locale, final Localizable pattern, final Object ... arguments) { - return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments); + return new MessageFormat(pattern.getLocalizedString(locale), locale).format(arguments); } /** Gets the pattern used to build the message of this throwable. - * - * @return the pattern used to build the message of this throwable - */ + * + * @return the pattern used to build the message of this throwable + * @deprecated as of 2.2 replaced by {@link #getLocalizablePattern()} + */ + @Deprecated public String getPattern() { + return pattern.getSourceString(); + } + + /** Gets the localizable pattern used to build the message of this throwable. + * + * @return the localizable pattern used to build the message of this throwable + * @since 2.2 + */ + public Localizable getLocalizablePattern() { return pattern; } @@ -151,7 +170,10 @@ public class MathRuntimeException extends RuntimeException { * @return localized message */ public String getMessage(final Locale locale) { - return buildMessage(locale, pattern, arguments); + if (pattern != null) { + return buildMessage(locale, pattern, arguments); + } + return ""; } /** {@inheritDoc} */ @@ -198,10 +220,23 @@ public class MathRuntimeException extends RuntimeException { */ public static ArithmeticException createArithmeticException(final String pattern, final Object ... arguments) { + return createArithmeticException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new ArithmeticException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static ArithmeticException createArithmeticException(final Localizable pattern, + final Object ... arguments) { return new ArithmeticException() { /** Serializable version identifier. */ - private static final long serialVersionUID = 7705628723242533939L; + private static final long serialVersionUID = 5305498554076846637L; /** {@inheritDoc} */ @Override @@ -227,10 +262,23 @@ public class MathRuntimeException extends RuntimeException { */ public static ArrayIndexOutOfBoundsException createArrayIndexOutOfBoundsException(final String pattern, final Object ... arguments) { + return createArrayIndexOutOfBoundsException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new ArrayIndexOutOfBoundsException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static ArrayIndexOutOfBoundsException createArrayIndexOutOfBoundsException(final Localizable pattern, + final Object ... arguments) { return new ArrayIndexOutOfBoundsException() { /** Serializable version identifier. */ - private static final long serialVersionUID = -3394748305449283486L; + private static final long serialVersionUID = 6718518191249632175L; /** {@inheritDoc} */ @Override @@ -256,10 +304,22 @@ public class MathRuntimeException extends RuntimeException { */ public static EOFException createEOFException(final String pattern, final Object ... arguments) { + return createEOFException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new EOFException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + */ + public static EOFException createEOFException(final Localizable pattern, + final Object ... arguments) { return new EOFException() { /** Serializable version identifier. */ - private static final long serialVersionUID = 279461544586092584L; + private static final long serialVersionUID = 6067985859347601503L; /** {@inheritDoc} */ @Override @@ -302,10 +362,23 @@ public class MathRuntimeException extends RuntimeException { */ public static IllegalArgumentException createIllegalArgumentException(final String pattern, final Object ... arguments) { + return createIllegalArgumentException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new IllegalArgumentException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static IllegalArgumentException createIllegalArgumentException(final Localizable pattern, + final Object ... arguments) { return new IllegalArgumentException() { /** Serializable version identifier. */ - private static final long serialVersionUID = -6555453980658317913L; + private static final long serialVersionUID = -4284649691002411505L; /** {@inheritDoc} */ @Override @@ -344,10 +417,23 @@ public class MathRuntimeException extends RuntimeException { */ public static IllegalStateException createIllegalStateException(final String pattern, final Object ... arguments) { + return createIllegalStateException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new IllegalStateException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static IllegalStateException createIllegalStateException(final Localizable pattern, + final Object ... arguments) { return new IllegalStateException() { /** Serializable version identifier. */ - private static final long serialVersionUID = -95247648156277208L; + private static final long serialVersionUID = 6880901520234515725L; /** {@inheritDoc} */ @Override @@ -373,10 +459,23 @@ public class MathRuntimeException extends RuntimeException { */ public static ConcurrentModificationException createConcurrentModificationException(final String pattern, final Object ... arguments) { + return createConcurrentModificationException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new ConcurrentModificationException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static ConcurrentModificationException createConcurrentModificationException(final Localizable pattern, + final Object ... arguments) { return new ConcurrentModificationException() { /** Serializable version identifier. */ - private static final long serialVersionUID = 6134247282754009421L; + private static final long serialVersionUID = -1878427236170442052L; /** {@inheritDoc} */ @Override @@ -402,10 +501,23 @@ public class MathRuntimeException extends RuntimeException { */ public static NoSuchElementException createNoSuchElementException(final String pattern, final Object ... arguments) { + return createNoSuchElementException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new NoSuchElementException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static NoSuchElementException createNoSuchElementException(final Localizable pattern, + final Object ... arguments) { return new NoSuchElementException() { /** Serializable version identifier. */ - private static final long serialVersionUID = 7304273322489425799L; + private static final long serialVersionUID = 1632410088350355086L; /** {@inheritDoc} */ @Override @@ -431,10 +543,23 @@ public class MathRuntimeException extends RuntimeException { */ public static NullPointerException createNullPointerException(final String pattern, final Object ... arguments) { + return createNullPointerException(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new NullPointerException with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static NullPointerException createNullPointerException(final Localizable pattern, + final Object ... arguments) { return new NullPointerException() { /** Serializable version identifier. */ - private static final long serialVersionUID = -3075660477939965216L; + private static final long serialVersionUID = 451965530686593945L; /** {@inheritDoc} */ @Override @@ -463,10 +588,26 @@ public class MathRuntimeException extends RuntimeException { public static ParseException createParseException(final int offset, final String pattern, final Object ... arguments) { + return createParseException(offset, new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new ParseException with specified + * formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param offset offset at which error occurred + * @param pattern format specifier + * @param arguments format arguments + * @return built exception + * @since 2.2 + */ + public static ParseException createParseException(final int offset, + final Localizable pattern, + final Object ... arguments) { return new ParseException(null, offset) { /** Serializable version identifier. */ - private static final long serialVersionUID = -1103502177342465975L; + private static final long serialVersionUID = 8153587599409010120L; /** {@inheritDoc} */ @Override @@ -489,7 +630,6 @@ public class MathRuntimeException extends RuntimeException { */ public static RuntimeException createInternalError(final Throwable cause) { - final String pattern = "internal error, please fill a bug report at {0}"; final String argument = "https://issues.apache.org/jira/browse/MATH"; return new RuntimeException() { @@ -500,13 +640,13 @@ public class MathRuntimeException extends RuntimeException { /** {@inheritDoc} */ @Override public String getMessage() { - return buildMessage(Locale.US, pattern, argument); + return buildMessage(Locale.US, LocalizedFormats.INTERNAL_ERROR, argument); } /** {@inheritDoc} */ @Override public String getLocalizedMessage() { - return buildMessage(Locale.getDefault(), pattern, argument); + return buildMessage(Locale.getDefault(), LocalizedFormats.INTERNAL_ERROR, argument); } }; diff --git a/src/main/java/org/apache/commons/math/MaxEvaluationsExceededException.java b/src/main/java/org/apache/commons/math/MaxEvaluationsExceededException.java index 427a97048..d054cb174 100644 --- a/src/main/java/org/apache/commons/math/MaxEvaluationsExceededException.java +++ b/src/main/java/org/apache/commons/math/MaxEvaluationsExceededException.java @@ -18,6 +18,9 @@ package org.apache.commons.math; import org.apache.commons.math.ConvergenceException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; /** * Error thrown when a numerical computation exceeds its allowed @@ -35,12 +38,11 @@ public class MaxEvaluationsExceededException extends ConvergenceException { private final int maxEvaluations; /** - * Constructs an exception with specified formatted detail message. - * Message formatting is delegated to {@link java.text.MessageFormat}. + * Constructs an exception with a default detail message. * @param maxEvaluations maximal number of evaluations allowed */ public MaxEvaluationsExceededException(final int maxEvaluations) { - super("Maximal number of evaluations ({0}) exceeded", maxEvaluations); + super(LocalizedFormats.MAX_EVALUATIONS_EXCEEDED, maxEvaluations); this.maxEvaluations = maxEvaluations; } @@ -50,9 +52,24 @@ public class MaxEvaluationsExceededException extends ConvergenceException { * @param maxEvaluations the exceeded maximal number of evaluations * @param pattern format specifier * @param arguments format arguments + * @deprecated as of 2.2 replaced by {@link #MaxEvaluationsExceededException(int, Localizable, Object...)} */ + @Deprecated public MaxEvaluationsExceededException(final int maxEvaluations, final String pattern, final Object ... arguments) { + this(maxEvaluations, new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param maxEvaluations the exceeded maximal number of evaluations + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public MaxEvaluationsExceededException(final int maxEvaluations, + final Localizable pattern, final Object ... arguments) { super(pattern, arguments); this.maxEvaluations = maxEvaluations; } diff --git a/src/main/java/org/apache/commons/math/MaxIterationsExceededException.java b/src/main/java/org/apache/commons/math/MaxIterationsExceededException.java index 4593d97ea..a3ade62d7 100644 --- a/src/main/java/org/apache/commons/math/MaxIterationsExceededException.java +++ b/src/main/java/org/apache/commons/math/MaxIterationsExceededException.java @@ -18,6 +18,9 @@ package org.apache.commons.math; import org.apache.commons.math.ConvergenceException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; /** * Error thrown when a numerical computation exceeds its allowed @@ -35,12 +38,11 @@ public class MaxIterationsExceededException extends ConvergenceException { private final int maxIterations; /** - * Constructs an exception with specified formatted detail message. - * Message formatting is delegated to {@link java.text.MessageFormat}. + * Constructs an exception with a default detail message. * @param maxIterations maximal number of iterations allowed */ public MaxIterationsExceededException(final int maxIterations) { - super("Maximal number of iterations ({0}) exceeded", maxIterations); + super(LocalizedFormats.MAX_ITERATIONS_EXCEEDED, maxIterations); this.maxIterations = maxIterations; } @@ -50,9 +52,24 @@ public class MaxIterationsExceededException extends ConvergenceException { * @param maxIterations the exceeded maximal number of iterations * @param pattern format specifier * @param arguments format arguments + * @deprecated as of 2.2 replaced by {@link #MaxIterationsExceededException(int, Localizable, Object...)} */ + @Deprecated public MaxIterationsExceededException(final int maxIterations, final String pattern, final Object ... arguments) { + this(maxIterations, new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param maxIterations the exceeded maximal number of iterations + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public MaxIterationsExceededException(final int maxIterations, + final Localizable pattern, final Object ... arguments) { super(pattern, arguments); this.maxIterations = maxIterations; } diff --git a/src/main/java/org/apache/commons/math/MessagesResources_fr.java b/src/main/java/org/apache/commons/math/MessagesResources_fr.java deleted file mode 100644 index fdada8239..000000000 --- a/src/main/java/org/apache/commons/math/MessagesResources_fr.java +++ /dev/null @@ -1,880 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math; - -import java.util.ListResourceBundle; - -/** - * French localization message resources for the commons-math library. - * @version $Revision$ $Date$ - * @since 1.2 - */ -public class MessagesResources_fr - extends ListResourceBundle { - - /** Non-translated/translated messages arrays. */ - private static final Object[][] CONTENTS = { - - // org.apache.commons.math.util.MathUtils - { "must have n >= k for binomial coefficient (n,k), got n = {0}, k = {1}", - "n doit \u00eatre sup\u00e9rieur ou \u00e9gal \u00e0 k " + - "pour le coefficient du bin\u00f4me (n,k), or n = {0}, k = {1}" }, - { "must have n >= 0 for binomial coefficient (n,k), got n = {0}", - "n doit \u00eatre positif pour le coefficient du bin\u00f4me (n,k), or n = {0}" }, - { "must have n >= 0 for n!, got n = {0}", - "n doit \u00eatre positif pour le calcul de n!, or n = {0}" }, - { "overflow: gcd({0}, {1}) is 2^31", - "d\u00e9passement de capacit\u00e9 : le PGCD de {0} et {1} vaut 2^31" }, - { "overflow: gcd({0}, {1}) is 2^63", - "d\u00e9passement de capacit\u00e9 : le PGCD de {0} et {1} vaut 2^63" }, - { "overflow: lcm({0}, {1}) is 2^31", - "d\u00e9passement de capacit\u00e9 : le MCM de {0} et {1} vaut 2^31" }, - { "overflow: lcm({0}, {1}) is 2^63", - "d\u00e9passement de capacit\u00e9 : le MCM de {0} et {1} vaut 2^63" }, - { "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})" }, - { "Cannot normalize to an infinite value", - "impossible de normaliser vers une valeur infinie" }, - { "Cannot normalize to NaN", - "impossible de normaliser vers NaN" }, - { "Array contains an infinite element, {0} at index {1}", - "le tableau contient l''\u00e9l\u00e9ment infini {0} \u00e0 l''index {1}" }, - - // org.apache.commons.math.FunctionEvaluationException - { "evaluation failed for argument = {0}", - "erreur d''\u00e9valuation pour l''argument {0}" }, - - // org.apache.commons.math.DuplicateSampleAbscissaException - { "Abscissa {0} is duplicated at both indices {1} and {2}", - "Abscisse {0} dupliqu\u00e9e aux indices {1} et {2}" }, - - // org.apache.commons.math.ConvergenceException - { "Convergence failed", - "\u00c9chec de convergence" }, - - // org.apache.commons.math.ArgumentOutsideDomainException - { "Argument {0} outside domain [{1} ; {2}]", - "Argument {0} hors du domaine [{1} ; {2}]" }, - - // org.apache.commons.math.MaxIterationsExceededException - { "Maximal number of iterations ({0}) exceeded", - "Nombre maximal d''it\u00e9rations ({0}) d\u00e9pass\u00e9" }, - - // org.apache.commons.math.MaxEvaluationsExceededException - { "Maximal number of evaluations ({0}) exceeded", - "Nombre maximal d''\u00e9valuations ({0}) d\u00e9pass\u00e9" }, - - // org.apache.commons.math.analysis.interpolation.SplineInterpolator - // org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm - // org.apache.commons.math.DimensionMismatchException - // org.apache.commons.math.optimization.LeastSquaresConverter - // org.apache.commons.math.optimization.direct.DirectSearchOptimizer - // org.apache.commons.math.optimization.general.AbstractLeastSquaresOptimizer - // org.apache.commons.math.ode.ContinuousOutputModel - // org.apache.commons.math.random.UncorrelatedRandomVectorGenerator - // org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression - // org.apache.commons.math.stat.inference.ChiSquareTestImpl - // org.apache.commons.math.analysis.interpolation.MicrosphereInterpolatingFunction - { "dimension mismatch {0} != {1}", - "dimensions incompatibles {0} != {1}" }, - - // org.apache.commons.math.analysis.interpolation.MicrosphereInterpolatingFunction - { "no data", - "aucune donn\u00e9e" }, - - // org.apache.commons.math.analysis.interpolation.MicrosphereInterpolator - { "brightness exponent should be positive or null, but got {0}", - "l''exposant de brillance devrait \u00eatre positif ou null, or e = {0}" }, - { "number of microsphere elements must be positive, but got {0}", - "le nombre d''\u00e9l\u00e9ments de la microsph\u00e8re devrait \u00eatre positif, or n = {0}" }, - - // org.apache.commons.math.linear.decomposition.NotPositiveDefiniteMatrixException - { "not positive definite matrix", - "matrice non d\u00e9finie positive" }, - - // org.apache.commons.math.linear.decomposition.NotSymmetricMatrixException - { "not symmetric matrix", - "matrice non symm\u00e9trique" }, - - // org.apache.commons.math.fraction.FractionConversionException - { "Unable to convert {0} to fraction after {1} iterations", - "Impossible de convertir {0} en fraction apr\u00e8s {1} it\u00e9rations" }, - { "Overflow trying to convert {0} to fraction ({1}/{2})", - "D\u00e9passement de capacit\u00e9 lors de la conversion de {0} en fraction ({1}/{2})" }, - - // org.apache.commons.math.fraction.BigFraction - { "numerator is null", - "le num\u00e9rateur est null" }, - { "denimonator is null", - "le d\u00e9nominateur est null" }, - { "denominator must be different from 0", - "le d\u00e9nominateur doit \u00eatre diff\u00e9rent de 0" }, - { "cannot convert NaN value", - "les valeurs NaN ne peuvent \u00eatre converties" }, - { "cannot convert infinite value", - "les valeurs infinies ne peuvent \u00eatre converties" }, - - // org.apache.commons.math.fraction.AbstractFormat - { "denominator format can not be null", - "le format du d\u00e9nominateur ne doit pas \u00eatre nul" }, - { "numerator format can not be null", - "le format du num\u00e9rateur ne doit pas \u00eatre nul" }, - - // org.apache.commons.math.fraction.FractionFormat - { "cannot convert given object to a fraction number: {0}", - "impossible de convertir l''objet sous forme d''un nombre rationnel : {0}" }, - - // org.apache.commons.math.fraction.FractionFormat - // org.apache.commons.math.fraction.BigFractionFormat - { "unparseable fraction number: \"{0}\"", - "\u00e9chec d''analyse du nombre rationnel \"{0}\"" }, - { "cannot format given object as a fraction number", - "impossible de formater l''objet sous forme d''un nombre rationnel" }, - - // org.apache.commons.math.fraction.ProperFractionFormat - // org.apache.commons.math.fraction.ProperBigFractionFormat - { "whole format can not be null", - "le format complet ne doit pas \u00eatre nul" }, - - // org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils - { "function is null", - "la fonction est nulle" }, - { "bad value for maximum iterations number: {0}", - "valeur invalide pour le nombre maximal d''it\u00e9rations : {0}" }, - { "invalid bracketing parameters: lower bound={0}, initial={1}, upper bound={2}", - "param\u00e8tres d''encadrement invalides : borne inf\u00e9rieure = {0}, valeur initiale = {1}, borne sup\u00e9rieure = {2}" }, - { "number of iterations={0}, maximum iterations={1}, initial={2}, lower bound={3}, upper bound={4}," + - " final a value={5}, final b value={6}, f(a)={7}, f(b)={8}", - "nombre d''it\u00e9rations = {0}, it\u00e9rations maximum = {1}, valeur initiale = {2}," + - " borne inf\u00e9rieure = {3}, borne sup\u00e9rieure = {4}," + - " valeur a finale = {5}, valeur b finale = {6}, f(a) = {7}, f(b) = {8}" }, - - // org.apache.commons.math.analysis.solvers.LaguerreSolver - { "polynomial degree must be positive: degree={0}", - "le polyn\u00f4me doit \u00eatre de degr\u00e9 positif : degr\u00e9 = {0}" }, - - // org.apache.commons.math.analysis.solvers.SecantSolver - { "function values at endpoints do not have different signs, endpoints: [{0}, {1}], values: [{2}, {3}]", - "les valeurs de la fonctions aux bornes sont de m\u00eame signe, bornes : [{0}, {1}], valeurs : [{2}, {3}]" }, - - // org.apache.commons.math.analysis.interpolation.SplineInterpolator - // org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm - { "{0} points are required, got only {1}", - "{0} sont n\u00e9cessaires, seuls {1} ont \u00e9t\u00e9 fournis" }, - - // org.apache.commons.math.analysis.interpolation.SplineInterpolator - { "points {0} and {1} are not strictly increasing ({2} >= {3})", - "les points {0} et {1} ne sont pas strictement croissants ({2} >= {3})" }, - { "points {0} and {1} are not strictly decreasing ({2} <= {3})", - "les points {0} et {1} ne sont pas strictement d\u00e9croissants ({2} <= {3})" }, - { "points {0} and {1} are not increasing ({2} > {3})", - "les points {0} et {1} ne sont pas croissants ({2} > {3})" }, - { "points {0} and {1} are not decreasing ({2} < {3})", - "les points {0} et {1} ne sont pas d\u00e9croissants ({2} < {3})" }, - - // org.apache.commons.math.analysis.interpolation.LoessInterpolator - { "bandwidth must be in the interval [0,1], but got {0}", - "la largeur de bande doit \u00eatre dans l''intervalle [0, 1], alors qu'elle vaut {0}" }, - { "the number of robustness iterations must be non-negative, but got {0}", - "le nombre d''it\u00e9rations robuste ne peut \u00eatre n\u00e9gatif, alors qu''il est de {0}" }, - { "Loess expects the abscissa and ordinate arrays to be of the same size, " + - "but got {0} abscissae and {1} ordinatae", - "la r\u00e9gression Loess n\u00e9cessite autant d''abscisses que d''ordonn\u00e9es, " + - "mais {0} abscisses et {1} ordonn\u00e9es ont \u00e9t\u00e9 fournies" }, - { "Loess expects at least 1 point", - "la r\u00e9gression Loess n\u00e9cessite au moins un point" }, - { "the bandwidth must be large enough to accomodate at least 2 points. There are {0} " + - " data points, and bandwidth must be at least {1} but it is only {2}", - "la largeur de bande doit \u00eatre assez grande pour supporter au moins 2 points. Il y a {0}" + - "donn\u00e9es et la largeur de bande doit \u00eatre au moins de {1}, or elle est seulement de {2}" }, - { "all abscissae must be finite real numbers, but {0}-th is {1}", - "toutes les abscisses doivent \u00eatre des nombres r\u00e9els finis, mais l''abscisse {0} vaut {1}" }, - { "all ordinatae must be finite real numbers, but {0}-th is {1}", - "toutes les ordonn\u00e9es doivent \u00eatre des nombres r\u00e9els finis, mais l''ordonn\u00e9e {0} vaut {1}" }, - { "all weights must be finite real numbers, but {0}-th is {1}", - "tous les poids doivent \u00eatre des nombres r\u00e9els finis, mais le poids {0} vaut {1}" }, - { "the abscissae array must be sorted in a strictly increasing order, " + - "but the {0}-th element is {1} whereas {2}-th is {3}", - "les abscisses doivent \u00eatre en ordre strictement croissant, " + - "mais l''\u00e9l\u00e9ment {0} vaut {1} alors que l''\u00e9l\u00e9ment {2} vaut {3}" }, - - // org.apache.commons.math.util.ContinuedFraction - { "Continued fraction convergents diverged to +/- infinity for value {0}", - "Divergence de fraction continue \u00e0 l''infini pour la valeur {0}" }, - { "Continued fraction convergents failed to converge for value {0}", - "\u00c9chec de convergence de fraction continue pour la valeur {0}" }, - { "Continued fraction diverged to NaN for value {0}", - "Divergence de fraction continue \u00e0 NaN pour la valeur {0}"}, - - // org.apache.commons.math.util.DefaultTransformer - { "Conversion Exception in Transformation, Object is null", - "Exception de conversion dans une transformation, l''objet est nul" }, - { "Conversion Exception in Transformation: {0}", - "Exception de conversion dans une transformation : {0}" }, - - // org.apache.commons.math.optimization.MultiStartOptimizer - { "no optimum computed yet", - "aucun optimum n''a encore \u00e9t\u00e9 calcul\u00e9" }, - - // org.apache.commons.math.optimization.direct.DirectSearchOptimizer - { "simplex must contain at least one point", - "le simplex doit contenir au moins un point" }, - { "equal vertices {0} and {1} in simplex configuration", - "sommets {0} et {1} \u00e9gaux dans la configuration du simplex" }, - - // org.apache.commons.math.estimation.AbstractEstimation - { "maximal number of evaluations exceeded ({0})", - "nombre maximal d''\u00e9valuations d\u00e9pass\u00e9 ({0})" }, - - // org.apache.commons.math.optimization.general.AbstractLeastSquaresOptimizer - { "unable to compute covariances: singular problem", - "impossible de calculer les covariances : probl\u00e8me singulier"}, - { "no degrees of freedom ({0} measurements, {1} parameters)", - "aucun degr\u00e9 de libert\u00e9 ({0} mesures, {1} param\u00e8tres)" }, - - // org.apache.commons.math.optimization.general.GaussNewtonOptimizer - { "unable to solve: singular problem", - "r\u00e9solution impossible : probl\u00e8me singulier" }, - - // org.apache.commons.math.optimization.general.LevenbergMarquardtEstimator - { "cost relative tolerance is too small ({0}), no further reduction in the sum of squares is possible", - "trop petite tol\u00e9rance relative sur le co\u00fbt ({0}), aucune r\u00e9duction de la somme des carr\u00e9s n''est possible" }, - { "parameters relative tolerance is too small ({0}), no further improvement in the approximate solution is possible", - "trop petite tol\u00e9rance relative sur les param\u00e8tres ({0}), aucune am\u00e9lioration de la solution approximative n''est possible" }, - { "orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian", - "trop petite tol\u00e9rance sur l''orthogonalit\u00e9 ({0}), la solution est orthogonale \u00e0 la jacobienne" }, - { "unable to perform Q.R decomposition on the {0}x{1} jacobian matrix", - "impossible de calculer la factorisation Q.R de la matrice jacobienne {0}x{1}" }, - - // org.apache.commons.math.optimization.general.NonLinearConjugateGradientOptimizer - { "unable to bracket optimum in line search", - "impossible d''encadrer l''optimum lors de la recherche lin\u00e9aire" }, - - // org.apache.commons.math.optimization.fitting.HarmonicCoefficientsGuesser - { "unable to first guess the harmonic coefficients", - "impossible de faire une premi\u00e8re estimation des coefficients harmoniques" }, - - // org.apache.commons.math.optimization.fitting.HarmonicCoefficientsGuesser - { "sample contains {0} observed points, at least {1} are required", - "l''\u00e9chantillon ne contient que {0} points alors qu''au moins {1} sont n\u00e9cessaires" }, - - // org.apache.commons.math.optimization.linear.NoFeasibleSolutionException - { "no feasible solution", - "aucune solution r\u00e9alisable" }, - - // org.apache.commons.math.optimization.linear.UnboundedSolutionException - { "unbounded solution", - "solution non born\u00e9e" }, - - // org.apache.commons.math.geometry.CardanEulerSingularityException - { "Cardan angles singularity", - "singularit\u00e9 d''angles de Cardan" }, - { "Euler angles singularity", - "singularit\u00e9 d''angles d''Euler" }, - - // org.apache.commons.math.geometry.Rotation - { "a {0}x{1} matrix cannot be a rotation matrix", - "une matrice {0}x{1} ne peut pas \u00eatre une matrice de rotation" }, - { "the closest orthogonal matrix has a negative determinant {0}", - "la matrice orthogonale la plus proche a un d\u00e9terminant n\u00e9gatif {0}" }, - { "unable to orthogonalize matrix in {0} iterations", - "impossible de rendre la matrice orthogonale en {0} it\u00e9rations" }, - - // 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})" }, - - // 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})" }, - { "too small integration interval: length = {0}", - "intervalle d''int\u00e9gration trop petit : {0}" }, - - // org.apache.commons.math.ode.MultistepIntegrator - { "{0} method needs at least one previous point", - "la m\u00e9thode {0} n\u00e9cessite au moins un point pr\u00e9c\u00e9dent" }, - - // org.apache.commons.math.ode.ContinuousOutputModel - // org.apache.commons.math.optimization.direct.DirectSearchOptimizer - { "unexpected exception caught", - "exception inattendue lev\u00e9e" }, - { "propagation direction mismatch", - "directions de propagation incoh\u00e9rentes" }, - { "{0} wide hole between models time ranges", - "trou de longueur {0} entre les domaines temporels des mod\u00e8les" }, - - // org.apache.commons.math.optimization.direct.DirectSearchOptimizer - { "none of the {0} start points lead to convergence", - "aucun des {0} points de d\u00e9part n''aboutit \u00e0 une convergence" }, - - // org.apache.commons.math.random.ValueServer - { "unknown mode {0}, known modes: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) and {11} ({12})", - "mode {0} inconnu, modes connus : {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) et {11} ({12})" }, - { "digest not initialized", - "mod\u00e8le empirique non initialis\u00e9" }, - - // org.apache.commons.math.random.EmpiricalDistributionImpl - { "distribution not loaded", - "aucune distribution n''a \u00e9t\u00e9 charg\u00e9e" }, - { "no bin selected", - "aucun compartiment s\u00e9lectionn\u00e9" }, - { "input data comes from unsupported datasource: {0}, supported sources: {1}, {2}", - "les donn\u00e9es d''entr\u00e9e proviennent " + - "d''une source non support\u00e9e : {0}, sources support\u00e9es : {1}, {2}" }, - - // org.apache.commons.math.random.EmpiricalDistributionImpl - // org.apache.commons.math.random.ValueServer - { "URL {0} contains no data", - "l''adresse {0} ne contient aucune donn\u00e9e" }, - - // org.apache.commons.math.random.AbstractRandomGenerator - // org.apache.commons.math.random.BitsStreamGenerator - { "upper bound must be positive ({0})", - "la borne sup\u00e9rieure doit \u00eatre positive ({0})" }, - - // org.apache.commons.math.random.RandomDataImpl - { "length must be positive ({0})", - "la longueur doit \u00eatre positive ({0})" }, - { "upper bound ({0}) must be greater than lower bound ({1})", - "la borne sup\u00e9rieure ({0}) doit \u00eatre sup\u00e9rieure" + - " \u00e0 la borne inf\u00e9rieure ({1})" }, - { "permutation k ({0}) exceeds n ({1})", - "la permutation k ({0}) d\u00e9passe n ({1})" }, - { "permutation k ({0}) must be positive", - "la permutation k ({0}) doit \u00eatre positive" }, - { "sample size ({0}) exceeds collection size ({1})", - "la taille de l''\u00e9chantillon ({0}) d\u00e9passe la taille de la collection ({1})" }, - - // org.apache.commons.math.linear.decomposition.EigenDecompositionImpl - { "cannot solve degree {0} equation", - "impossible de r\u00e9soudre une \u00e9quation de degr\u00e9 {0}" }, - { "eigen decomposition of assymetric matrices not supported yet", - "la d\u00e9composition en valeurs/vecteurs propres de matrices " + - "non sym\u00e9triques n''est pas encore disponible" }, - - // org.apache.commons.math.linear.decomposition.NonSquareMatrixException - // org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression - { "a {0}x{1} matrix was provided instead of a square matrix", - "une matrice {0}x{1} a \u00e9t\u00e9 fournie \u00e0 la place d''une matrice carr\u00e9e" }, - - // org.apache.commons.math.linear.decomposition.SingularMatrixException - { "matrix is singular", - "matrice singuli\u00e8re" }, - - // org.apache.commons.math.linear.decomposition.SingularValueDecompositionImpl - { "cutoff singular value is {0}, should be at most {1}", - "la valeur singuli\u00e8re de coupure vaut {0}, elle ne devrait pas d\u00e9passer {1}" }, - - // org.apache.commons.math.linear.decomposition.CholeskyDecompositionImpl - // org.apache.commons.math.linear.decomposition.EigenDecompositionImpl - // org.apache.commons.math.linear.decomposition.LUDecompositionImpl - // 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 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 - // org.apache.commons.math.linear.decomposition.LUDecompositionImpl - // org.apache.commons.math.linear.decomposition.QRDecompositionImpl - // org.apache.commons.math.linear.decomposition.SingularValueDecompositionImpl - // org.apache.commons.math.linear.ArrayRealVector - // org.apache.commons.math.linear.SparseRealVector - { "vector length mismatch: got {0} but expected {1}", - "taille de vecteur invalide : {0} au lieu de {1} attendue" }, - - // org.apache.commons.math.linear.ArrayRealVector - // org.apache.commons.math.linear.ArrayFieldVector - // org.apache.commons.math.linear.SparseRealVector - { "index {0} out of allowed range [{1}, {2}]", - "index {0} hors de la plage autoris\u00e9e [{1}, {2}]" }, - { "vector must have at least one element", - "un vecteur doit comporter au moins un \u00e9l\u00e9ment" }, - { "position {0} and size {1} don't fit to the size of the input array {2}", - "la position {0} et la taille {1} sont incompatibles avec la taille du tableau d''entr\u00e9e {2}"}, - - // org.apache.commons.math.linear.AbstractRealMatrix - // org.apache.commons.math.linear.AbstractFieldMatrix - { "invalid row dimension: {0} (must be positive)", - "nombre de lignes invalide : {0} (doit \u00eatre positif)" }, - { "invalid column dimension: {0} (must be positive)", - "nombre de colonnes invalide : {0} (doit \u00eatre positif)" }, - { "matrix must have at least one row", - "une matrice doit comporter au moins une ligne" }, - { "matrix must have at least one column", - "une matrice doit comporter au moins une colonne" }, - - // org.apache.commons.math.linear.AbstractRealMatrix - // org.apache.commons.math.linear.AbstractFieldMatrix - // org.apache.commons.math.stat.inference.ChiSquareTestImpl - { "some rows have length {0} while others have length {1}", - "certaines lignes ont une longueur de {0} alors que d''autres ont une longueur de {1}" }, - - // org.apache.commons.math.linear.MatrixUtils - { "row index {0} out of allowed range [{1}, {2}]", - "index de ligne {0} hors de la plage autoris\u00e9e [{1}, {2}]" }, - { "column index {0} out of allowed range [{1}, {2}]", - "index de colonne {0} hors de la plage autoris\u00e9e [{1}, {2}]" }, - { "initial row {0} after final row {1}", - "ligne initiale {0} apr\u00e8s la ligne finale {1}" }, - { "initial column {0} after final column {1}", - "colonne initiale {0} apr\u00e8s la colonne finale {1}" }, - { "empty selected row index array", - "tableau des indices de lignes s\u00e9lectionn\u00e9es vide" }, - { "empty selected column index array", - "tableau des indices de colonnes s\u00e9lectionn\u00e9es vide" }, - { "{0}x{1} and {2}x{3} matrices are not addition compatible", - "les dimensions {0}x{1} et {2}x{3} sont incompatibles pour l'addition matricielle" }, - { "{0}x{1} and {2}x{3} matrices are not subtraction compatible", - "les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la soustraction matricielle" }, - { "{0}x{1} and {2}x{3} matrices are not multiplication compatible", - "les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la multiplication matricielle" }, - - // org.apache.commons.math.linear.BlockRealMatrix - { "wrong array shape (block length = {0}, expected {1})", - "forme de tableau erron\u00e9e (bloc de longueur {0} au lieu des {1} attendus)" }, - - // org.apache.commons.math.complex.Complex - { "cannot compute nth root for null or negative n: {0}", - "impossible de calculer la racine ni\u00e8me pour n n\u00e9gatif ou nul : {0}" }, - - // org.apache.commons.math.complex.ComplexFormat - { "unparseable complex number: \"{0}\"", - "\u00e9chec d''analyse du nombre complexe \"{0}\"" }, - { "cannot format a {0} instance as a complex number", - "impossible de formater une instance de {0} comme un nombre complexe" }, - { "empty string for imaginary character", - "cha\u00eene vide pour le caract\u00e8 imaginaire" }, - { "null imaginary format", - "format imaginaire nul" }, - { "null real format", - "format r\u00e9el nul" }, - - // org.apache.commons.math.complex.ComplexUtils - { "negative complex module {0}", - "module n\u00e9gatif ({0}) pour un nombre complexe" }, - - // org.apache.commons.math.geometry.Vector3DFormat - { "unparseable 3D vector: \"{0}\"", - "\u00e9chec d''analyse du vecteur de dimension 3 \"{0}\"" }, - { "cannot format a {0} instance as a 3D vector", - "impossible de formater une instance de {0} comme un vecteur de dimension 3" }, - - // org.apache.commons.math.linear.RealVectorFormat - { "unparseable real vector: \"{0}\"", - "\u00e9chec d''analyse du vecteur r\u00e9el \"{0}\"" }, - { "cannot format a {0} instance as a real vector", - "impossible de formater une instance de {0} comme un vecteur r\u00e9el" }, - - // org.apache.commons.math.util.ResizableDoubleArray - { "the index specified: {0} is larger than the current maximal index {1}", - "l''index sp\u00e9cifi\u00e9 ({0}) d\u00e9passe l''index maximal courant ({1})" }, - { "elements cannot be retrieved from a negative array index {0}", - "impossible d''extraire un \u00e9l\u00e9ment \u00e0 un index n\u00e9gatif ({0})" }, - { "cannot set an element at a negative index {0}", - "impossible de mettre un \u00e9l\u00e9ment \u00e0 un index n\u00e9gatif ({0})" }, - { "cannot substitute an element from an empty array", - "impossible de substituer un \u00e9l\u00e9ment dans un tableau vide" }, - { "contraction criteria ({0}) smaller than the expansion factor ({1}). This would " + - "lead to a never ending loop of expansion and contraction as a newly expanded " + - "internal storage array would immediately satisfy the criteria for contraction.", - "crit\u00e8re de contraction ({0}) inf\u00e9rieur au facteur d''extension. Ceci " + - "induit une boucle infinie d''extensions/contractions car tout tableau de stockage " + - "fra\u00eechement \u00e9tendu respecte imm\u00e9diatement le crit\u00e8re de contraction."}, - { "contraction criteria smaller than one ({0}). This would lead to a never ending " + - "loop of expansion and contraction as an internal storage array length equal " + - "to the number of elements would satisfy the contraction criteria.", - "crit\u00e8re de contraction inf\u00e9rieur \u00e0 un ({0}). Ceci induit une boucle " + - "infinie d''extensions/contractions car tout tableau de stockage de longueur \u00e9gale " + - "au nombre d''\u00e9l\u00e9ments respecte le crit\u00e8re de contraction." }, - { "expansion factor smaller than one ({0})", - "facteur d''extension inf\u00e9rieur \u00e0 un ({0})"}, - { "cannot discard {0} elements from a {1} elements array", - "impossible d''enlever {0} \u00e9l\u00e9ments d''un tableau en contenant {1}"}, - { "cannot discard a negative number of elements ({0})", - "impossible d''enlever un nombre d''\u00e9l\u00e9ments{0} n\u00e9gatif"}, - { "unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})", - "mode d''extension {0} no support\u00e9, les modes support\u00e9s sont {1} ({2}) et {3} ({4})" }, - { "initial capacity ({0}) is not positive", - "la capacit\u00e9 initiale ({0}) n''est pas positive" }, - { "index ({0}) is not positive", - "l''indice ({0}) n''est pas positif" }, - - // org.apache.commons.math.analysis.polynomials.PolynomialFunction - // org.apache.commons.math.analysis.polynomials.PolynomialFunctionNewtonForm - { "empty polynomials coefficients array", - "tableau de coefficients polyn\u00f4miaux vide" }, - - // org.apache.commons.math.analysis.polynomials.PolynomialFunctionNewtonForm - { "array sizes should have difference 1 ({0} != {1} + 1)", - "les tableaux devraient avoir une diff\u00e9rence de taille de 1 ({0} != {1} + 1)" }, - - // org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm - { "identical abscissas x[{0}] == x[{1}] == {2} cause division by zero", - "division par z\u00e9ro caus\u00e9e par les abscisses identiques x[{0}] == x[{1}] == {2}" }, - - // org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction - { "spline partition must have at least {0} points, got {1}", - "une partiction spline n\u00e9cessite au moins {0} points, seuls {1} ont \u00e9t\u00e9 fournis" }, - { "knot values must be strictly increasing", - "les n\u0153uds d''interpolation doivent \u00eatre strictement croissants" }, - { "number of polynomial interpolants must match the number of segments ({0} != {1} - 1)", - "le nombre d''interpolants polyn\u00f4miaux doit correspondre au nombre de segments ({0} != {1} - 1)" }, - - // org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl - { "function to solve cannot be null", - "la fonction \u00e0 r\u00e9soudre ne peux pas \u00eatre nulle" }, - { "invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}", - "param\u00e8tres de l''intervalle initial invalides : borne inf = {0}, valeur initiale = {1}, borne sup = {2}" }, - - // org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl - // org.apache.commons.math.analysis.solvers.BrentSolver - { "function values at endpoints do not have different signs. Endpoints: [{0}, {1}], Values: [{2}, {3}]", - "les valeurs de la fonction aux bornes n''ont pas des signes diff\u00e9rents. Bornes : [{0}, {1}], valeurs : [{2}, {3}]" }, - - // org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl - // org.apache.commons.math.analysis.integration.UnivariateRealIntegratorImpl - // org.apache.commons.math.transform.FastFourierTransformer - { "endpoints do not specify an interval: [{0}, {1}]", - "les extr\u00e9mit\u00e9s ne constituent pas un intervalle : [{0}, {1}]" }, - - // org.apache.commons.math.analysis.solvers.LaguerreSolver - { "function is not polynomial", - "la fonction n''est pas p\u00f4lynomiale" }, - - // org.apache.commons.math.analysis.solvers.NewtonSolver - { "function is not differentiable", - "la fonction n''est pas diff\u00e9rentiable" }, - - // org.apache.commons.math.analysis.integration.UnivariateRealIntegratorImpl - { "invalid iteration limits: min={0}, max={1}", - "limites d''it\u00e9rations invalides : min = {0}, max = {1}" }, - - // org.apache.commons.math.analysis.integration.LegendreGaussIntegrator - { "{0} points Legendre-Gauss integrator not supported," + - " number of points must be in the {1}-{2} range", - "int\u00e9grateur de Legendre-Gauss non support\u00e9 en {0} points, " + - "le nombre de points doit \u00eatre entre {1} et {2}" }, - - // org.apache.commons.math.fraction.Fraction - { "zero denominator in fraction {0}/{1}", - "d\u00e9nominateur null dans le nombre rationnel {0}/{1}" }, - { "overflow in fraction {0}/{1}, cannot negate", - "d\u00e9passement de capacit\u00e9 pour la fraction {0}/{1}, son signe ne peut \u00eatre chang\u00e9" }, - { "overflow, numerator too large after multiply: {0}", - "d\u00e9passement de capacit\u00e9 pour le num\u00e9rateur apr\u00e8s multiplication : {0}" }, - { "the fraction to divide by must not be zero: {0}/{1}", - "division par un nombre rationnel nul : {0}/{1}" }, - { "null fraction", - "fraction nulle" }, - - // org.apache.commons.math.geometry.Rotation - { "zero norm for rotation axis", - "norme nulle pour un axe de rotation" }, - { "zero norm for rotation defining vector", - "norme nulle pour un axe de d\u00e9finition de rotation" }, - - // org.apache.commons.math.geometry.Vector3D - // org.apache.commons.math.linear.ArrayRealVector - { "cannot normalize a zero norm vector", - "impossible de normer un vecteur de norme nulle" }, - { "zero norm", - "norme nulle" }, - - // org.apache.commons.math.ConvergingAlgorithmImpl - { "no result available", - "aucun r\u00e9sultat n''est disponible" }, - - // org.apache.commons.math.linear.BigMatrixImpl - { "first {0} rows are not initialized yet", - "les {0} premi\u00e8res lignes ne sont pas encore initialis\u00e9es" }, - { "first {0} columns are not initialized yet", - "les {0} premi\u00e8res colonnes ne sont pas encore initialis\u00e9es" }, - - // org.apache.commons.math.stat.Frequency - { "class ({0}) does not implement Comparable", - "la classe ({0}) n''implante pas l''interface Comparable" }, - { "instance of class {0} not comparable to existing values", - "l''instance de la classe {0} n''est pas comparable aux valeurs existantes" }, - - // org.apache.commons.math.stat.StatUtils - { "input arrays must have the same positive length ({0} and {1})", - "les tableaux d''entr\u00e9e doivent avoir la m\u00eame taille positive ({0} et {1})" }, - { "input arrays must have the same length and at least two elements ({0} and {1})", - "les tableaux d''entr\u00e9e doivent avoir la m\u00eame taille" + - " et au moins deux \u00e9l\u00e9ments ({0} et {1})" }, - - // org.apache.commons.math.stat.correlation.Covariance - { "arrays must have the same length and both must have at " + - "least two elements. xArray has size {0}, yArray has {1} elements", - "les tableaux doivent avoir la m\u00eame taille " + - "et comporter au moins deux \u00e9l\u00e9ments. " + - "xArray a une taille de {0}, yArray a {1} \u00e9l\u00e9ments"}, - { "insufficient data: only {0} rows and {1} columns.", - "donn\u00e9es insuffisantes : seulement {0} lignes et {1} colonnes." }, - - // org.apache.commons.math.stat.correlation.PearsonsCorrelation - { "covariance matrix is null", - "la matrice de covariance est nulle" }, - { "invalid array dimensions. xArray has size {0}; yArray has {1} elements", - "dimensions de tableaux invalides. xArray a une taille de {0}, " + - "yArray a {1} \u00e9l\u00e9ments" }, - - // 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 {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]" }, - - // org.apache.commons.math.stat.descriptive.moment.Variance - // org.apache.commons.math.stat.descriptive.moment.SemiVariance - // org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic - // org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic - { "input values array is null", - "le tableau des valeurs d''entr\u00e9es est nul" }, - - // org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic - { "start position cannot be negative ({0})", - "la position de d\u00e9part ne peut pas \u00eatre n\u00e9gative" }, - { "length cannot be negative ({0})", - "la longueur ne peut pas \u00eatre n\u00e9gative" }, - { "subarray ends after array end", - "le sous-tableau se termine apr\u00e8s la fin du tableau" }, - - // org.apache.commons.math.stat.descriptive.moment.GeometricMean - // org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics - // org.apache.commons.math.stat.descriptive.SummaryStatistics - { "{0} values have been added before statistic is configured", - "{0} valeurs ont \u00e9t\u00e9 ajout\u00e9es " + - "avant que la statistique ne soit configur\u00e9e" }, - - // 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" }, - { "statistics constructed from external moments cannot be cleared", - "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", - "le tableau des valeurs attendues a une longueur de {0}, elle devrait \u00eatre au moins de 2" }, - { "observed array length = {0}, must be at least 2", - "le tableau des valeurs observ\u00e9es a une longueur de {0}, elle devrait \u00eatre au moins de 2" }, - { "observed counts are all 0 in first observed array", - "aucune occurrence dans le premier tableau des observations" }, - { "observed counts are all 0 in second observed array", - "aucune occurrence dans le second tableau des observations" }, - { "observed counts are both zero for entry {0}", - "les occurrences observ\u00e9es sont toutes deux nulles pour l'entr\u00e9e {0}" }, - { "invalid row dimension: {0} (must be at least 2)", - "nombre de lignes invalide : {0} (doit \u00eatre au moins de 2)" }, - { "invalid column dimension: {0} (must be at least 2)", - "nombre de colonnes invalide : {0} (doit \u00eatre au moins de 2)" }, - { "element {0} is not positive: {1}", - "l''\u00e9l\u00e9ment {0} n''est pas positif : {1}" }, - { "element {0} is negative: {1}", - "l''\u00e9l\u00e9ment {0} est n\u00e9gatif : {1}" }, - { "element ({0}, {1}) is negative: {2}", - "l''\u00e9l\u00e9ment ({0}, {1}) est n\u00e9gatif : {2}" }, - - // org.apache.commons.math.stat.inference.OneWayAnovaImpl - { "two or more categories required, got {0}", - "deux cat\u00e9gories ou plus sont n\u00e9cessaires, il y en a {0}" }, - { "two or more values required in each category, one has {0}", - "deux valeurs ou plus sont n\u00e9cessaires pour chaque cat\u00e9gorie, une cat\u00e9gorie en a {0}" }, - - // org.apache.commons.math.stat.inference.TTestImpl - { "insufficient data for t statistic, needs at least 2, got {0}", - "deux valeurs ou plus sont n\u00e9cessaires pour la statistique t, il y en a {0}" }, - - // org.apache.commons.math.stat.inference.ChiSquareTestImpl - // org.apache.commons.math.stat.inference.TTestImpl - // org.apache.commons.math.stat.inference.OneWayAnovaImpl - // org.apache.commons.math.stat.Regression - { "out of bounds significance level {0}, must be between {1} and {2}", - "niveau de signification {0} hors domaine, doit \u00eatre entre {1} et {2}" }, - - // org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression - { "not enough data ({0} rows) for this many predictors ({1} predictors)", - "pas assez de donn\u00e9es ({0} lignes) pour {1} pr\u00e9dicteurs" }, - - // org.apache.commons.math.distribution.AbstractContinuousDistribution - // org.apache.commons.math.distribution.AbstractIntegerDistribution - // org.apache.commons.math.distribution.ExponentialDistributionImpl - // org.apache.commons.math.distribution.BinomialDistributionImpl - // org.apache.commons.math.distribution.CauchyDistributionImpl - // org.apache.commons.math.distribution.PascalDistributionImpl - // org.apache.commons.math.distribution.WeibullDistributionImpl - { "{0} out of [{1}, {2}] range", - "{0} hors du domaine [{1}, {2}]" }, - - // org.apache.commons.math.distribution.AbstractDistribution - // org.apache.commons.math.distribution.AbstractIntegerDistribution - { "lower endpoint ({0}) must be less than or equal to upper endpoint ({1})", - "la borne inf\u00e9rieure ({0}) devrait \u00eatre inf\u00e9rieure " + - "ou \u00e9gale \u00e0 la borne sup\u00e9rieure ({1})" }, - - // org.apache.commons.math.distribution.AbstractContinuousDistribution - { "Cumulative probability function returned NaN for argument {0} p = {1}", - "Fonction de probabilit\u00e9 cumulative retourn\u00e9 NaN \u00e0 l''argument de {0} p = {1}" }, - { "This distribution does not have a density function implemented", - "La fonction de densit\u00e9 pour cette distribution n'a pas \u00e9t\u00e9 mis en oeuvre" }, - - // org.apache.commons.math.distribution.AbstractIntegerDistribution - { "Discrete cumulative probability function returned NaN for argument {0}", - "Discr\u00e8tes fonction de probabilit\u00e9 cumulative retourn\u00e9 NaN \u00e0 l''argument de {0}" }, - - // org.apache.commons.math.distribution.AbstractIntegerDistribution - // org.apache.commons.math.distribution.AbstractContinuousDistribution - { "Sample size must be positive", - "La taille de l'\u00e9chantillon doit \u00eatre positive" }, - - // org.apache.commons.math.distribution.BinomialDistributionImpl - { "number of trials must be non-negative ({0})", - "le nombre d''essais ne doit pas \u00eatre n\u00e9gatif ({0})" }, - - // org.apache.commons.math.distribution.ExponentialDistributionImpl - // org.apache.commons.math.random.RandomDataImpl - { "mean must be positive ({0})", - "la moyenne doit \u00eatre positive ({0})" }, - - // org.apache.commons.math.distribution.FDistributionImpl - // org.apache.commons.math.distribution.TDistributionImpl - { "degrees of freedom must be positive ({0})", - "les degr\u00e9s de libert\u00e9 doivent \u00eatre positifs ({0})" }, - - // org.apache.commons.math.distribution.GammaDistributionImpl - { "alpha must be positive ({0})", - "alpha doit \u00eatre positif ({0})" }, - { "beta must be positive ({0})", - "beta doit \u00eatre positif ({0})" }, - - // org.apache.commons.math.distribution.HypergeometricDistributionImpl - { "number of successes ({0}) must be less than or equal to population size ({1})", - "le nombre de succ\u00e8s doit \u00eatre inf\u00e9rieur " + - "ou \u00e9gal \u00e0 la taille de la population ({1})" }, - { "sample size ({0}) must be less than or equal to population size ({1})", - "la taille de l''\u00e9chantillon doit \u00eatre inf\u00e9rieure " + - "ou \u00e9gale \u00e0 la taille de la population ({1})" }, - { "population size must be positive ({0})", - "la taille de la population doit \u00eatre positive ({0})" }, - - // org.apache.commons.math.distribution.HypergeometricDistributionImpl - // org.apache.commons.math.random.RandomDataImpl - { "sample size must be positive ({0})", - "la taille de l''\u00e9chantillon doit \u00eatre positive ({0})" }, - - // org.apache.commons.math.distribution.HypergeometricDistributionImpl - // org.apache.commons.math.distribution.PascalDistributionImpl - { "number of successes must be non-negative ({0})", - "le nombre de succ\u00e8s ne doit pas \u00eatre n\u00e9gatif ({0})" }, - - // org.apache.commons.math.distribution.NormalDistributionImpl - // org.apache.commons.math.random.RandomDataImpl - { "standard deviation must be positive ({0})", - "l''\u00e9cart type doit \u00eatre positif ({0})" }, - - // org.apache.commons.math.distribution.PoissonDistributionImpl - // org.apache.commons.math.random.RandomDataImpl - { "the Poisson mean must be positive ({0})", - "la moyenne de Poisson doit \u00eatre positive ({0})" }, - - // org.apache.commons.math.distribution.WeibullDistributionImpl - { "shape must be positive ({0})", - "le facteur de forme doit \u00eatre positif ({0})" }, - - // org.apache.commons.math.distribution.WeibullDistributionImpl - // org.apache.commons.math.distribution.CauchyDistributionImpl - { "scale must be positive ({0})", - "l''\u00e9chelle doit \u00eatre positive ({0})" }, - - // org.apache.commons.math.distribution.ZipfDistributionImpl - { "invalid number of elements {0} (must be positive)", - "nombre d''\u00e9l\u00e9ments {0} invalide (doit \u00eatre positif)" }, - { "invalid exponent {0} (must be positive)", - "exposant {0} invalide (doit \u00eatre positif)" }, - - // org.apache.commons.math.transform.FastHadamardTransformer - { "{0} is not a power of 2", - "{0} n''est pas une puissance de 2" }, - - // org.apache.commons.math.transform.FastFourierTransformer - { "cannot compute 0-th root of unity, indefinite result", - "impossible de calculer la racine z\u00e9roi\u00e8me de l''unit\u00e9, " + - "r\u00e9sultat ind\u00e9fini" }, - { "roots of unity have not been computed yet", - "les racines de l''unit\u00e9 n''ont pas encore \u00e9t\u00e9 calcul\u00e9es" }, - { "out of range root of unity index {0} (must be in [{1};{2}])", - "index de racine de l''unit\u00e9 hors domaine (devrait \u00eatre dans [{1}; {2}])" }, - { "number of sample is not positive: {0}", - "le nombre d''\u00e9chantillons n''est pas positif : {0}" }, - { "{0} is not a power of 2, consider padding for fix", - "{0} n''est pas une puissance de 2, ajoutez des \u00e9l\u00e9ments pour corriger" }, - { "some dimensions don't match: {0} != {1}", - "certaines dimensions sont incoh\u00e9rentes : {0} != {1}" }, - - // org.apache.commons.math.transform.FastCosineTransformer - { "{0} is not a power of 2 plus one", - "{0} n''est pas une puissance de 2 plus un" }, - - // org.apache.commons.math.transform.FastSineTransformer - { "first element is not 0: {0}", - "le premier \u00e9l\u00e9ment n''est pas nul : {0}" }, - - // org.apache.commons.math.util.OpenIntToDoubleHashMap - { "map has been modified while iterating", - "la table d''adressage a \u00e9t\u00e9 modifi\u00e9e pendant l''it\u00e9ration" }, - { "iterator exhausted", - "it\u00e9ration achev\u00e9e" }, - - // org.apache.commons.math.MathRuntimeException - { "internal error, please fill a bug report at {0}", - "erreur interne, veuillez signaler l''erreur \u00e0 {0}" } - - }; - - /** - * Simple constructor. - */ - public MessagesResources_fr() { - } - - /** - * Get the non-translated/translated messages arrays from this resource bundle. - * @return non-translated/translated messages arrays - */ - @Override - public Object[][] getContents() { - return CONTENTS.clone(); - } - -} diff --git a/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java b/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java index 83bf56f4d..679517ff5 100644 --- a/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java +++ b/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java @@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -113,7 +114,7 @@ public class RombergIntegrator extends UnivariateRealIntegratorImpl { // at most 32 bisection refinements due to higher order divider if (maximalIterationCount > 32) { throw MathRuntimeException.createIllegalArgumentException( - "invalid iteration limits: min={0}, max={1}", + LocalizedFormats.INVALID_ITERATIONS_LIMITS, 0, 32); } } diff --git a/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java b/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java index 0f679e19b..306299c06 100644 --- a/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java +++ b/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java @@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -104,7 +105,7 @@ public class SimpsonIntegrator extends UnivariateRealIntegratorImpl { // at most 64 bisection refinements if (maximalIterationCount > 64) { throw MathRuntimeException.createIllegalArgumentException( - "invalid iteration limits: min={0}, max={1}", + LocalizedFormats.INVALID_ITERATIONS_LIMITS, 0, 64); } } diff --git a/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java b/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java index 514fee089..808143add 100644 --- a/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java +++ b/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java @@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -135,7 +136,7 @@ public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl { // at most 64 bisection refinements if (maximalIterationCount > 64) { throw MathRuntimeException.createIllegalArgumentException( - "invalid iteration limits: min={0}, max={1}", + LocalizedFormats.INVALID_ITERATIONS_LIMITS, 0, 64); } } diff --git a/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java b/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java index 34023646b..3a0b0a5b1 100644 --- a/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java +++ b/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.integration; import org.apache.commons.math.ConvergingAlgorithmImpl; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Provide a default implementation for several generic functions. @@ -66,7 +67,7 @@ public abstract class UnivariateRealIntegratorImpl throws IllegalArgumentException { super(defaultMaximalIterationCount, 1.0e-15); if (f == null) { - throw MathRuntimeException.createIllegalArgumentException("function is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); } this.f = f; @@ -108,7 +109,7 @@ public abstract class UnivariateRealIntegratorImpl if (resultComputed) { return result; } else { - throw MathRuntimeException.createIllegalStateException("no result available"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE); } } @@ -171,7 +172,7 @@ public abstract class UnivariateRealIntegratorImpl protected void verifyIterationCount() throws IllegalArgumentException { if ((minimalIterationCount <= 0) || (maximalIterationCount <= minimalIterationCount)) { throw MathRuntimeException.createIllegalArgumentException( - "invalid iteration limits: min={0}, max={1}", + LocalizedFormats.INVALID_ITERATIONS_LIMITS, minimalIterationCount, maximalIterationCount); } } diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java b/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java index 970ea3c62..2467c9eb5 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolatingFunction.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.analysis.interpolation; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.FunctionEvaluationException; @@ -98,7 +99,7 @@ public class BicubicSplineInterpolatingFunction final int yLen = y.length; if (xLen == 0 || yLen == 0 || f.length == 0 || f[0].length == 0) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xLen != f.length) { throw new DimensionMismatchException(xLen, f.length); @@ -157,13 +158,15 @@ public class BicubicSplineInterpolatingFunction public double value(double x, double y) { final int i = searchIndex(x, xval); if (i == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", - x, xval[0], xval[xval.length - 1]); + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.OUT_OF_RANGE_SIMPLE, + x, xval[0], xval[xval.length - 1]); } final int j = searchIndex(y, yval); if (j == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", - y, yval[0], yval[yval.length - 1]); + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.OUT_OF_RANGE_SIMPLE, + y, yval[0], yval[yval.length - 1]); } final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]); @@ -230,12 +233,12 @@ public class BicubicSplineInterpolatingFunction final int i = searchIndex(x, xval); if (i == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, x, xval[0], xval[xval.length - 1]); } final int j = searchIndex(y, yval); if (j == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, y, yval[0], yval[yval.length - 1]); } @@ -373,11 +376,11 @@ class BicubicSplineFunction */ public double value(double x, double y) { if (x < 0 || x > 1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, x, 0, 1); } if (y < 0 || y > 1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, y, 0, 1); } diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java index 90168b5eb..a2f29fc04 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.interpolation; import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; @@ -39,7 +40,7 @@ public class BicubicSplineInterpolator final double[][] fval) throws MathException, IllegalArgumentException { if (xval.length == 0 || yval.length == 0 || fval.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xval.length != fval.length) { throw new DimensionMismatchException(xval.length, fval.length); diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java index e7d52a080..79c81a3a6 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java @@ -21,6 +21,8 @@ import java.util.Arrays; import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -145,14 +147,12 @@ public class LoessInterpolator */ public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) throws MathException { if (bandwidth < 0 || bandwidth > 1) { - throw new MathException("bandwidth must be in the interval [0,1], but got {0}", + throw new MathException(LocalizedFormats.BANDWIDTH_OUT_OF_INTERVAL, bandwidth); } this.bandwidth = bandwidth; if (robustnessIters < 0) { - throw new MathException("the number of robustness iterations must " + - "be non-negative, but got {0}", - robustnessIters); + throw new MathException(LocalizedFormats.NEGATIVE_ROBUSTNESS_ITERATIONS, robustnessIters); } this.robustnessIters = robustnessIters; this.accuracy = accuracy; @@ -198,22 +198,19 @@ public class LoessInterpolator public final double[] smooth(final double[] xval, final double[] yval, final double[] weights) throws MathException { if (xval.length != yval.length) { - throw new MathException( - "Loess expects the abscissa and ordinate arrays " + - "to be of the same size, " + - "but got {0} abscissae and {1} ordinatae", - xval.length, yval.length); + throw new MathException(LocalizedFormats.MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS, + xval.length, yval.length); } final int n = xval.length; if (n == 0) { - throw new MathException("Loess expects at least 1 point"); + throw new MathException(LocalizedFormats.LOESS_EXPECTS_AT_LEAST_ONE_POINT); } - checkAllFiniteReal(xval, "all abscissae must be finite real numbers, but {0}-th is {1}"); - checkAllFiniteReal(yval, "all ordinatae must be finite real numbers, but {0}-th is {1}"); - checkAllFiniteReal(weights, "all weights must be finite real numbers, but {0}-th is {1}"); + checkAllFiniteReal(xval, LocalizedFormats.NON_REAL_FINITE_ABSCISSA); + checkAllFiniteReal(yval, LocalizedFormats.NON_REAL_FINITE_ORDINATE); + checkAllFiniteReal(weights, LocalizedFormats.NON_REAL_FINITE_WEIGHT); checkStrictlyIncreasing(xval); @@ -228,12 +225,8 @@ public class LoessInterpolator int bandwidthInPoints = (int) (bandwidth * n); if (bandwidthInPoints < 2) { - throw new MathException( - "the bandwidth must be large enough to " + - "accomodate at least 2 points. There are {0} " + - " data points, and bandwidth must be at least {1} " + - " but it is only {2}", - n, 2.0 / n, bandwidth); + throw new MathException(LocalizedFormats.TOO_SMALL_BANDWIDTH, + n, 2.0 / n, bandwidth); } final double[] res = new double[n]; @@ -365,11 +358,8 @@ public class LoessInterpolator public final double[] smooth(final double[] xval, final double[] yval) throws MathException { if (xval.length != yval.length) { - throw new MathException( - "Loess expects the abscissa and ordinate arrays " + - "to be of the same size, " + - "but got {0} abscissae and {1} ordinatae", - xval.length, yval.length); + throw new MathException(LocalizedFormats.MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS, + xval.length, yval.length); } final double[] unitWeights = new double[xval.length]; @@ -442,7 +432,7 @@ public class LoessInterpolator * @param pattern pattern of the error message * @throws MathException if one of the values is not a finite real number */ - private static void checkAllFiniteReal(final double[] values, final String pattern) + private static void checkAllFiniteReal(final double[] values, final Localizable pattern) throws MathException { for (int i = 0; i < values.length; i++) { final double x = values[i]; @@ -464,11 +454,8 @@ public class LoessInterpolator throws MathException { for (int i = 0; i < xval.length; ++i) { if (i >= 1 && xval[i - 1] >= xval[i]) { - throw new MathException( - "the abscissae array must be sorted in a strictly " + - "increasing order, but the {0}-th element is {1} " + - "whereas {2}-th is {3}", - i - 1, xval[i - 1], i, xval[i]); + throw new MathException(LocalizedFormats.OUT_OF_ORDER_ABSCISSA_ARRAY, + i - 1, xval[i - 1], i, xval[i]); } } } diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatingFunction.java b/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatingFunction.java index 2dc9ae611..bf101728d 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatingFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatingFunction.java @@ -27,6 +27,7 @@ import org.apache.commons.math.analysis.MultivariateRealFunction; import org.apache.commons.math.linear.ArrayRealVector; import org.apache.commons.math.linear.RealVector; import org.apache.commons.math.random.UnitSphereRandomVectorGenerator; +import org.apache.commons.math.util.LocalizedFormats; /** * Interpolating function that implements the @@ -150,7 +151,7 @@ public class MicrosphereInterpolatingFunction UnitSphereRandomVectorGenerator rand) throws DimensionMismatchException, IllegalArgumentException { if (xval.length == 0 || xval[0] == null) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xval.length != yval.length) { diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolator.java index 9c41f7a2d..d909aed87 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolator.java @@ -20,6 +20,7 @@ import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.MultivariateRealFunction; import org.apache.commons.math.random.UnitSphereRandomVectorGenerator; +import org.apache.commons.math.util.LocalizedFormats; /** * Interpolator that implements the algorithm described in @@ -100,7 +101,7 @@ public class MicrosphereInterpolator public void setBrightnessExponent(final int brightnessExponent) { if (brightnessExponent < 0) { throw MathRuntimeException.createIllegalArgumentException( - "brightness exponent should be positive or null, but got {0}", + LocalizedFormats.NEGATIVE_BRIGHTNESS_EXPONENT, brightnessExponent); } this.brightnessExponent = brightnessExponent; @@ -114,7 +115,7 @@ public class MicrosphereInterpolator public void setMicropshereElements(final int elements) { if (microsphereElements < 0) { throw MathRuntimeException.createIllegalArgumentException( - "number of microsphere elements must be positive, but got {0}", + LocalizedFormats.NON_POSITIVE_MICROSPHERE_ELEMENTS, microsphereElements); } this.microsphereElements = elements; diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingBicubicSplineInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingBicubicSplineInterpolator.java index 3eaba1857..4a399034e 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingBicubicSplineInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingBicubicSplineInterpolator.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.interpolation; import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; @@ -48,7 +49,7 @@ public class SmoothingBicubicSplineInterpolator final double[][] zval) throws MathException, IllegalArgumentException { if (xval.length == 0 || yval.length == 0 || zval.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xval.length != zval.length) { throw new DimensionMismatchException(xval.length, zval.length); diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java index 770c24697..ea2597865 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.interpolation; import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.optimization.general.GaussNewtonOptimizer; import org.apache.commons.math.optimization.fitting.PolynomialFitter; @@ -71,7 +72,7 @@ public class SmoothingPolynomialBicubicSplineInterpolator final double[][] fval) throws MathException, IllegalArgumentException { if (xval.length == 0 || yval.length == 0 || fval.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xval.length != fval.length) { throw new DimensionMismatchException(xval.length, fval.length); diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java index e1f8bda08..8ed1d9cd6 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.interpolation; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.polynomials.PolynomialFunction; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set. @@ -58,12 +59,12 @@ public class SplineInterpolator implements UnivariateRealInterpolator { public PolynomialSplineFunction interpolate(double x[], double y[]) { if (x.length != y.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", x.length, y.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, x.length, y.length); } if (x.length < 3) { throw MathRuntimeException.createIllegalArgumentException( - "{0} points are required, got only {1}", 3, x.length); + LocalizedFormats.WRONG_NUMBER_OF_POINTS, 3, x.length); } // Number of intervals. The number of data points is n + 1. @@ -72,7 +73,7 @@ public class SplineInterpolator implements UnivariateRealInterpolator { for (int i = 0; i < n; i++) { if (x[i] >= x[i + 1]) { throw MathRuntimeException.createIllegalArgumentException( - "points {0} and {1} are not strictly increasing ({2} >= {3})", + LocalizedFormats.NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS, i, i+1, x[i], x[i+1]); } } diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java b/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java index 8db53372b..9cfbd1ee3 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunction.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.analysis.interpolation; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.DimensionMismatchException; @@ -156,7 +157,7 @@ public class TricubicSplineInterpolatingFunction if (xLen == 0 || yLen == 0 || z.length == 0 || f.length == 0 || f[0].length == 0) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xLen != f.length) { throw new DimensionMismatchException(xLen, f.length); @@ -307,18 +308,21 @@ public class TricubicSplineInterpolatingFunction public double value(double x, double y, double z) { final int i = searchIndex(x, xval); if (i == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", - x, xval[0], xval[xval.length - 1]); + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.OUT_OF_RANGE_SIMPLE, + x, xval[0], xval[xval.length - 1]); } final int j = searchIndex(y, yval); if (j == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", - y, yval[0], yval[yval.length - 1]); + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.OUT_OF_RANGE_SIMPLE, + y, yval[0], yval[yval.length - 1]); } final int k = searchIndex(z, zval); if (k == -1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", - z, zval[0], zval[zval.length - 1]); + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.OUT_OF_RANGE_SIMPLE, + z, zval[0], zval[zval.length - 1]); } final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]); @@ -449,15 +453,15 @@ class TricubicSplineFunction */ public double value(double x, double y, double z) { if (x < 0 || x > 1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, x, 0, 1); } if (y < 0 || y > 1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, y, 0, 1); } if (z < 0 || z > 1) { - throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.OUT_OF_RANGE_SIMPLE, z, 0, 1); } diff --git a/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java b/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java index 2b6ee551e..0a06a09b9 100644 --- a/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java +++ b/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.interpolation; import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -38,7 +39,7 @@ public class TricubicSplineInterpolator final double[][][] fval) throws MathException, IllegalArgumentException { if (xval.length == 0 || yval.length == 0 || zval.length == 0 || fval.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("no data"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NO_DATA); } if (xval.length != fval.length) { throw new DimensionMismatchException(xval.length, fval.length); diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java index d5e70445c..3c351b24c 100644 --- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java @@ -22,6 +22,7 @@ import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Immutable representation of a real polynomial function with real coefficients. @@ -33,10 +34,6 @@ 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"; - /** * Serialization identifier */ @@ -66,7 +63,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction, public PolynomialFunction(double c[]) { super(); if (c.length < 1) { - throw MathRuntimeException.createIllegalArgumentException(EMPTY_ARRAY_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } int l = c.length; while ((l > 1) && (c[l - 1] == 0)) { @@ -126,7 +123,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_ARRAY_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } double result = coefficients[n - 1]; for (int j = n -2; j >=0; j--) { @@ -235,7 +232,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction, protected static double[] differentiate(double[] coefficients) { int n = coefficients.length; if (n < 1) { - throw MathRuntimeException.createIllegalArgumentException(EMPTY_ARRAY_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } if (n == 1) { return new double[]{0}; diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java index 6489991ae..20ce9b484 100644 --- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java +++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java @@ -20,6 +20,7 @@ import org.apache.commons.math.DuplicateSampleAbscissaException; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the representation of a real polynomial function in @@ -90,7 +91,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction { try { return evaluate(x, y, z); } catch (DuplicateSampleAbscissaException e) { - throw new FunctionEvaluationException(e, z, e.getPattern(), e.getArguments()); + throw new FunctionEvaluationException(e, z, e.getLocalizablePattern(), e.getArguments()); } } @@ -297,12 +298,12 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction { if (x.length != y.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", x.length, y.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, x.length, y.length); } if (x.length < 2) { throw MathRuntimeException.createIllegalArgumentException( - "{0} points are required, got only {1}", 2, x.length); + LocalizedFormats.WRONG_NUMBER_OF_POINTS, 2, x.length); } } diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java index d6ca59a27..b33cc6881 100644 --- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java +++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java @@ -19,6 +19,7 @@ package org.apache.commons.math.analysis.polynomials; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the representation of a real polynomial function in @@ -209,11 +210,11 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction { if (a.length < 1 || c.length < 1) { throw MathRuntimeException.createIllegalArgumentException( - "empty polynomials coefficients array"); + LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } if (a.length != c.length + 1) { throw MathRuntimeException.createIllegalArgumentException( - "array sizes should have difference 1 ({0} != {1} + 1)", + LocalizedFormats.ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1, a.length, c.length); } } diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java index b8a3a7822..f03aec7c4 100644 --- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java @@ -22,6 +22,7 @@ import org.apache.commons.math.ArgumentOutsideDomainException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Represents a polynomial spline function. @@ -97,17 +98,17 @@ public class PolynomialSplineFunction public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[]) { if (knots.length < 2) { throw MathRuntimeException.createIllegalArgumentException( - "spline partition must have at least {0} points, got {1}", + LocalizedFormats.NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION, 2, knots.length); } if (knots.length - 1 != polynomials.length) { throw MathRuntimeException.createIllegalArgumentException( - "number of polynomial interpolants must match the number of segments ({0} != {1} - 1)", + LocalizedFormats.POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS, polynomials.length, knots.length); } if (!isStrictlyIncreasing(knots)) { throw MathRuntimeException.createIllegalArgumentException( - "knot values must be strictly increasing"); + LocalizedFormats.NOT_STRICTLY_INCREASING_KNOT_VALUES); } this.n = knots.length -1; diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/BrentSolver.java b/src/main/java/org/apache/commons/math/analysis/solvers/BrentSolver.java index 83c0d91c5..430b7747e 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/BrentSolver.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/BrentSolver.java @@ -21,6 +21,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -43,11 +44,6 @@ public class BrentSolver extends UnivariateRealSolverImpl { */ public static final int DEFAULT_MAXIMUM_ITERATIONS = 100; - /** Error message for non-bracketing interval. */ - private static final String NON_BRACKETING_MESSAGE = - "function values at endpoints do not have different signs. " + - "Endpoints: [{0}, {1}], Values: [{2}, {3}]"; - /** Serializable version identifier */ private static final long serialVersionUID = 7694577816772532779L; @@ -134,7 +130,7 @@ public class BrentSolver extends UnivariateRealSolverImpl { clearResult(); if ((initial < min) || (initial > max)) { throw MathRuntimeException.createIllegalArgumentException( - "invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}", + LocalizedFormats.INVALID_INTERVAL_INITIAL_VALUE_PARAMETERS, min, initial, max); } @@ -170,7 +166,7 @@ public class BrentSolver extends UnivariateRealSolverImpl { } throw MathRuntimeException.createIllegalArgumentException( - NON_BRACKETING_MESSAGE, min, max, yMin, yMax); + LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, min, max, yMin, yMax); } @@ -217,7 +213,7 @@ public class BrentSolver extends UnivariateRealSolverImpl { } else { // neither value is close to zero and min and max do not bracket root. throw MathRuntimeException.createIllegalArgumentException( - NON_BRACKETING_MESSAGE, min, max, yMin, yMax); + LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, min, max, yMin, yMax); } } else if (sign < 0){ // solve using only the first endpoint as initial guess diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java b/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java index 72d0e100c..3d54ad63c 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java @@ -23,6 +23,7 @@ import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialFunction; import org.apache.commons.math.complex.Complex; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -38,14 +39,6 @@ import org.apache.commons.math.complex.Complex; */ 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 */ @@ -69,7 +62,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl { if (f instanceof PolynomialFunction) { p = (PolynomialFunction) f; } else { - throw MathRuntimeException.createIllegalArgumentException(NON_POLYNOMIAL_FUNCTION_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.FUNCTION_NOT_POLYNOMIAL); } } @@ -172,7 +165,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl { // check function type if (!(f instanceof PolynomialFunction)) { - throw MathRuntimeException.createIllegalArgumentException(NON_POLYNOMIAL_FUNCTION_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.FUNCTION_NOT_POLYNOMIAL); } // check for zeros before verifying bracketing @@ -265,7 +258,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl { int iterationCount = 0; if (n < 1) { throw MathRuntimeException.createIllegalArgumentException( - NON_POSITIVE_DEGREE_MESSAGE, n); + LocalizedFormats.NON_POSITIVE_POLYNOMIAL_DEGREE, n); } Complex c[] = new Complex[n+1]; // coefficients for deflated polynomial for (int i = 0; i <= n; i++) { @@ -313,7 +306,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl { int n = coefficients.length - 1; if (n < 1) { throw MathRuntimeException.createIllegalArgumentException( - NON_POSITIVE_DEGREE_MESSAGE, n); + LocalizedFormats.NON_POSITIVE_POLYNOMIAL_DEGREE, n); } Complex N = new Complex(n, 0.0); Complex N1 = new Complex(n - 1, 0.0); diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java b/src/main/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java index 7e4626d31..d9a64c589 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java @@ -22,6 +22,7 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements @@ -129,7 +130,7 @@ public class NewtonSolver extends UnivariateRealSolverImpl { throw new MaxIterationsExceededException(maximalIterationCount); } catch (ClassCastException cce) { - throw MathRuntimeException.createIllegalArgumentException("function is not differentiable"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.FUNCTION_NOT_DIFFERENTIABLE); } } diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java b/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java index 03296bb13..dd58b1b8f 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java @@ -21,6 +21,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -127,9 +128,7 @@ public class SecantSolver extends UnivariateRealSolverImpl { // Verify bracketing if (y0 * y1 >= 0) { throw MathRuntimeException.createIllegalArgumentException( - "function values at endpoints do not have different signs, " + - "endpoints: [{0}, {1}], values: [{2}, {3}]", - min, max, y0, y1); + LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, min, max, y0, y1); } double x2 = x0; diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java index dadbe9469..f4aabe2d8 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java @@ -21,6 +21,7 @@ import org.apache.commons.math.ConvergingAlgorithmImpl; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Provide a default implementation for several functions useful to generic @@ -73,7 +74,7 @@ public abstract class UnivariateRealSolverImpl final double defaultAbsoluteAccuracy) { super(defaultMaximalIterationCount, defaultAbsoluteAccuracy); if (f == null) { - throw MathRuntimeException.createIllegalArgumentException("function to solve cannot be null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); } this.f = f; this.defaultFunctionValueAccuracy = 1.0e-15; @@ -100,7 +101,7 @@ public abstract class UnivariateRealSolverImpl */ protected void checkResultComputed() throws IllegalStateException { if (!resultComputed) { - throw MathRuntimeException.createIllegalStateException("no result available"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE); } } @@ -224,7 +225,7 @@ public abstract class UnivariateRealSolverImpl protected void verifySequence(final double lower, final double initial, final double upper) { if (!isSequence(lower, initial, upper)) { throw MathRuntimeException.createIllegalArgumentException( - "invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}", + LocalizedFormats.INVALID_INTERVAL_INITIAL_VALUE_PARAMETERS, lower, initial, upper); } } @@ -247,8 +248,7 @@ public abstract class UnivariateRealSolverImpl verifyInterval(lower, upper); if (!isBracketing(lower, upper, function)) { throw MathRuntimeException.createIllegalArgumentException( - "function values at endpoints do not have different signs. " + - "Endpoints: [{0}, {1}], Values: [{2}, {3}]", + LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lower, upper, function.value(lower), function.value(upper)); } } diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java index 96fff76c7..576996648 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java @@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Utility routines for {@link UnivariateRealSolver} objects. @@ -28,10 +29,6 @@ import org.apache.commons.math.analysis.UnivariateRealFunction; */ public class UnivariateRealSolverUtils { - /** Message for null function.*/ - private static final String NULL_FUNCTION_MESSAGE = - "function is null"; - /** * Default constructor. */ @@ -173,15 +170,15 @@ public class UnivariateRealSolverUtils { FunctionEvaluationException { if (function == null) { - throw MathRuntimeException.createIllegalArgumentException(NULL_FUNCTION_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); } if (maximumIterations <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "bad value for maximum iterations number: {0}", maximumIterations); + LocalizedFormats.INVALID_MAX_ITERATIONS, maximumIterations); } if (initial < lowerBound || initial > upperBound || lowerBound >= upperBound) { throw MathRuntimeException.createIllegalArgumentException( - "invalid bracketing parameters: lower bound={0}, initial={1}, upper bound={2}", + LocalizedFormats.INVALID_BRACKETING_PARAMETERS, lowerBound, initial, upperBound); } double a = initial; @@ -202,9 +199,7 @@ public class UnivariateRealSolverUtils { if (fa * fb > 0.0 ) { throw new ConvergenceException( - "number of iterations={0}, maximum iterations={1}, " + - "initial={2}, lower bound={3}, upper bound={4}, final a value={5}, " + - "final b value={6}, f(a)={7}, f(b)={8}", + LocalizedFormats.FAILED_BRACKETING, numIterations, maximumIterations, initial, lowerBound, upperBound, a, b, fa, fb); } @@ -230,7 +225,7 @@ public class UnivariateRealSolverUtils { */ private static void setup(UnivariateRealFunction f) { if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(NULL_FUNCTION_MESSAGE); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); } } diff --git a/src/main/java/org/apache/commons/math/complex/Complex.java b/src/main/java/org/apache/commons/math/complex/Complex.java index e0b257a81..c1c61de90 100644 --- a/src/main/java/org/apache/commons/math/complex/Complex.java +++ b/src/main/java/org/apache/commons/math/complex/Complex.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -941,7 +942,7 @@ public class Complex implements FieldElement, Serializable { if (n <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot compute nth root for null or negative n: {0}", + LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } diff --git a/src/main/java/org/apache/commons/math/complex/ComplexFormat.java b/src/main/java/org/apache/commons/math/complex/ComplexFormat.java index d1c6510fa..c9282f5f5 100644 --- a/src/main/java/org/apache/commons/math/complex/ComplexFormat.java +++ b/src/main/java/org/apache/commons/math/complex/ComplexFormat.java @@ -25,6 +25,7 @@ import java.util.Locale; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.util.CompositeFormat; +import org.apache.commons.math.util.LocalizedFormats; /** * Formats a Complex number in cartesian format "Re(c) + Im(c)i". 'i' can @@ -192,7 +193,7 @@ public class ComplexFormat extends CompositeFormat { toAppendTo, pos); } else { throw MathRuntimeException.createIllegalArgumentException( - "cannot format a {0} instance as a complex number", + LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_COMPLEX, obj.getClass().getName()); } @@ -349,7 +350,7 @@ public class ComplexFormat extends CompositeFormat { public void setImaginaryCharacter(String imaginaryCharacter) { if (imaginaryCharacter == null || imaginaryCharacter.length() == 0) { throw MathRuntimeException.createIllegalArgumentException( - "empty string for imaginary character"); + LocalizedFormats.EMPTY_STRING_FOR_IMAGINARY_CHARACTER); } this.imaginaryCharacter = imaginaryCharacter; } @@ -363,7 +364,7 @@ public class ComplexFormat extends CompositeFormat { public void setImaginaryFormat(NumberFormat imaginaryFormat) { if (imaginaryFormat == null) { throw MathRuntimeException.createIllegalArgumentException( - "null imaginary format"); + LocalizedFormats.NULL_IMAGINARY_FORMAT); } this.imaginaryFormat = imaginaryFormat; } @@ -377,7 +378,7 @@ public class ComplexFormat extends CompositeFormat { public void setRealFormat(NumberFormat realFormat) { if (realFormat == null) { throw MathRuntimeException.createIllegalArgumentException( - "null real format"); + LocalizedFormats.NULL_REAL_FORMAT); } this.realFormat = realFormat; } diff --git a/src/main/java/org/apache/commons/math/complex/ComplexUtils.java b/src/main/java/org/apache/commons/math/complex/ComplexUtils.java index 56d0dc557..160b425f8 100644 --- a/src/main/java/org/apache/commons/math/complex/ComplexUtils.java +++ b/src/main/java/org/apache/commons/math/complex/ComplexUtils.java @@ -18,6 +18,7 @@ package org.apache.commons.math.complex; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Static implementations of common @@ -62,7 +63,7 @@ public class ComplexUtils { public static Complex polar2Complex(double r, double theta) { if (r < 0) { throw MathRuntimeException.createIllegalArgumentException( - "negative complex module {0}", r); + LocalizedFormats.NEGATIVE_COMPLEX_MODULE, r); } return new Complex(r * Math.cos(theta), r * Math.sin(theta)); } diff --git a/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java b/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java index b71121358..d2a855686 100644 --- a/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java +++ b/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java @@ -26,6 +26,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.solvers.BrentSolver; import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils; import org.apache.commons.math.random.RandomDataImpl; +import org.apache.commons.math.util.LocalizedFormats; /** * Base class for continuous distributions. Default implementations are @@ -69,7 +70,7 @@ public abstract class AbstractContinuousDistribution */ public double density(double x) throws MathRuntimeException { throw new MathRuntimeException(new UnsupportedOperationException(), - "This distribution does not have a density function implemented"); + LocalizedFormats.NO_DENSITY_FOR_THIS_DISTRIBUTION); } /** @@ -87,7 +88,7 @@ public abstract class AbstractContinuousDistribution throws MathException { if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} out of [{1}, {2}] range", p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } // by default, do simple root finding using bracketing and default solver. @@ -99,11 +100,11 @@ public abstract class AbstractContinuousDistribution try { ret = cumulativeProbability(x) - p; } catch (MathException ex) { - throw new FunctionEvaluationException(ex, x, ex.getPattern(), ex.getArguments()); + throw new FunctionEvaluationException(ex, x, ex.getLocalizablePattern(), ex.getArguments()); } if (Double.isNaN(ret)) { throw new FunctionEvaluationException(x, - "Cumulative probability function returned NaN for argument {0} p = {1}", x, p); + LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p); } return ret; } @@ -176,7 +177,7 @@ public abstract class AbstractContinuousDistribution */ public double[] sample(int sampleSize) throws MathException { if (sampleSize <= 0) { - MathRuntimeException.createIllegalArgumentException("Sample size must be positive"); + MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_POSITIVE_SAMPLE_SIZE, sampleSize); } double[] out = new double[sampleSize]; for (int i = 0; i < sampleSize; i++) { diff --git a/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java b/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java index 14f4f3414..696351c87 100644 --- a/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java +++ b/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java @@ -20,6 +20,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Base class for probability distributions. @@ -60,7 +61,7 @@ public abstract class AbstractDistribution throws MathException { if (x0 > x1) { throw MathRuntimeException.createIllegalArgumentException( - "lower endpoint ({0}) must be less than or equal to upper endpoint ({1})", + LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1); } return cumulativeProbability(x1) - cumulativeProbability(x0); diff --git a/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java b/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java index eea53e029..fdd52e2a9 100644 --- a/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java +++ b/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java @@ -22,6 +22,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.random.RandomDataImpl; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -34,15 +35,7 @@ import org.apache.commons.math.random.RandomDataImpl; 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 */ + /** Serializable version identifier */ private static final long serialVersionUID = -1146319659338487221L; /** @@ -95,7 +88,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution throws MathException { if (x0 > x1) { throw MathRuntimeException.createIllegalArgumentException( - WRONG_ORDER_ENDPOINTS_MESSAGE, x0, x1); + LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1); } if (Math.floor(x0) < x0) { return cumulativeProbability(((int) Math.floor(x0)) + 1, @@ -152,7 +145,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution public double cumulativeProbability(int x0, int x1) throws MathException { if (x0 > x1) { throw MathRuntimeException.createIllegalArgumentException( - WRONG_ORDER_ENDPOINTS_MESSAGE, x0, x1); + LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1); } return cumulativeProbability(x1) - cumulativeProbability(x0 - 1); } @@ -171,7 +164,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( - OUT_OF_RANGE_POINT, p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } // by default, do simple bisection. @@ -250,7 +243,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution */ public int[] sample(int sampleSize) throws MathException { if (sampleSize <= 0) { - MathRuntimeException.createIllegalArgumentException("Sample size must be positive"); + MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_POSITIVE_SAMPLE_SIZE, sampleSize); } int[] out = new int[sampleSize]; for (int i = 0; i < sampleSize; i++) { @@ -274,11 +267,11 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution try { result = cumulativeProbability(argument); } catch (MathException ex) { - throw new FunctionEvaluationException(ex, argument, ex.getPattern(), ex.getArguments()); + throw new FunctionEvaluationException(ex, argument, ex.getLocalizablePattern(), ex.getArguments()); } if (Double.isNaN(result)) { throw new FunctionEvaluationException(argument, - "Discrete cumulative probability function returned NaN for argument {0}", argument); + LocalizedFormats.DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN, argument); } return result; } diff --git a/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java index 1e492da62..564b4c01d 100644 --- a/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.special.Beta; +import org.apache.commons.math.util.LocalizedFormats; /** * The default implementation of {@link BinomialDistribution}. @@ -92,7 +93,7 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution private void setNumberOfTrialsInternal(int trials) { if (trials < 0) { throw MathRuntimeException.createIllegalArgumentException( - "number of trials must be non-negative ({0})", trials); + LocalizedFormats.NEGATIVE_NUMBER_OF_TRIALS, trials); } numberOfTrials = trials; } @@ -119,7 +120,7 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution private void setProbabilityOfSuccessInternal(double p) { if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} out of [{1}, {2}] range", p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } probabilityOfSuccess = p; } diff --git a/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java index 1851c3287..129176412 100644 --- a/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.distribution; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Default implementation of @@ -136,7 +137,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution double ret; if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} out of [{1}, {2}] range", p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } else if (p == 0) { ret = Double.NEGATIVE_INFINITY; } else if (p == 1) { @@ -182,7 +183,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution private void setScaleInternal(double s) { if (s <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "scale must be positive ({0})", s); + LocalizedFormats.NOT_POSITIVE_SCALE, s); } scale = s; } diff --git a/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java index 1720b240b..80a4f7fed 100644 --- a/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java @@ -20,6 +20,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * The default implementation of {@link ExponentialDistribution}. @@ -83,7 +84,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution private void setMeanInternal(double newMean) { if (newMean <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "mean must be positive ({0})", newMean); + LocalizedFormats.NOT_POSITIVE_MEAN, newMean); } this.mean = newMean; } @@ -165,7 +166,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} out of [{1}, {2}] range", p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } else if (p == 1.0) { ret = Double.POSITIVE_INFINITY; } else { diff --git a/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java index 814221091..5e88cb853 100644 --- a/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.special.Beta; +import org.apache.commons.math.util.LocalizedFormats; /** * Default implementation of @@ -38,10 +39,6 @@ public class FDistributionImpl */ public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9; - /** 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; @@ -222,7 +219,7 @@ public class FDistributionImpl private void setNumeratorDegreesOfFreedomInternal(double degreesOfFreedom) { if (degreesOfFreedom <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE, degreesOfFreedom); + LocalizedFormats.NOT_POSITIVE_DEGREES_OF_FREEDOM, degreesOfFreedom); } this.numeratorDegreesOfFreedom = degreesOfFreedom; } @@ -256,7 +253,7 @@ public class FDistributionImpl private void setDenominatorDegreesOfFreedomInternal(double degreesOfFreedom) { if (degreesOfFreedom <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE, degreesOfFreedom); + LocalizedFormats.NOT_POSITIVE_DEGREES_OF_FREEDOM, degreesOfFreedom); } this.denominatorDegreesOfFreedom = degreesOfFreedom; } diff --git a/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java index 2dd5361ac..7ac64fd10 100644 --- a/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.special.Gamma; +import org.apache.commons.math.util.LocalizedFormats; /** * The default implementation of {@link GammaDistribution}. @@ -145,7 +146,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution private void setAlphaInternal(double newAlpha) { if (newAlpha <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "alpha must be positive ({0})", + LocalizedFormats.NOT_POSITIVE_ALPHA, newAlpha); } this.alpha = newAlpha; @@ -178,7 +179,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution private void setBetaInternal(double newBeta) { if (newBeta <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "beta must be positive ({0})", + LocalizedFormats.NOT_POSITIVE_BETA, newBeta); } this.beta = newBeta; diff --git a/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java index 56c84cb3e..6a484bc40 100644 --- a/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.distribution; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -56,13 +57,13 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution if (numberOfSuccesses > populationSize) { throw MathRuntimeException .createIllegalArgumentException( - "number of successes ({0}) must be less than or equal to population size ({1})", + LocalizedFormats.NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE, numberOfSuccesses, populationSize); } if (sampleSize > populationSize) { throw MathRuntimeException .createIllegalArgumentException( - "sample size ({0}) must be less than or equal to population size ({1})", + LocalizedFormats.SAMPLE_SIZE_LARGER_THAN_POPULATION_SIZE, sampleSize, populationSize); } @@ -249,7 +250,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution private void setNumberOfSuccessesInternal(int num) { if (num < 0) { throw MathRuntimeException.createIllegalArgumentException( - "number of successes must be non-negative ({0})", num); + LocalizedFormats.NEGATIVE_NUMBER_OF_SUCCESSES, num); } numberOfSuccesses = num; } @@ -274,7 +275,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution private void setPopulationSizeInternal(int size) { if (size <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "population size must be positive ({0})", size); + LocalizedFormats.NOT_POSITIVE_POPULATION_SIZE, size); } populationSize = size; } @@ -299,7 +300,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution private void setSampleSizeInternal(int size) { if (size < 0) { throw MathRuntimeException.createIllegalArgumentException( - "sample size must be positive ({0})", size); + LocalizedFormats.NOT_POSITIVE_SAMPLE_SIZE, size); } sampleSize = size; } diff --git a/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java index 3d521297f..e4b4e663e 100644 --- a/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java @@ -23,6 +23,7 @@ import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.special.Erf; +import org.apache.commons.math.util.LocalizedFormats; /** * Default implementation of @@ -138,7 +139,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution private void setStandardDeviationInternal(double sd) { if (sd <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "standard deviation must be positive ({0})", + LocalizedFormats.NOT_POSITIVE_STANDARD_DEVIATION, sd); } standardDeviation = sd; diff --git a/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java index 78e03e11e..8a71c137a 100644 --- a/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.special.Beta; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -88,7 +89,7 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution private void setNumberOfSuccessesInternal(int successes) { if (successes < 0) { throw MathRuntimeException.createIllegalArgumentException( - "number of successes must be non-negative ({0})", + LocalizedFormats.NEGATIVE_NUMBER_OF_SUCCESSES, successes); } numberOfSuccesses = successes; @@ -114,7 +115,7 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution private void setProbabilityOfSuccessInternal(double p) { if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} out of [{1}, {2}] range", p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } probabilityOfSuccess = p; } diff --git a/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java index b227237d8..cdc4f127f 100644 --- a/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.special.Gamma; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -168,7 +169,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution double p) { if (p <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "the Poisson mean must be positive ({0})", p); + LocalizedFormats.NOT_POSITIVE_POISSON_MEAN, p); } mean = p; normal = z; diff --git a/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java index ad74e0e1d..c16186c98 100644 --- a/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.special.Beta; import org.apache.commons.math.special.Gamma; +import org.apache.commons.math.util.LocalizedFormats; /** * Default implementation of @@ -87,7 +88,7 @@ public class TDistributionImpl private void setDegreesOfFreedomInternal(double newDegreesOfFreedom) { if (newDegreesOfFreedom <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "degrees of freedom must be positive ({0})", + LocalizedFormats.NOT_POSITIVE_DEGREES_OF_FREEDOM, newDegreesOfFreedom); } this.degreesOfFreedom = newDegreesOfFreedom; diff --git a/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java index d63b9757b..30cedd3d8 100644 --- a/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.distribution; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Default implementation of @@ -149,7 +150,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution double ret; if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} out of [{1}, {2}] range", p, 0.0, 1.0); + LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } else if (p == 0) { ret = 0.0; } else if (p == 1) { @@ -176,7 +177,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution private void setShapeInternal(double alpha) { if (alpha <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "shape must be positive ({0})", + LocalizedFormats.NOT_POSITIVE_SHAPE, alpha); } this.shape = alpha; @@ -198,7 +199,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution private void setScaleInternal(double beta) { if (beta <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "scale must be positive ({0})", + LocalizedFormats.NOT_POSITIVE_SCALE, beta); } this.scale = beta; diff --git a/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java index 7728e5a62..457d8d1ba 100644 --- a/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.distribution; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Implementation for the {@link ZipfDistribution}. @@ -87,8 +88,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution throws IllegalArgumentException { if (n <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "invalid number of elements {0} (must be positive)", - n); + LocalizedFormats.INSUFFICIENT_DIMENSION, n, 0); } this.numberOfElements = n; } @@ -127,7 +127,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution throws IllegalArgumentException { if (s <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "invalid exponent {0} (must be positive)", + LocalizedFormats.NOT_POSITIVE_EXPONENT, s); } this.exponent = s; diff --git a/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java b/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java index b9a78cdad..eaefc5783 100644 --- a/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java +++ b/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java @@ -23,6 +23,7 @@ import org.apache.commons.math.linear.InvalidMatrixException; import org.apache.commons.math.linear.LUDecompositionImpl; import org.apache.commons.math.linear.MatrixUtils; import org.apache.commons.math.linear.RealMatrix; +import org.apache.commons.math.util.LocalizedFormats; /** * Base class for implementing estimators. @@ -150,7 +151,7 @@ public abstract class AbstractEstimator implements Estimator { throws EstimationException { if (++costEvaluations > maxCostEval) { - throw new EstimationException("maximal number of evaluations exceeded ({0})", + throw new EstimationException(LocalizedFormats.MAX_EVALUATIONS_EXCEEDED, maxCostEval); } @@ -237,7 +238,7 @@ public abstract class AbstractEstimator implements Estimator { new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj)).getSolver().getInverse(); return inverse.getData(); } catch (InvalidMatrixException ime) { - throw new EstimationException("unable to compute covariances: singular problem"); + throw new EstimationException(LocalizedFormats.UNABLE_TO_COMPUTE_COVARIANCE_SINGULAR_PROBLEM); } } @@ -257,7 +258,7 @@ public abstract class AbstractEstimator implements Estimator { int p = problem.getUnboundParameters().length; if (m <= p) { throw new EstimationException( - "no degrees of freedom ({0} measurements, {1} parameters)", + LocalizedFormats.NO_DEGREES_OF_FREEDOM, m, p); } double[] errors = new double[problem.getUnboundParameters().length]; diff --git a/src/main/java/org/apache/commons/math/estimation/EstimationException.java b/src/main/java/org/apache/commons/math/estimation/EstimationException.java index b76d7d0ab..25dacafc9 100644 --- a/src/main/java/org/apache/commons/math/estimation/EstimationException.java +++ b/src/main/java/org/apache/commons/math/estimation/EstimationException.java @@ -18,6 +18,8 @@ package org.apache.commons.math.estimation; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; /** * This class represents exceptions thrown by the estimation solvers. @@ -42,6 +44,16 @@ extends MathException { * @param parts to insert in the format (no translation) */ public EstimationException(String specifier, Object ... parts) { + this(new DummyLocalizable(specifier), parts); + } + + /** + * Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + */ + public EstimationException(Localizable specifier, Object ... parts) { super(specifier, parts); } diff --git a/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java b/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java index ec8e52144..078432b38 100644 --- a/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java +++ b/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java @@ -25,6 +25,7 @@ import org.apache.commons.math.linear.MatrixUtils; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.RealVector; import org.apache.commons.math.linear.ArrayRealVector; +import org.apache.commons.math.util.LocalizedFormats; /** * This class implements a solver for estimation problems. @@ -213,7 +214,7 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa } } catch(InvalidMatrixException e) { - throw new EstimationException("unable to solve: singular problem"); + throw new EstimationException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM); } diff --git a/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java b/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java index 16119d4cd..44d802b52 100644 --- a/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java +++ b/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java @@ -19,6 +19,8 @@ package org.apache.commons.math.estimation; import java.io.Serializable; import java.util.Arrays; +import org.apache.commons.math.util.LocalizedFormats; + /** * This class solves a least squares problem. @@ -821,7 +823,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se } if (Double.isInfinite(norm2) || Double.isNaN(norm2)) { throw new EstimationException( - "unable to perform Q.R decomposition on the {0}x{1} jacobian matrix", + LocalizedFormats.UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JACOBIAN, rows, cols); } if (norm2 > ak2) { diff --git a/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java b/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java index 59f3ab9d1..ea155e3ee 100644 --- a/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java @@ -24,6 +24,7 @@ import java.text.ParsePosition; import java.util.Locale; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Common part shared by both {@link FractionFormat} and {@link BigFractionFormat}. @@ -119,7 +120,7 @@ public abstract class AbstractFormat extends NumberFormat implements Serializabl public void setDenominatorFormat(final NumberFormat format) { if (format == null) { throw MathRuntimeException.createIllegalArgumentException( - "denominator format can not be null"); + LocalizedFormats.NULL_DENOMINATOR_FORMAT); } this.denominatorFormat = format; } @@ -133,7 +134,7 @@ public abstract class AbstractFormat extends NumberFormat implements Serializabl public void setNumeratorFormat(final NumberFormat format) { if (format == null) { throw MathRuntimeException.createIllegalArgumentException( - "numerator format can not be null"); + LocalizedFormats.NULL_NUMERATOR_FORMAT); } this.numeratorFormat = format; } diff --git a/src/main/java/org/apache/commons/math/fraction/BigFraction.java b/src/main/java/org/apache/commons/math/fraction/BigFraction.java index b7633050f..fdfd180ab 100644 --- a/src/main/java/org/apache/commons/math/fraction/BigFraction.java +++ b/src/main/java/org/apache/commons/math/fraction/BigFraction.java @@ -22,6 +22,7 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -80,10 +81,6 @@ 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"; - /** BigInteger representation of 100. */ private static final BigInteger ONE_HUNDRED_DOUBLE = BigInteger.valueOf(100); @@ -123,13 +120,13 @@ public class BigFraction */ public BigFraction(BigInteger num, BigInteger den) { if (num == null) { - throw MathRuntimeException.createNullPointerException("numerator is null"); + throw MathRuntimeException.createNullPointerException(LocalizedFormats.NULL_NUMERATOR); } if (den == null) { - throw MathRuntimeException.createNullPointerException("denominator is null"); + throw MathRuntimeException.createNullPointerException(LocalizedFormats.NULL_DENOMINATOR); } if (BigInteger.ZERO.equals(den)) { - throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } if (BigInteger.ZERO.equals(num)) { numerator = BigInteger.ZERO; @@ -179,10 +176,10 @@ public class BigFraction */ public BigFraction(final double value) throws IllegalArgumentException { if (Double.isNaN(value)) { - throw MathRuntimeException.createIllegalArgumentException("cannot convert NaN value"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NAN_VALUE_CONVERSION); } if (Double.isInfinite(value)) { - throw MathRuntimeException.createIllegalArgumentException("cannot convert infinite value"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.INFINITE_VALUE_CONVERSION); } // compute m and k such that value = m * 2^k @@ -619,7 +616,7 @@ public class BigFraction */ public BigFraction divide(final BigInteger bg) { if (BigInteger.ZERO.equals(bg)) { - throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } return new BigFraction(numerator, denominator.multiply(bg)); } @@ -672,7 +669,7 @@ public class BigFraction */ public BigFraction divide(final BigFraction fraction) { if (BigInteger.ZERO.equals(fraction.numerator)) { - throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } return multiply(fraction.reciprocal()); diff --git a/src/main/java/org/apache/commons/math/fraction/BigFractionFormat.java b/src/main/java/org/apache/commons/math/fraction/BigFractionFormat.java index de1a3c19d..a04d57afd 100644 --- a/src/main/java/org/apache/commons/math/fraction/BigFractionFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/BigFractionFormat.java @@ -26,6 +26,7 @@ import java.text.ParsePosition; import java.util.Locale; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Formats a BigFraction number in proper format or improper format. @@ -174,7 +175,7 @@ public class BigFractionFormat extends AbstractFormat implements Serializable { toAppendTo, pos); } else { throw MathRuntimeException.createIllegalArgumentException( - "cannot format given object as a fraction number"); + LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION); } return ret; diff --git a/src/main/java/org/apache/commons/math/fraction/Fraction.java b/src/main/java/org/apache/commons/math/fraction/Fraction.java index 285c3fe04..8c614c6b6 100644 --- a/src/main/java/org/apache/commons/math/fraction/Fraction.java +++ b/src/main/java/org/apache/commons/math/fraction/Fraction.java @@ -21,6 +21,7 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -77,18 +78,6 @@ 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; @@ -265,12 +254,12 @@ public class Fraction public Fraction(int num, int den) { if (den == 0) { throw MathRuntimeException.createArithmeticException( - ZERO_DENOMINATOR_MESSAGE, num, den); + LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION, num, den); } if (den < 0) { if (num == Integer.MIN_VALUE || den == Integer.MIN_VALUE) { throw MathRuntimeException.createArithmeticException( - OVERFLOW_MESSAGE, num, den); + LocalizedFormats.OVERFLOW_IN_FRACTION, num, den); } num = -num; den = -den; @@ -413,7 +402,7 @@ public class Fraction public Fraction negate() { if (numerator==Integer.MIN_VALUE) { throw MathRuntimeException.createArithmeticException( - OVERFLOW_MESSAGE, numerator, denominator); + LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator); } return new Fraction(-numerator, denominator); } @@ -484,7 +473,7 @@ public class Fraction */ private Fraction addSub(Fraction fraction, boolean isAdd) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); } // zero is identity for addition. if (numerator == 0) { @@ -521,7 +510,7 @@ public class Fraction // result is (t/d2) / (u'/d1)(v'/d2) BigInteger w = t.divide(BigInteger.valueOf(d2)); if (w.bitLength() > 31) { - throw MathRuntimeException.createArithmeticException("overflow, numerator too large after multiply: {0}", + throw MathRuntimeException.createArithmeticException(LocalizedFormats.NUMERATOR_OVERFLOW_AFTER_MULTIPLY, w); } return new Fraction (w.intValue(), @@ -541,7 +530,7 @@ public class Fraction */ public Fraction multiply(Fraction fraction) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); } if (numerator == 0 || fraction.numerator == 0) { return ZERO; @@ -576,11 +565,11 @@ public class Fraction */ public Fraction divide(Fraction fraction) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); } if (fraction.numerator == 0) { throw MathRuntimeException.createArithmeticException( - "the fraction to divide by must not be zero: {0}/{1}", + LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY, fraction.numerator, fraction.denominator); } return multiply(fraction.reciprocal()); @@ -609,7 +598,7 @@ public class Fraction public static Fraction getReducedFraction(int numerator, int denominator) { if (denominator == 0) { throw MathRuntimeException.createArithmeticException( - ZERO_DENOMINATOR_MESSAGE, numerator, denominator); + LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION, numerator, denominator); } if (numerator==0) { return ZERO; // normalize zero. @@ -622,7 +611,7 @@ public class Fraction if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { throw MathRuntimeException.createArithmeticException( - OVERFLOW_MESSAGE, numerator, denominator); + LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator); } numerator = -numerator; denominator = -denominator; diff --git a/src/main/java/org/apache/commons/math/fraction/FractionConversionException.java b/src/main/java/org/apache/commons/math/fraction/FractionConversionException.java index 8673e1bba..838662320 100644 --- a/src/main/java/org/apache/commons/math/fraction/FractionConversionException.java +++ b/src/main/java/org/apache/commons/math/fraction/FractionConversionException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.fraction; import org.apache.commons.math.ConvergenceException; +import org.apache.commons.math.util.LocalizedFormats; /** * Error thrown when a double value cannot be converted to a fraction @@ -38,7 +39,7 @@ public class FractionConversionException extends ConvergenceException { * @param maxIterations maximal number of iterations allowed */ public FractionConversionException(double value, int maxIterations) { - super("Unable to convert {0} to fraction after {1} iterations", value, maxIterations); + super(LocalizedFormats.FAILED_FRACTION_CONVERSION, value, maxIterations); } /** @@ -49,7 +50,7 @@ public class FractionConversionException extends ConvergenceException { * @param q current denominator */ public FractionConversionException(double value, long p, long q) { - super("Overflow trying to convert {0} to fraction ({1}/{2})", value, p, q); + super(LocalizedFormats.FRACTION_CONVERSION_OVERFLOW, value, p, q); } } diff --git a/src/main/java/org/apache/commons/math/fraction/FractionFormat.java b/src/main/java/org/apache/commons/math/fraction/FractionFormat.java index 002c442d7..eb209639c 100644 --- a/src/main/java/org/apache/commons/math/fraction/FractionFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/FractionFormat.java @@ -25,6 +25,7 @@ import java.util.Locale; import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Formats a Fraction number in proper format or improper format. The number @@ -180,12 +181,12 @@ public class FractionFormat extends AbstractFormat { toAppendTo, pos); } catch (ConvergenceException ex) { throw MathRuntimeException.createIllegalArgumentException( - "cannot convert given object to a fraction number: {0}", + LocalizedFormats.CANNOT_CONVERT_OBJECT_TO_FRACTION, ex.getLocalizedMessage()); } } else { throw MathRuntimeException.createIllegalArgumentException( - "cannot format given object as a fraction number"); + LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION); } return ret; diff --git a/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java b/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java index e6486859e..cbaef2c83 100644 --- a/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java @@ -22,6 +22,7 @@ import java.text.NumberFormat; import java.text.ParsePosition; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Formats a BigFraction number in proper format. The number format for each of @@ -233,7 +234,7 @@ public class ProperBigFractionFormat extends BigFractionFormat { public void setWholeFormat(final NumberFormat format) { if (format == null) { throw MathRuntimeException.createIllegalArgumentException( - "whole format can not be null"); + LocalizedFormats.NULL_WHOLE_FORMAT); } this.wholeFormat = format; } diff --git a/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java b/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java index 03f08ecb5..f40192f19 100644 --- a/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java @@ -21,6 +21,7 @@ import java.text.NumberFormat; import java.text.ParsePosition; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -226,7 +227,7 @@ public class ProperFractionFormat extends FractionFormat { public void setWholeFormat(NumberFormat format) { if (format == null) { throw MathRuntimeException.createIllegalArgumentException( - "whole format can not be null"); + LocalizedFormats.NULL_WHOLE_FORMAT); } this.wholeFormat = format; } diff --git a/src/main/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java b/src/main/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java index 65271a228..0c6210ed7 100644 --- a/src/main/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java +++ b/src/main/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.geometry; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; /** This class represents exceptions thrown while extractiong Cardan * or Euler angles from a rotation. @@ -38,7 +39,7 @@ public class CardanEulerSingularityException * if false it is related to EulerAngles */ public CardanEulerSingularityException(boolean isCardan) { - super(isCardan ? "Cardan angles singularity" : "Euler angles singularity"); + super(isCardan ? LocalizedFormats.CARDAN_ANGLES_SINGULARITY : LocalizedFormats.EULER_ANGLES_SINGULARITY); } } diff --git a/src/main/java/org/apache/commons/math/geometry/NotARotationMatrixException.java b/src/main/java/org/apache/commons/math/geometry/NotARotationMatrixException.java index 6622b0a07..579b18691 100644 --- a/src/main/java/org/apache/commons/math/geometry/NotARotationMatrixException.java +++ b/src/main/java/org/apache/commons/math/geometry/NotARotationMatrixException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.geometry; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.Localizable; /** * This class represents exceptions thrown while building rotations @@ -38,9 +39,22 @@ public class NotARotationMatrixException * Build an exception by translating and formating a message * @param specifier format specifier (to be translated) * @param parts to insert in the format (no translation) + * @deprecated as of 2.2 replaced by {@link #NotARotationMatrixException(Localizable, Object...)} */ + @Deprecated public NotARotationMatrixException(String specifier, Object ... parts) { super(specifier, parts); } + /** + * Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + * @since 2.2 + */ + public NotARotationMatrixException(Localizable specifier, Object ... parts) { + super(specifier, parts); + } + } diff --git a/src/main/java/org/apache/commons/math/geometry/Rotation.java b/src/main/java/org/apache/commons/math/geometry/Rotation.java index 555fd249f..a05579431 100644 --- a/src/main/java/org/apache/commons/math/geometry/Rotation.java +++ b/src/main/java/org/apache/commons/math/geometry/Rotation.java @@ -20,6 +20,7 @@ package org.apache.commons.math.geometry; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * This class implements rotations in a three-dimensional space. @@ -172,7 +173,7 @@ public class Rotation implements Serializable { double norm = axis.getNorm(); if (norm == 0) { - throw MathRuntimeException.createArithmeticException("zero norm for rotation axis"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_AXIS); } double halfAngle = -0.5 * angle; @@ -222,7 +223,7 @@ public class Rotation implements Serializable { if ((m.length != 3) || (m[0].length != 3) || (m[1].length != 3) || (m[2].length != 3)) { throw new NotARotationMatrixException( - "a {0}x{1} matrix cannot be a rotation matrix", + LocalizedFormats.ROTATION_MATRIX_DIMENSIONS, m.length, m[0].length); } @@ -235,7 +236,7 @@ public class Rotation implements Serializable { ort[2][0] * (ort[0][1] * ort[1][2] - ort[1][1] * ort[0][2]); if (det < 0.0) { throw new NotARotationMatrixException( - "the closest orthogonal matrix has a negative determinant {0}", + LocalizedFormats.CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT, det); } @@ -316,7 +317,7 @@ public class Rotation implements Serializable { double v1v1 = Vector3D.dotProduct(v1, v1); double v2v2 = Vector3D.dotProduct(v2, v2); if ((u1u1 == 0) || (u2u2 == 0) || (v1v1 == 0) || (v2v2 == 0)) { - throw MathRuntimeException.createIllegalArgumentException("zero norm for rotation defining vector"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR); } double u1x = u1.getX(); @@ -447,7 +448,7 @@ public class Rotation implements Serializable { double normProduct = u.getNorm() * v.getNorm(); if (normProduct == 0) { - throw MathRuntimeException.createIllegalArgumentException("zero norm for rotation defining vector"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR); } double dot = Vector3D.dotProduct(u, v); @@ -1035,7 +1036,7 @@ public class Rotation implements Serializable { // the algorithm did not converge after 10 iterations throw new NotARotationMatrixException( - "unable to orthogonalize matrix in {0} iterations", + LocalizedFormats.UNABLE_TO_ORTHOGONOLIZE_MATRIX, i - 1); } diff --git a/src/main/java/org/apache/commons/math/geometry/Vector3D.java b/src/main/java/org/apache/commons/math/geometry/Vector3D.java index d7850ef61..25e11a014 100644 --- a/src/main/java/org/apache/commons/math/geometry/Vector3D.java +++ b/src/main/java/org/apache/commons/math/geometry/Vector3D.java @@ -20,6 +20,7 @@ package org.apache.commons.math.geometry; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -283,7 +284,7 @@ public class Vector3D public Vector3D normalize() { double s = getNorm(); if (s == 0) { - throw MathRuntimeException.createArithmeticException("cannot normalize a zero norm vector"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR); } return scalarMultiply(1 / s); } @@ -307,7 +308,7 @@ public class Vector3D double threshold = 0.6 * getNorm(); if (threshold == 0) { - throw MathRuntimeException.createArithmeticException("zero norm"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM); } if ((x >= -threshold) && (x <= threshold)) { @@ -337,7 +338,7 @@ public class Vector3D double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { - throw MathRuntimeException.createArithmeticException("zero norm"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM); } double dot = dotProduct(v1, v2); diff --git a/src/main/java/org/apache/commons/math/geometry/Vector3DFormat.java b/src/main/java/org/apache/commons/math/geometry/Vector3DFormat.java index e3e21dd26..4a9d94852 100644 --- a/src/main/java/org/apache/commons/math/geometry/Vector3DFormat.java +++ b/src/main/java/org/apache/commons/math/geometry/Vector3DFormat.java @@ -25,6 +25,7 @@ import java.util.Locale; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.util.CompositeFormat; +import org.apache.commons.math.util.LocalizedFormats; /** * Formats a 3D vector in components list format "{x; y; z}". @@ -241,7 +242,7 @@ public class Vector3DFormat extends CompositeFormat { return format( (Vector3D)obj, toAppendTo, pos); } - throw MathRuntimeException.createIllegalArgumentException("cannot format a {0} instance as a 3D vector", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_3D_VECTOR, obj.getClass().getName()); } diff --git a/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java index 18a8abe4b..89f25f612 100644 --- a/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java @@ -23,6 +23,7 @@ import java.util.Arrays; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Basic implementation of {@link FieldMatrix} methods regardless of the underlying storage. @@ -64,15 +65,13 @@ public abstract class AbstractFieldMatrix> implements protected AbstractFieldMatrix(final Field field, final int rowDimension, final int columnDimension) throws IllegalArgumentException { - if (rowDimension <= 0 ) { + if (rowDimension < 1 ) { throw MathRuntimeException.createIllegalArgumentException( - "invalid row dimension {0} (must be positive)", - rowDimension); + LocalizedFormats.INSUFFICIENT_DIMENSION, rowDimension, 1); } - if (columnDimension <= 0) { + if (columnDimension < 1) { throw MathRuntimeException.createIllegalArgumentException( - "invalid column dimension {0} (must be positive)", - columnDimension); + LocalizedFormats.INSUFFICIENT_DIMENSION, columnDimension, 1); } this.field = field; } @@ -87,10 +86,10 @@ public abstract class AbstractFieldMatrix> implements protected static > Field extractField(final T[][] d) throws IllegalArgumentException { if (d.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } if (d[0].length == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } return d[0][0].getField(); } @@ -105,7 +104,7 @@ public abstract class AbstractFieldMatrix> implements protected static > Field extractField(final T[] d) throws IllegalArgumentException { if (d.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } return d[0].getField(); } @@ -338,7 +337,7 @@ public abstract class AbstractFieldMatrix> implements final int columnsCount = endColumn + 1 - startColumn; if ((destination.length < rowsCount) || (destination[0].length < columnsCount)) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, destination.length, destination[0].length, rowsCount, columnsCount); } @@ -380,7 +379,7 @@ public abstract class AbstractFieldMatrix> implements if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, destination.length, destination[0].length, selectedRows.length, selectedColumns.length); } @@ -401,18 +400,18 @@ public abstract class AbstractFieldMatrix> implements final int nRows = subMatrix.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[r].length); } } @@ -454,7 +453,7 @@ public abstract class AbstractFieldMatrix> implements if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { @@ -487,7 +486,7 @@ public abstract class AbstractFieldMatrix> implements if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } for (int i = 0; i < nRows; ++i) { @@ -510,7 +509,7 @@ public abstract class AbstractFieldMatrix> implements final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { @@ -533,7 +532,7 @@ public abstract class AbstractFieldMatrix> implements final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, vector.getDimension(), 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { @@ -565,7 +564,7 @@ public abstract class AbstractFieldMatrix> implements final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { @@ -597,7 +596,7 @@ public abstract class AbstractFieldMatrix> implements final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, array.length, 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { @@ -676,7 +675,7 @@ public abstract class AbstractFieldMatrix> implements final int nCols = getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols); } @@ -703,7 +702,7 @@ public abstract class AbstractFieldMatrix> implements final int nCols = getColumnDimension(); if (v.getDimension() != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.getDimension(), nCols); } @@ -728,7 +727,7 @@ public abstract class AbstractFieldMatrix> implements final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows); } @@ -756,7 +755,7 @@ public abstract class AbstractFieldMatrix> implements final int nCols = getColumnDimension(); if (v.getDimension() != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.getDimension(), nRows); } @@ -1054,14 +1053,14 @@ public abstract class AbstractFieldMatrix> implements checkRowIndex(startRow); checkRowIndex(endRow); if (startRow > endRow) { - throw new MatrixIndexException("initial row {0} after final row {1}", + throw new MatrixIndexException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW, startRow, endRow); } checkColumnIndex(startColumn); checkColumnIndex(endColumn); if (startColumn > endColumn) { - throw new MatrixIndexException("initial column {0} after final column {1}", + throw new MatrixIndexException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN, startColumn, endColumn); } @@ -1079,9 +1078,9 @@ public abstract class AbstractFieldMatrix> implements protected void checkSubMatrixIndex(final int[] selectedRows, final int[] selectedColumns) { if (selectedRows.length * selectedColumns.length == 0) { if (selectedRows.length == 0) { - throw new MatrixIndexException("empty selected row index array"); + throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY); } - throw new MatrixIndexException("empty selected column index array"); + throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY); } for (final int row : selectedRows) { @@ -1101,7 +1100,7 @@ public abstract class AbstractFieldMatrix> implements if ((getRowDimension() != m.getRowDimension()) || (getColumnDimension() != m.getColumnDimension())) { throw MathRuntimeException.createIllegalArgumentException( - "{0}x{1} and {2}x{3} matrices are not addition compatible", + LocalizedFormats.NOT_ADDITION_COMPATIBLE_MATRICES, getRowDimension(), getColumnDimension(), m.getRowDimension(), m.getColumnDimension()); } @@ -1116,7 +1115,7 @@ public abstract class AbstractFieldMatrix> implements if ((getRowDimension() != m.getRowDimension()) || (getColumnDimension() != m.getColumnDimension())) { throw MathRuntimeException.createIllegalArgumentException( - "{0}x{1} and {2}x{3} matrices are not subtraction compatible", + LocalizedFormats.NOT_SUBTRACTION_COMPATIBLE_MATRICES, getRowDimension(), getColumnDimension(), m.getRowDimension(), m.getColumnDimension()); } @@ -1130,7 +1129,7 @@ public abstract class AbstractFieldMatrix> implements protected void checkMultiplicationCompatible(final FieldMatrix m) { if (getColumnDimension() != m.getRowDimension()) { throw MathRuntimeException.createIllegalArgumentException( - "{0}x{1} and {2}x{3} matrices are not multiplication compatible", + LocalizedFormats.NOT_MULTIPLICATION_COMPATIBLE_MATRICES, getRowDimension(), getColumnDimension(), m.getRowDimension(), m.getColumnDimension()); } diff --git a/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java b/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java index 10b41592c..45df22629 100644 --- a/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -53,15 +54,13 @@ public abstract class AbstractRealMatrix implements RealMatrix { */ protected AbstractRealMatrix(final int rowDimension, final int columnDimension) throws IllegalArgumentException { - if (rowDimension <= 0 ) { + if (rowDimension < 1 ) { throw MathRuntimeException.createIllegalArgumentException( - "invalid row dimension {0} (must be positive)", - rowDimension); + LocalizedFormats.INSUFFICIENT_DIMENSION, rowDimension, 1); } if (columnDimension <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "invalid column dimension {0} (must be positive)", - columnDimension); + LocalizedFormats.INSUFFICIENT_DIMENSION, columnDimension, 1); } lu = null; } @@ -311,7 +310,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int columnsCount = endColumn + 1 - startColumn; if ((destination.length < rowsCount) || (destination[0].length < columnsCount)) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, destination.length, destination[0].length, rowsCount, columnsCount); } @@ -353,7 +352,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, destination.length, destination[0].length, selectedRows.length, selectedColumns.length); } @@ -374,18 +373,18 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nRows = subMatrix.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[r].length); } } @@ -429,7 +428,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { @@ -462,7 +461,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } for (int i = 0; i < nRows; ++i) { @@ -485,7 +484,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { @@ -508,7 +507,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, vector.getDimension(), 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { @@ -540,7 +539,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { @@ -572,7 +571,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, array.length, 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { @@ -677,7 +676,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nCols = getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols); } @@ -704,7 +703,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nCols = getColumnDimension(); if (v.getDimension() != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.getDimension(), nCols); } @@ -729,7 +728,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows); } @@ -757,7 +756,7 @@ public abstract class AbstractRealMatrix implements RealMatrix { final int nCols = getColumnDimension(); if (v.getDimension() != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.getDimension(), nRows); } diff --git a/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java b/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java index e17254367..8a0d1a683 100644 --- a/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java +++ b/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java @@ -25,6 +25,7 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.BinaryFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.ComposableFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * This class provides default basic implementations for many methods in the @@ -56,8 +57,7 @@ public abstract class AbstractRealVector implements RealVector { double d = getDimension(); if (d != n) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", - d, n); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, d, n); } } diff --git a/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java index 064e37406..72bc466a6 100644 --- a/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java @@ -22,6 +22,7 @@ import java.io.Serializable; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Implementation of FieldMatrix using a {@link FieldElement}[][] array to store entries. @@ -39,26 +40,6 @@ public class Array2DRowFieldMatrix> 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; @@ -132,17 +113,17 @@ public class Array2DRowFieldMatrix> extends AbstractFi final int nRows = d.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_ROW_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_COLUMN_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; r++) { if (d[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, d[r].length); + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[r].length); } } data = d; @@ -327,28 +308,28 @@ public class Array2DRowFieldMatrix> extends AbstractFi if (data == null) { if (row > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} rows are not initialized yet", row); + LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); } if (column > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} columns are not initialized yet", column); + LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); } final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_ROW_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_COLUMN_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_COLUMN); } data = buildArray(getField(), subMatrix.length, nCols); for (int i = 0; i < data.length; ++i) { if (subMatrix[i].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, subMatrix[i].length); + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[i].length); } System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols); } @@ -366,7 +347,7 @@ public class Array2DRowFieldMatrix> extends AbstractFi return data[row][column]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -378,7 +359,7 @@ public class Array2DRowFieldMatrix> extends AbstractFi data[row][column] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -390,7 +371,7 @@ public class Array2DRowFieldMatrix> extends AbstractFi data[row][column] = data[row][column].add(increment); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -402,7 +383,7 @@ public class Array2DRowFieldMatrix> extends AbstractFi data[row][column] = data[row][column].multiply(factor); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -426,7 +407,7 @@ public class Array2DRowFieldMatrix> extends AbstractFi final int nCols = this.getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - VECTOR_LENGTHS_MISMATCH, v.length, nCols); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols); } final T[] out = buildArray(getField(), nRows); for (int row = 0; row < nRows; row++) { @@ -449,7 +430,7 @@ public class Array2DRowFieldMatrix> extends AbstractFi final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - VECTOR_LENGTHS_MISMATCH, v.length, nRows); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows); } final T[] out = buildArray(getField(), nCols); diff --git a/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java b/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java index b40cd3ede..94e10d151 100644 --- a/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java @@ -20,6 +20,7 @@ package org.apache.commons.math.linear; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Implementation of RealMatrix using a double[][] array to store entries and @@ -54,26 +55,6 @@ 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[][]; @@ -141,17 +122,17 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ final int nRows = d.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_ROW_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_COLUMN_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; r++) { if (d[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, d[r].length); + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[r].length); } } data = d; @@ -335,28 +316,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); + LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); } if (column > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} columns are not initialized yet", column); + LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); } final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_ROW_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException( - AT_LEAST_ONE_COLUMN_MESSAGE); + LocalizedFormats.AT_LEAST_ONE_COLUMN); } data = new double[subMatrix.length][nCols]; for (int i = 0; i < data.length; ++i) { if (subMatrix[i].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, subMatrix[i].length); + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[i].length); } System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols); } @@ -374,7 +355,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ return data[row][column]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -386,7 +367,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ data[row][column] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -398,7 +379,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ data[row][column] += increment; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -410,7 +391,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ data[row][column] *= factor; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -434,7 +415,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ final int nCols = this.getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - VECTOR_LENGTHS_MISMATCH, v.length, nCols); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols); } final double[] out = new double[nRows]; for (int row = 0; row < nRows; row++) { @@ -457,7 +438,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - VECTOR_LENGTHS_MISMATCH, v.length, nRows); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows); } final double[] out = new double[nCols]; diff --git a/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java b/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java index 80c3d5ec9..99f4edc09 100644 --- a/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java +++ b/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java @@ -23,6 +23,7 @@ import java.util.Arrays; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * This class implements the {@link FieldVector} interface with a {@link FieldElement} array. @@ -88,7 +89,7 @@ public class ArrayFieldVector> implements FieldVector< data = d.clone(); } catch (ArrayIndexOutOfBoundsException e) { throw MathRuntimeException.createIllegalArgumentException( - "vector must have at least one element"); + LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } } @@ -113,7 +114,7 @@ public class ArrayFieldVector> implements FieldVector< data = copyArray ? d.clone() : d; } catch (ArrayIndexOutOfBoundsException e) { throw MathRuntimeException.createIllegalArgumentException( - "vector must have at least one element"); + LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } } @@ -126,7 +127,7 @@ public class ArrayFieldVector> implements FieldVector< public ArrayFieldVector(T[] 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}", + LocalizedFormats.POSITION_SIZE_MISMATCH_INPUT_ARRAY, pos, size, d.length); } field = d[0].getField(); @@ -215,7 +216,7 @@ public class ArrayFieldVector> implements FieldVector< field = data[0].getField(); } catch (ArrayIndexOutOfBoundsException e) { throw MathRuntimeException.createIllegalArgumentException( - "vector must have at least one element"); + LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } } @@ -715,7 +716,7 @@ public class ArrayFieldVector> implements FieldVector< throws IllegalArgumentException { if (data.length != n) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, data.length, n); } } diff --git a/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java b/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java index 522ffc79e..5a5123e2a 100644 --- a/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java +++ b/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Iterator; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -30,10 +31,6 @@ import org.apache.commons.math.util.MathUtils; */ public class ArrayRealVector extends AbstractRealVector implements 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; @@ -103,7 +100,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable throw new NullPointerException(); } if (d.length == 0) { - throw MathRuntimeException.createIllegalArgumentException("vector must have at least one element"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } data = copyArray ? d.clone() : d; } @@ -117,7 +114,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable public ArrayRealVector(double[] d, int pos, int size) { if (d.length < pos + size) { throw MathRuntimeException.createIllegalArgumentException( - NON_FITTING_POSITION_AND_SIZE_MESSAGE, pos, size, d.length); + LocalizedFormats.POSITION_SIZE_MISMATCH_INPUT_ARRAY, pos, size, d.length); } data = new double[size]; System.arraycopy(d, pos, data, 0, size); @@ -143,7 +140,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable public ArrayRealVector(Double[] d, int pos, int size) { if (d.length < pos + size) { throw MathRuntimeException.createIllegalArgumentException( - NON_FITTING_POSITION_AND_SIZE_MESSAGE, pos, size, d.length); + LocalizedFormats.POSITION_SIZE_MISMATCH_INPUT_ARRAY, pos, size, d.length); } data = new double[size]; for (int i = pos; i < pos + size; i++) { @@ -910,7 +907,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable public RealVector unitVector() throws ArithmeticException { final double norm = getNorm(); if (norm == 0) { - throw MathRuntimeException.createArithmeticException("zero norm"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM); } return mapDivide(norm); } @@ -920,7 +917,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable public void unitize() throws ArithmeticException { final double norm = getNorm(); if (norm == 0) { - throw MathRuntimeException.createArithmeticException("cannot normalize a zero norm vector"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR); } mapDivideToSelf(norm); } @@ -1135,7 +1132,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable throws IllegalArgumentException { if (data.length != n) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, data.length, n); } } diff --git a/src/main/java/org/apache/commons/math/linear/BigMatrixImpl.java b/src/main/java/org/apache/commons/math/linear/BigMatrixImpl.java index 9d5d2bfdb..8155fcae6 100644 --- a/src/main/java/org/apache/commons/math/linear/BigMatrixImpl.java +++ b/src/main/java/org/apache/commons/math/linear/BigMatrixImpl.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.math.BigDecimal; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Implementation of {@link BigMatrix} using a BigDecimal[][] array to store entries @@ -101,15 +102,13 @@ public class BigMatrixImpl implements BigMatrix, Serializable { * positive */ public BigMatrixImpl(int rowDimension, int columnDimension) { - if (rowDimension <= 0 ) { + if (rowDimension < 1 ) { throw MathRuntimeException.createIllegalArgumentException( - "invalid row dimension {0} (must be positive)", - rowDimension); + LocalizedFormats.INSUFFICIENT_DIMENSION, rowDimension, 1); } - if (columnDimension <= 0) { + if (columnDimension < 1) { throw MathRuntimeException.createIllegalArgumentException( - "invalid column dimension {0} (must be positive)", - columnDimension); + LocalizedFormats.INSUFFICIENT_DIMENSION, columnDimension, 1); } data = new BigDecimal[rowDimension][columnDimension]; lu = null; @@ -156,17 +155,17 @@ public class BigMatrixImpl implements BigMatrix, Serializable { } final int nRows = d.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } 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}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[r].length); } } @@ -189,17 +188,17 @@ public class BigMatrixImpl implements BigMatrix, Serializable { public BigMatrixImpl(double[][] d) { final int nRows = d.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int row = 1; row < nRows; row++) { if (d[row].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[row].length); } } @@ -219,17 +218,17 @@ public class BigMatrixImpl implements BigMatrix, Serializable { public BigMatrixImpl(String[][] d) { final int nRows = d.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int row = 1; row < nRows; row++) { if (d[row].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[row].length); } } @@ -604,14 +603,14 @@ public class BigMatrixImpl implements BigMatrix, Serializable { MatrixUtils.checkRowIndex(this, startRow); MatrixUtils.checkRowIndex(this, endRow); if (startRow > endRow) { - throw new MatrixIndexException("initial row {0} after final row {1}", + throw new MatrixIndexException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW, startRow, endRow); } MatrixUtils.checkColumnIndex(this, startColumn); MatrixUtils.checkColumnIndex(this, endColumn); if (startColumn > endColumn) { - throw new MatrixIndexException("initial column {0} after final column {1}", + throw new MatrixIndexException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN, startColumn, endColumn); } @@ -643,9 +642,9 @@ public class BigMatrixImpl implements BigMatrix, Serializable { if (selectedRows.length * selectedColumns.length == 0) { if (selectedRows.length == 0) { - throw new MatrixIndexException("empty selected row index array"); + throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY); } - throw new MatrixIndexException("empty selected column index array"); + throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY); } final BigDecimal[][] subMatrixData = @@ -703,18 +702,18 @@ public class BigMatrixImpl implements BigMatrix, Serializable { final int nRows = subMatrix.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; r++) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[r].length); } } @@ -722,12 +721,12 @@ public class BigMatrixImpl implements BigMatrix, Serializable { if (data == null) { if (row > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} rows are not initialized yet", + LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); } if (column > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} columns are not initialized yet", + LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); } data = new BigDecimal[nRows][nCols]; @@ -881,7 +880,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable { return data[row][column]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1027,7 +1026,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable { public BigDecimal[] operate(BigDecimal[] v) throws IllegalArgumentException { if (v.length != getColumnDimension()) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, getColumnDimension() ); } final int nRows = this.getRowDimension(); @@ -1069,7 +1068,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable { final int nRows = this.getRowDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows ); } final int nCols = this.getColumnDimension(); @@ -1099,7 +1098,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable { final int nRows = this.getRowDimension(); if (b.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.length, nRows); } final BigMatrix bMatrix = new BigMatrixImpl(b); @@ -1144,7 +1143,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable { public BigMatrix solve(BigMatrix b) throws IllegalArgumentException, InvalidMatrixException { if (b.getRowDimension() != getRowDimension()) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), getRowDimension(), "n"); } if (!isSquare()) { diff --git a/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java index 6ccd0f0b2..86a6cc410 100644 --- a/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java @@ -22,6 +22,7 @@ import java.io.Serializable; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Cache-friendly implementation of FieldMatrix using a flat arrays to store @@ -218,7 +219,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa final int length = rawData[i].length; if (length != columns) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, columns, length); } } @@ -809,7 +810,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa // safety checks final int refLength = subMatrix[0].length; if (refLength < 1) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final int endRow = row + subMatrix.length - 1; final int endColumn = column + refLength - 1; @@ -817,7 +818,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (final T[] subRow : subMatrix) { if (subRow.length != refLength) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, refLength, subRow.length); } } @@ -917,7 +918,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } @@ -1006,7 +1007,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } @@ -1134,7 +1135,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, array.length, 1, nCols); } @@ -1185,7 +1186,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, array.length, 1, nRows, 1); } @@ -1216,7 +1217,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa return blocks[iBlock * blockColumns + jBlock][k]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1233,7 +1234,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa blocks[iBlock * blockColumns + jBlock][k] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1251,7 +1252,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa blockIJ[k] = blockIJ[k].add(increment); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1269,7 +1270,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa blockIJ[k] = blockIJ[k].multiply(factor); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1334,7 +1335,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa if (v.length != columns) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, columns); } final T[] out = buildArray(getField(), rows); @@ -1380,7 +1381,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa if (v.length != rows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, rows); } final T[] out = buildArray(getField(), columns); diff --git a/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java b/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java index 9ed9356bc..145f88352 100644 --- a/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java +++ b/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Cache-friendly implementation of RealMatrix using a flat arrays to store @@ -167,7 +168,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int jBlock = 0; jBlock < blockColumns; ++jBlock, ++index) { if (blockData[index].length != iHeight * blockWidth(jBlock)) { throw MathRuntimeException.createIllegalArgumentException( - "wrong array shape (block length = {0}, expected {1})", + LocalizedFormats.WRONG_BLOCK_LENGTH, blockData[index].length, iHeight * blockWidth(jBlock)); } if (copyArray) { @@ -213,7 +214,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final int length = rawData[i].length; if (length != columns) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, columns, length); } } @@ -835,7 +836,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable // safety checks final int refLength = subMatrix[0].length; if (refLength < 1) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final int endRow = row + subMatrix.length - 1; final int endColumn = column + refLength - 1; @@ -843,7 +844,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (final double[] subRow : subMatrix) { if (subRow.length != refLength) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, refLength, subRow.length); } } @@ -943,7 +944,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } @@ -1032,7 +1033,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } @@ -1160,7 +1161,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, array.length, 1, nCols); } @@ -1211,7 +1212,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, array.length, 1, nRows, 1); } @@ -1242,7 +1243,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable return blocks[iBlock * blockColumns + jBlock][k]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1259,7 +1260,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable blocks[iBlock * blockColumns + jBlock][k] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1276,7 +1277,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable blocks[iBlock * blockColumns + jBlock][k] += increment; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1293,7 +1294,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable blocks[iBlock * blockColumns + jBlock][k] *= factor; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -1358,7 +1359,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable if (v.length != columns) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, columns); } final double[] out = new double[rows]; @@ -1402,7 +1403,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable if (v.length != rows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, rows); } final double[] out = new double[columns]; diff --git a/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java b/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java index 7794a6f50..bed62be26 100644 --- a/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java +++ b/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -212,7 +213,7 @@ public class CholeskyDecompositionImpl implements CholeskyDecomposition { final int m = lTData.length; if (b.length != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.length, m); } @@ -251,7 +252,7 @@ public class CholeskyDecompositionImpl implements CholeskyDecomposition { final int m = lTData.length; if (b.getDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.getDimension(), m); } @@ -300,7 +301,7 @@ public class CholeskyDecompositionImpl implements CholeskyDecomposition { final int m = lTData.length; if (b.getRowDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), m, "n"); } diff --git a/src/main/java/org/apache/commons/math/linear/EigenDecompositionImpl.java b/src/main/java/org/apache/commons/math/linear/EigenDecompositionImpl.java index 4c061fc7d..a00888659 100644 --- a/src/main/java/org/apache/commons/math/linear/EigenDecompositionImpl.java +++ b/src/main/java/org/apache/commons/math/linear/EigenDecompositionImpl.java @@ -19,6 +19,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxIterationsExceededException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -102,7 +103,7 @@ public class EigenDecompositionImpl implements EigenDecomposition { // NOT supported // see issue https://issues.apache.org/jira/browse/MATH-235 throw new InvalidMatrixException( - "eigen decomposition of assymetric matrices not supported yet"); + LocalizedFormats.ASSYMETRIC_EIGEN_NOT_SUPPORTED); } } @@ -291,7 +292,7 @@ public class EigenDecompositionImpl implements EigenDecomposition { final int m = realEigenvalues.length; if (b.length != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.length, m); } @@ -333,7 +334,7 @@ public class EigenDecompositionImpl implements EigenDecomposition { final int m = realEigenvalues.length; if (b.getDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", b + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b .getDimension(), m); } @@ -376,7 +377,7 @@ public class EigenDecompositionImpl implements EigenDecomposition { if (b.getRowDimension() != m) { throw MathRuntimeException .createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), m, "n"); } diff --git a/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java b/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java index 04f1eab07..f835c6a73 100644 --- a/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java +++ b/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java @@ -22,6 +22,7 @@ import java.lang.reflect.Array; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Calculates the LUP-decomposition of a square matrix. @@ -263,7 +264,7 @@ public class FieldLUDecompositionImpl> implements Fiel final int m = pivot.length; if (b.length != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.length, m); } if (singular) { @@ -309,7 +310,7 @@ public class FieldLUDecompositionImpl> implements Fiel final int m = pivot.length; if (b.getDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.getDimension(), m); } if (singular) { @@ -365,7 +366,7 @@ public class FieldLUDecompositionImpl> implements Fiel final int m = pivot.length; if (b.getRowDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), m, "n"); } if (singular) { diff --git a/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java b/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java index 4f572c8f4..dcd0bdec8 100644 --- a/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java +++ b/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java @@ -18,6 +18,8 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; /** * Thrown when a system attempts an operation on a matrix, and @@ -28,7 +30,7 @@ import org.apache.commons.math.MathRuntimeException; public class InvalidMatrixException extends MathRuntimeException { /** Serializable version identifier. */ - private static final long serialVersionUID = 1135533765052675495L; + private static final long serialVersionUID = -2068020346562029801L; /** * Construct an exception with the given message. @@ -37,6 +39,16 @@ public class InvalidMatrixException extends MathRuntimeException { * @since 2.0 */ public InvalidMatrixException(final String pattern, final Object ... arguments) { + this(new DummyLocalizable(pattern), arguments); + } + + /** + * Construct an exception with the given message. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public InvalidMatrixException(final Localizable pattern, final Object ... arguments) { super(pattern, arguments); } diff --git a/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java b/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java index 87db6a1d3..c5bdb07b0 100644 --- a/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java +++ b/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Calculates the LUP-decomposition of a square matrix. @@ -36,10 +37,6 @@ 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[][]; @@ -266,7 +263,7 @@ public class LUDecompositionImpl implements LUDecomposition { final int m = pivot.length; if (b.length != m) { throw MathRuntimeException.createIllegalArgumentException( - VECTOR_LENGTH_MISMATCH_MESSAGE, b.length, m); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.length, m); } if (singular) { throw new SingularMatrixException(); @@ -310,7 +307,7 @@ public class LUDecompositionImpl implements LUDecomposition { final int m = pivot.length; if (b.getDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - VECTOR_LENGTH_MISMATCH_MESSAGE, b.getDimension(), m); + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.getDimension(), m); } if (singular) { throw new SingularMatrixException(); @@ -364,7 +361,7 @@ public class LUDecompositionImpl implements LUDecomposition { final int m = pivot.length; if (b.getRowDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), m, "n"); } if (singular) { diff --git a/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java b/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java index a4716b80a..27adacad0 100644 --- a/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java +++ b/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java @@ -18,6 +18,8 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; /** * Thrown when an operation addresses a matrix coordinate (row, col) @@ -27,7 +29,7 @@ import org.apache.commons.math.MathRuntimeException; public class MatrixIndexException extends MathRuntimeException { /** Serializable version identifier */ - private static final long serialVersionUID = -2382324504109300625L; + private static final long serialVersionUID = 8120540015829487660L; /** * Constructs a new instance with specified formatted detail message. @@ -35,6 +37,16 @@ public class MatrixIndexException extends MathRuntimeException { * @param arguments format arguments */ public MatrixIndexException(final String pattern, final Object ... arguments) { + this(new DummyLocalizable(pattern), arguments); + } + + /** + * Constructs a new instance with specified formatted detail message. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.0 + */ + public MatrixIndexException(final Localizable pattern, final Object ... arguments) { super(pattern, arguments); } diff --git a/src/main/java/org/apache/commons/math/linear/MatrixUtils.java b/src/main/java/org/apache/commons/math/linear/MatrixUtils.java index 82daebc42..387848020 100644 --- a/src/main/java/org/apache/commons/math/linear/MatrixUtils.java +++ b/src/main/java/org/apache/commons/math/linear/MatrixUtils.java @@ -29,6 +29,7 @@ import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.fraction.BigFraction; import org.apache.commons.math.fraction.Fraction; +import org.apache.commons.math.util.LocalizedFormats; /** * A collection of static methods that operate on or return matrices. @@ -352,7 +353,7 @@ public class MatrixUtils { createRowFieldMatrix(final T[] rowData) { final int nCols = rowData.length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final FieldMatrix m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { @@ -451,7 +452,7 @@ public class MatrixUtils { createColumnFieldMatrix(final T[] columnData) { final int nRows = columnData.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { @@ -564,14 +565,14 @@ public class MatrixUtils { checkRowIndex(m, startRow); checkRowIndex(m, endRow); if (startRow > endRow) { - throw new MatrixIndexException("initial row {0} after final row {1}", + throw new MatrixIndexException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW, startRow, endRow); } checkColumnIndex(m, startColumn); checkColumnIndex(m, endColumn); if (startColumn > endColumn) { - throw new MatrixIndexException("initial column {0} after final column {1}", + throw new MatrixIndexException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN, startColumn, endColumn); } @@ -592,9 +593,9 @@ public class MatrixUtils { throws MatrixIndexException { if (selectedRows.length * selectedColumns.length == 0) { if (selectedRows.length == 0) { - throw new MatrixIndexException("empty selected row index array"); + throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY); } - throw new MatrixIndexException("empty selected column index array"); + throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY); } for (final int row : selectedRows) { @@ -616,7 +617,7 @@ public class MatrixUtils { if ((left.getRowDimension() != right.getRowDimension()) || (left.getColumnDimension() != right.getColumnDimension())) { throw MathRuntimeException.createIllegalArgumentException( - "{0}x{1} and {2}x{3} matrices are not addition compatible", + LocalizedFormats.NOT_ADDITION_COMPATIBLE_MATRICES, left.getRowDimension(), left.getColumnDimension(), right.getRowDimension(), right.getColumnDimension()); } @@ -633,7 +634,7 @@ public class MatrixUtils { if ((left.getRowDimension() != right.getRowDimension()) || (left.getColumnDimension() != right.getColumnDimension())) { throw MathRuntimeException.createIllegalArgumentException( - "{0}x{1} and {2}x{3} matrices are not subtraction compatible", + LocalizedFormats.NOT_SUBTRACTION_COMPATIBLE_MATRICES, left.getRowDimension(), left.getColumnDimension(), right.getRowDimension(), right.getColumnDimension()); } @@ -649,7 +650,7 @@ public class MatrixUtils { throws IllegalArgumentException { if (left.getColumnDimension() != right.getRowDimension()) { throw MathRuntimeException.createIllegalArgumentException( - "{0}x{1} and {2}x{3} matrices are not multiplication compatible", + LocalizedFormats.NOT_MULTIPLICATION_COMPATIBLE_MATRICES, left.getRowDimension(), left.getColumnDimension(), right.getRowDimension(), right.getColumnDimension()); } diff --git a/src/main/java/org/apache/commons/math/linear/MatrixVisitorException.java b/src/main/java/org/apache/commons/math/linear/MatrixVisitorException.java index 3f76f2078..737b50fcd 100644 --- a/src/main/java/org/apache/commons/math/linear/MatrixVisitorException.java +++ b/src/main/java/org/apache/commons/math/linear/MatrixVisitorException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.Localizable; /** * Thrown when a visitor encounters an error while processing a matrix entry. @@ -32,9 +33,21 @@ public class MatrixVisitorException extends MathRuntimeException { * Constructs a new instance with specified formatted detail message. * @param pattern format specifier * @param arguments format arguments + * @deprecated as of 2.2 replaced by {@link #MatrixVisitorException(Localizable, Object...)} */ + @Deprecated public MatrixVisitorException(final String pattern, final Object[] arguments) { super(pattern, arguments); } + /** + * Constructs a new instance with specified formatted detail message. + * @param pattern format specifier + * @param arguments format arguments + * @since 2.2 + */ + public MatrixVisitorException(final Localizable pattern, final Object[] arguments) { + super(pattern, arguments); + } + } diff --git a/src/main/java/org/apache/commons/math/linear/NonSquareMatrixException.java b/src/main/java/org/apache/commons/math/linear/NonSquareMatrixException.java index dc839b617..c41e877c8 100644 --- a/src/main/java/org/apache/commons/math/linear/NonSquareMatrixException.java +++ b/src/main/java/org/apache/commons/math/linear/NonSquareMatrixException.java @@ -17,6 +17,8 @@ package org.apache.commons.math.linear; +import org.apache.commons.math.util.LocalizedFormats; + /** * Thrown when an operation defined only for square matrices is applied to non-square ones. @@ -34,8 +36,7 @@ public class NonSquareMatrixException extends InvalidMatrixException { * @param columns number of columns of the faulty matrix */ public NonSquareMatrixException(final int rows, final int columns) { - super("a {0}x{1} matrix was provided instead of a square matrix", - rows, columns); + super(LocalizedFormats.NON_SQUARE_MATRIX, rows, columns); } } diff --git a/src/main/java/org/apache/commons/math/linear/NotPositiveDefiniteMatrixException.java b/src/main/java/org/apache/commons/math/linear/NotPositiveDefiniteMatrixException.java index 465afca2a..492f00411 100644 --- a/src/main/java/org/apache/commons/math/linear/NotPositiveDefiniteMatrixException.java +++ b/src/main/java/org/apache/commons/math/linear/NotPositiveDefiniteMatrixException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; /** * This class represents exceptions thrown when a matrix expected to @@ -36,7 +37,7 @@ public class NotPositiveDefiniteMatrixException extends MathException { * build an exception with a default message. */ public NotPositiveDefiniteMatrixException() { - super("not positive definite matrix"); + super(LocalizedFormats.NOT_POSITIVE_DEFINITE_MATRIX); } } diff --git a/src/main/java/org/apache/commons/math/linear/NotSymmetricMatrixException.java b/src/main/java/org/apache/commons/math/linear/NotSymmetricMatrixException.java index 5fa30042d..8e66d36ae 100644 --- a/src/main/java/org/apache/commons/math/linear/NotSymmetricMatrixException.java +++ b/src/main/java/org/apache/commons/math/linear/NotSymmetricMatrixException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.LocalizedFormats; /** * This class represents exceptions thrown when a matrix expected to @@ -36,7 +37,7 @@ public class NotSymmetricMatrixException extends MathException { * build an exception with a default message. */ public NotSymmetricMatrixException() { - super("not symmetric matrix"); + super(LocalizedFormats.NOT_SYMMETRIC_MATRIX); } } diff --git a/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java b/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java index 9884d05fa..dc71e17d2 100644 --- a/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java +++ b/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java @@ -19,6 +19,7 @@ package org.apache.commons.math.linear; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.OpenIntToDoubleHashMap; import org.apache.commons.math.util.OpenIntToDoubleHashMap.Iterator; @@ -732,7 +733,7 @@ public class OpenMapRealVector extends AbstractRealVector implements SparseRealV public void unitize() { double norm = getNorm(); if (isDefaultValue(norm)) { - throw MathRuntimeException.createArithmeticException("cannot normalize a zero norm vector"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR); } Iterator iter = entries.iterator(); while (iter.hasNext()) { diff --git a/src/main/java/org/apache/commons/math/linear/QRDecompositionImpl.java b/src/main/java/org/apache/commons/math/linear/QRDecompositionImpl.java index 088c10568..28bf94605 100644 --- a/src/main/java/org/apache/commons/math/linear/QRDecompositionImpl.java +++ b/src/main/java/org/apache/commons/math/linear/QRDecompositionImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.linear; import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -290,7 +291,7 @@ public class QRDecompositionImpl implements QRDecomposition { final int m = qrt[0].length; if (b.length != m) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, b.length, m); } if (!isNonSingular()) { @@ -361,7 +362,7 @@ public class QRDecompositionImpl implements QRDecomposition { final int m = qrt[0].length; if (b.getRowDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( - "dimensions mismatch: got {0}x{1} but expected {2}x{3}", + LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), m, "n"); } if (!isNonSingular()) { diff --git a/src/main/java/org/apache/commons/math/linear/RealMatrixImpl.java b/src/main/java/org/apache/commons/math/linear/RealMatrixImpl.java index 724627a32..392dee46c 100644 --- a/src/main/java/org/apache/commons/math/linear/RealMatrixImpl.java +++ b/src/main/java/org/apache/commons/math/linear/RealMatrixImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.linear; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Implementation of RealMatrix using a double[][] array to store entries and @@ -122,16 +123,16 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { } final int nRows = d.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } 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}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[r].length); } } @@ -316,28 +317,28 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { if (data == null) { if (row > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} rows are not initialized yet", + LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); } if (column > 0) { throw MathRuntimeException.createIllegalStateException( - "first {0} columns are not initialized yet", + LocalizedFormats.FIRST_COLUMNS_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(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } 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}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[i].length); } System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols); @@ -356,7 +357,7 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { return data[row][column]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -369,7 +370,7 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { data[row][column] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -382,7 +383,7 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { data[row][column] += increment; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -395,7 +396,7 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { data[row][column] *= factor; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( - "no entry at indices ({0}, {1}) in a {2}x{3} matrix", + LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension()); } } @@ -420,7 +421,7 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { final int nCols = this.getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols); } final double[] out = new double[nRows]; @@ -444,7 +445,7 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable { final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows); } diff --git a/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java b/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java index 82d3b114e..4af951b46 100644 --- a/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java +++ b/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java @@ -27,6 +27,7 @@ import java.util.Locale; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.util.CompositeFormat; +import org.apache.commons.math.util.LocalizedFormats; /** * Formats a vector in components list format "{v0; v1; ...; vk-1}". @@ -246,7 +247,7 @@ public class RealVectorFormat extends CompositeFormat { } throw MathRuntimeException.createIllegalArgumentException( - "cannot format a {0} instance as a real vector", + LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_REAL_VECTOR, obj.getClass().getName()); } diff --git a/src/main/java/org/apache/commons/math/linear/SingularMatrixException.java b/src/main/java/org/apache/commons/math/linear/SingularMatrixException.java index 48184e866..88f06f92a 100644 --- a/src/main/java/org/apache/commons/math/linear/SingularMatrixException.java +++ b/src/main/java/org/apache/commons/math/linear/SingularMatrixException.java @@ -17,6 +17,8 @@ package org.apache.commons.math.linear; +import org.apache.commons.math.util.LocalizedFormats; + /** * Thrown when a matrix is singular. @@ -32,7 +34,7 @@ public class SingularMatrixException extends InvalidMatrixException { * Construct an exception with a default message. */ public SingularMatrixException() { - super("matrix is singular"); + super(LocalizedFormats.SINGULAR_MATRIX); } } diff --git a/src/main/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java b/src/main/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java index 38008ee57..08d5b84ed 100644 --- a/src/main/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java +++ b/src/main/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java @@ -18,6 +18,7 @@ package org.apache.commons.math.linear; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Calculates the compact Singular Value Decomposition of a matrix. @@ -219,7 +220,7 @@ public class SingularValueDecompositionImpl implements if (dimension == 0) { throw MathRuntimeException.createIllegalArgumentException( - "cutoff singular value is {0}, should be at most {1}", + LocalizedFormats.TOO_LARGE_CUTOFF_SINGULAR_VALUE, minSingularValue, singularValues[0]); } diff --git a/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java b/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java index f9421c496..2c000f57a 100644 --- a/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java +++ b/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java @@ -22,6 +22,7 @@ import java.lang.reflect.Array; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.OpenIntToFieldHashMap; /** @@ -565,7 +566,7 @@ public class SparseFieldVector> implements FieldVector protected void checkVectorDimensions(int n) throws IllegalArgumentException { if (getDimension() != n) { throw MathRuntimeException.createIllegalArgumentException( - "vector length mismatch: got {0} but expected {1}", + LocalizedFormats.VECTOR_LENGTH_MISMATCH, getDimension(), n); } } diff --git a/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java b/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java index 4b4d0b928..d989e2cfd 100644 --- a/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java @@ -26,6 +26,7 @@ import org.apache.commons.math.ode.events.CombinedEventsManager; import org.apache.commons.math.ode.events.EventHandler; import org.apache.commons.math.ode.events.EventState; import org.apache.commons.math.ode.sampling.StepHandler; +import org.apache.commons.math.util.LocalizedFormats; /** * Base class managing common boilerplate for all integrators. @@ -197,21 +198,17 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { if (ode.getDimension() != y0.length) { throw new IntegratorException( - "dimensions mismatch: ODE problem has dimension {0}," + - " initial state vector has dimension {1}", - ode.getDimension(), y0.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, ode.getDimension(), y0.length); } if (ode.getDimension() != y.length) { throw new IntegratorException( - "dimensions mismatch: ODE problem has dimension {0}," + - " final state vector has dimension {1}", - ode.getDimension(), y.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, ode.getDimension(), y.length); } if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) { throw new IntegratorException( - "too small integration interval: length = {0}", + LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, Math.abs(t - t0)); } diff --git a/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java b/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java index 02b64b3d9..02441dbea 100644 --- a/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java +++ b/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java @@ -24,6 +24,7 @@ import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepInterpolator; +import org.apache.commons.math.util.LocalizedFormats; /** * This class stores all information provided by an ODE integrator @@ -134,13 +135,13 @@ public class ContinuousOutputModel if (getInterpolatedState().length != model.getInterpolatedState().length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, getInterpolatedState().length, model.getInterpolatedState().length); } if (forward ^ model.forward) { throw MathRuntimeException.createIllegalArgumentException( - "propagation direction mismatch"); + LocalizedFormats.PROPAGATION_DIRECTION_MISMATCH); } final StepInterpolator lastInterpolator = steps.get(index); @@ -150,7 +151,7 @@ public class ContinuousOutputModel final double gap = model.getInitialTime() - current; if (Math.abs(gap) > 1.0e-3 * Math.abs(step)) { throw MathRuntimeException.createIllegalArgumentException( - "{0} wide hole between models time ranges", Math.abs(gap)); + LocalizedFormats.HOLE_BETWEEN_MODELS_TIME_RANGES, Math.abs(gap)); } } diff --git a/src/main/java/org/apache/commons/math/ode/DerivativeException.java b/src/main/java/org/apache/commons/math/ode/DerivativeException.java index f0820ea74..19fda4e8e 100644 --- a/src/main/java/org/apache/commons/math/ode/DerivativeException.java +++ b/src/main/java/org/apache/commons/math/ode/DerivativeException.java @@ -18,6 +18,8 @@ package org.apache.commons.math.ode; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; /** * This exception is made available to users to report @@ -36,12 +38,23 @@ public class DerivativeException * Build an exception by translating and formating a message * @param specifier format specifier (to be translated) * @param parts to insert in the format (no translation) + * @deprecated as of 2.2 replaced by {@link #DerivativeException(Localizable, Object...)} */ + @Deprecated public DerivativeException(final String specifier, final Object ... parts) { + this(new DummyLocalizable(specifier), parts); + } + + /** Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + */ + public DerivativeException(final Localizable specifier, final Object ... parts) { super(specifier, parts); } - /** Build an instance from an underlying cause. + /** Build an instance from an underlying cause. * @param cause cause for the exception */ public DerivativeException(final Throwable cause) { diff --git a/src/main/java/org/apache/commons/math/ode/IntegratorException.java b/src/main/java/org/apache/commons/math/ode/IntegratorException.java index 47d38cae0..f0b9869ba 100644 --- a/src/main/java/org/apache/commons/math/ode/IntegratorException.java +++ b/src/main/java/org/apache/commons/math/ode/IntegratorException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.ode; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.Localizable; /** * This exception is made available to users to report @@ -31,14 +32,25 @@ public class IntegratorException /** Serializable version identifier */ private static final long serialVersionUID = -1607588949778036796L; - /** Simple constructor. - * Build an exception by translating and formating a message - * @param specifier format specifier (to be translated) - * @param parts to insert in the format (no translation) - */ - public IntegratorException(final String specifier, final Object ... parts) { - super(specifier, parts); - } + /** Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + * @deprecated as of 2.2 replaced by {@link #IntegratorException(Localizable, Object...)} + */ + @Deprecated + public IntegratorException(final String specifier, final Object ... parts) { + super(specifier, parts); + } + + /** Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + */ + public IntegratorException(final Localizable specifier, final Object ... parts) { + super(specifier, parts); + } /** * Create an exception with a given root cause. diff --git a/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java b/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java index d33bdfed1..5ec05c675 100644 --- a/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java @@ -24,6 +24,7 @@ import org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator; import org.apache.commons.math.ode.nonstiff.DormandPrince853Integrator; import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepInterpolator; +import org.apache.commons.math.util.LocalizedFormats; /** * This class is the base class for multistep integrators for Ordinary @@ -113,7 +114,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { if (nSteps <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} method needs at least one previous point", + LocalizedFormats.INTEGRATION_METHOD_NEEDS_AT_LEAST_ONE_PREVIOUS_POINT, name); } diff --git a/src/main/java/org/apache/commons/math/ode/events/EventException.java b/src/main/java/org/apache/commons/math/ode/events/EventException.java index f8f1ca68c..3d62ef0e2 100644 --- a/src/main/java/org/apache/commons/math/ode/events/EventException.java +++ b/src/main/java/org/apache/commons/math/ode/events/EventException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.ode.events; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.Localizable; /** * This exception is made available to users to report @@ -34,11 +35,23 @@ public class EventException extends MathException { * Build an exception by translating and formating a message * @param specifier format specifier (to be translated) * @param parts to insert in the format (no translation) + * @deprecated as of 2.2 replaced by {@link #EventException(Localizable, Object...)} */ + @Deprecated public EventException(final String specifier, final Object ... parts) { super(specifier, parts); } + /** Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + * @since 2.2 + */ + public EventException(final Localizable specifier, final Object ... parts) { + super(specifier, parts); + } + /** * Create an exception with a given root cause. * @param cause the exception or error that caused this exception to be thrown diff --git a/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java b/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java index ccd107997..f8b6c2cfc 100644 --- a/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java +++ b/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java @@ -34,6 +34,7 @@ import org.apache.commons.math.ode.events.EventException; import org.apache.commons.math.ode.events.EventHandler; import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepInterpolator; +import org.apache.commons.math.util.LocalizedFormats; /** This class enhances a first order integrator for differential equations to * compute also partial derivatives of the solution with respect to initial state @@ -348,7 +349,7 @@ public class FirstOrderIntegratorWithJacobians { int arrayDimension = (array == null) ? 0 : Array.getLength(array); if (arrayDimension != expected) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", arrayDimension, expected); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, arrayDimension, expected); } } diff --git a/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java b/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java index 549f1091f..9811c1497 100644 --- a/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java @@ -21,6 +21,7 @@ import org.apache.commons.math.ode.AbstractIntegrator; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; +import org.apache.commons.math.util.LocalizedFormats; /** * This abstract class holds the common part of all adaptive @@ -172,16 +173,12 @@ public abstract class AdaptiveStepsizeIntegrator if ((vecAbsoluteTolerance != null) && (vecAbsoluteTolerance.length != y0.length)) { throw new IntegratorException( - "dimensions mismatch: state vector has dimension {0}," + - " absolute tolerance vector has dimension {1}", - y0.length, vecAbsoluteTolerance.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, y0.length, vecAbsoluteTolerance.length); } if ((vecRelativeTolerance != null) && (vecRelativeTolerance.length != y0.length)) { throw new IntegratorException( - "dimensions mismatch: state vector has dimension {0}," + - " relative tolerance vector has dimension {1}", - y0.length, vecRelativeTolerance.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, y0.length, vecRelativeTolerance.length); } } @@ -283,7 +280,7 @@ public abstract class AdaptiveStepsizeIntegrator filteredH = forward ? minStep : -minStep; } else { throw new IntegratorException( - "minimal step size ({0,number,0.00E00}) reached, integration needs {1,number,0.00E00}", + LocalizedFormats.MINIMAL_STEPSIZE_REACHED_DURING_INTEGRATION, minStep, Math.abs(h)); } } diff --git a/src/main/java/org/apache/commons/math/optimization/LeastSquaresConverter.java b/src/main/java/org/apache/commons/math/optimization/LeastSquaresConverter.java index 31218dc2f..8ef7fc89a 100644 --- a/src/main/java/org/apache/commons/math/optimization/LeastSquaresConverter.java +++ b/src/main/java/org/apache/commons/math/optimization/LeastSquaresConverter.java @@ -22,6 +22,7 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.MultivariateRealFunction; import org.apache.commons.math.analysis.MultivariateVectorialFunction; import org.apache.commons.math.linear.RealMatrix; +import org.apache.commons.math.util.LocalizedFormats; /** This class converts {@link MultivariateVectorialFunction vectorial * objective functions} to {@link MultivariateRealFunction scalar objective functions} @@ -113,7 +114,7 @@ public class LeastSquaresConverter implements MultivariateRealFunction { throws IllegalArgumentException { if (observations.length != weights.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, observations.length, weights.length); } this.function = function; @@ -146,7 +147,7 @@ public class LeastSquaresConverter implements MultivariateRealFunction { throws IllegalArgumentException { if (observations.length != scale.getColumnDimension()) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, observations.length, scale.getColumnDimension()); } this.function = function; @@ -161,7 +162,7 @@ public class LeastSquaresConverter implements MultivariateRealFunction { // compute residuals final double[] residuals = function.value(point); if (residuals.length != observations.length) { - throw new FunctionEvaluationException(point, "dimension mismatch {0} != {1}", + throw new FunctionEvaluationException(point, LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, residuals.length, observations.length); } for (int i = 0; i < residuals.length; ++i) { diff --git a/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java index 26425a6fd..ea8768317 100644 --- a/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java @@ -24,6 +24,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction; import org.apache.commons.math.random.RandomVectorGenerator; +import org.apache.commons.math.util.LocalizedFormats; /** * Special implementation of the {@link DifferentiableMultivariateRealOptimizer} interface adding @@ -117,7 +118,7 @@ public class MultiStartDifferentiableMultivariateRealOptimizer */ public RealPointValuePair[] getOptima() throws IllegalStateException { if (optima == null) { - throw MathRuntimeException.createIllegalStateException("no optimum computed yet"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET); } return optima.clone(); } @@ -215,7 +216,7 @@ public class MultiStartDifferentiableMultivariateRealOptimizer if (optima[0] == null) { throw new OptimizationException( - "none of the {0} start points lead to convergence", + LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT, starts); } diff --git a/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java b/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java index fedfc2400..12519e439 100644 --- a/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java @@ -24,6 +24,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction; import org.apache.commons.math.random.RandomVectorGenerator; +import org.apache.commons.math.util.LocalizedFormats; /** * Special implementation of the {@link DifferentiableMultivariateVectorialOptimizer} interface adding @@ -121,7 +122,7 @@ public class MultiStartDifferentiableMultivariateVectorialOptimizer */ public VectorialPointValuePair[] getOptima() throws IllegalStateException { if (optima == null) { - throw MathRuntimeException.createIllegalStateException("no optimum computed yet"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET); } return optima.clone(); } @@ -225,7 +226,7 @@ public class MultiStartDifferentiableMultivariateVectorialOptimizer if (optima[0] == null) { throw new OptimizationException( - "none of the {0} start points lead to convergence", + LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT, starts); } diff --git a/src/main/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java index 9fbb32c42..1354d713e 100644 --- a/src/main/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java @@ -24,6 +24,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.MultivariateRealFunction; import org.apache.commons.math.random.RandomVectorGenerator; +import org.apache.commons.math.util.LocalizedFormats; /** * Special implementation of the {@link MultivariateRealOptimizer} interface adding @@ -112,7 +113,7 @@ public class MultiStartMultivariateRealOptimizer */ public RealPointValuePair[] getOptima() throws IllegalStateException { if (optima == null) { - throw MathRuntimeException.createIllegalStateException("no optimum computed yet"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET); } return optima.clone(); } @@ -203,7 +204,7 @@ public class MultiStartMultivariateRealOptimizer if (optima[0] == null) { throw new OptimizationException( - "none of the {0} start points lead to convergence", + LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT, starts); } diff --git a/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java index f00b9fba1..10bc9e66c 100644 --- a/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java @@ -22,6 +22,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.random.RandomGenerator; +import org.apache.commons.math.util.LocalizedFormats; /** * Special implementation of the {@link UnivariateRealOptimizer} interface adding @@ -190,7 +191,7 @@ public class MultiStartUnivariateRealOptimizer implements UnivariateRealOptimize */ public double[] getOptima() throws IllegalStateException { if (optima == null) { - throw MathRuntimeException.createIllegalStateException("no optimum computed yet"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET); } return optima.clone(); } @@ -216,7 +217,7 @@ public class MultiStartUnivariateRealOptimizer implements UnivariateRealOptimize */ public double[] getOptimaValues() throws IllegalStateException { if (optimaValues == null) { - throw MathRuntimeException.createIllegalStateException("no optimum computed yet"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET); } return optimaValues.clone(); } @@ -299,7 +300,7 @@ public class MultiStartUnivariateRealOptimizer implements UnivariateRealOptimize if (Double.isNaN(optima[0])) { throw new OptimizationException( - "none of the {0} start points lead to convergence", + LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT, starts); } diff --git a/src/main/java/org/apache/commons/math/optimization/OptimizationException.java b/src/main/java/org/apache/commons/math/optimization/OptimizationException.java index bfbe32536..81ca5e30c 100644 --- a/src/main/java/org/apache/commons/math/optimization/OptimizationException.java +++ b/src/main/java/org/apache/commons/math/optimization/OptimizationException.java @@ -18,6 +18,8 @@ package org.apache.commons.math.optimization; import org.apache.commons.math.ConvergenceException; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; /** * This class represents exceptions thrown by optimizers. @@ -30,15 +32,28 @@ import org.apache.commons.math.ConvergenceException; public class OptimizationException extends ConvergenceException { /** Serializable version identifier. */ - private static final long serialVersionUID = -357696069587075016L; + private static final long serialVersionUID = -4605887730798282127L; /** * Simple constructor. * Build an exception by translating and formating a message * @param specifier format specifier (to be translated) * @param parts to insert in the format (no translation) + * @deprecated as of 2.2 replaced by {@link #OptimizationException(Localizable, Object...)} */ + @Deprecated public OptimizationException(String specifier, Object ... parts) { + this(new DummyLocalizable(specifier), parts); + } + + /** + * Simple constructor. + * Build an exception by translating and formating a message + * @param specifier format specifier (to be translated) + * @param parts to insert in the format (no translation) + * @since 2.2 + */ + public OptimizationException(Localizable specifier, Object ... parts) { super(specifier, parts); } diff --git a/src/main/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java b/src/main/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java index 9861c47cf..af268f76c 100644 --- a/src/main/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java @@ -31,6 +31,7 @@ import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.RealConvergenceChecker; import org.apache.commons.math.optimization.RealPointValuePair; import org.apache.commons.math.optimization.SimpleScalarValueChecker; +import org.apache.commons.math.util.LocalizedFormats; /** * This class implements simplex-based direct search optimization @@ -87,14 +88,6 @@ 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; @@ -154,7 +147,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer for (int j = 0; j < i + 1; ++j) { if (steps[j] == 0.0) { throw MathRuntimeException.createIllegalArgumentException( - EQUAL_VERTICES_MESSAGE, j, j + 1); + LocalizedFormats.EQUAL_VERTICES_IN_SIMPLEX, j, j + 1); } System.arraycopy(steps, 0, vertexI, 0, j + 1); } @@ -178,7 +171,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer final int n = referenceSimplex.length - 1; if (n < 0) { throw MathRuntimeException.createIllegalArgumentException( - "simplex must contain at least one point"); + LocalizedFormats.SIMPLEX_NEED_ONE_POINT); } startConfiguration = new double[n][n]; final double[] ref0 = referenceSimplex[0]; @@ -191,7 +184,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer // safety checks if (refI.length != n) { throw MathRuntimeException.createIllegalArgumentException( - DIMENSION_MISMATCH_MESSAGE, refI.length, n); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, refI.length, n); } for (int j = 0; j < i; ++j) { final double[] refJ = referenceSimplex[j]; @@ -204,7 +197,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer } if (allEquals) { throw MathRuntimeException.createIllegalArgumentException( - EQUAL_VERTICES_MESSAGE, i, j); + LocalizedFormats.EQUAL_VERTICES_IN_SIMPLEX, i, j); } } @@ -366,7 +359,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer final int n = startPoint.length; if (n != startConfiguration.length) { throw MathRuntimeException.createIllegalArgumentException( - DIMENSION_MISMATCH_MESSAGE, n, startConfiguration.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, startConfiguration.length); } // set first vertex diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java b/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java index f05a0f1c7..e4d222e59 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java @@ -18,6 +18,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.optimization.OptimizationException; +import org.apache.commons.math.util.LocalizedFormats; /** This class guesses harmonic coefficients from a sample. @@ -238,7 +239,7 @@ public class HarmonicCoefficientsGuesser { double c2 = sxy * sxz - sx2 * syz; double c3 = sx2 * sy2 - sxy * sxy; if ((c1 / c2 < 0.0) || (c2 / c3 < 0.0)) { - throw new OptimizationException("unable to first guess the harmonic coefficients"); + throw new OptimizationException(LocalizedFormats.UNABLE_TO_FIRST_GUESS_HARMONIC_COEFFICIENTS); } a = Math.sqrt(c1 / c2); omega = Math.sqrt(c2 / c3); diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java b/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java index 27c6a2cdc..039971cf7 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java @@ -21,6 +21,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; import org.apache.commons.math.optimization.OptimizationException; +import org.apache.commons.math.util.LocalizedFormats; /** This class implements a curve fitting specialized for sinusoids. *

Harmonic fitting is a very simple case of curve fitting. The @@ -82,7 +83,7 @@ public class HarmonicFitter { if (parameters == null) { final WeightedObservedPoint[] observations = fitter.getObservations(); if (observations.length < 4) { - throw new OptimizationException("sample contains {0} observed points, at least {1} are required", + throw new OptimizationException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4); } diff --git a/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java index 0935d53db..f6cea19ad 100644 --- a/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java @@ -31,6 +31,7 @@ import org.apache.commons.math.optimization.SimpleVectorialValueChecker; import org.apache.commons.math.optimization.VectorialConvergenceChecker; import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; import org.apache.commons.math.optimization.VectorialPointValuePair; +import org.apache.commons.math.util.LocalizedFormats; /** * Base class for implementing least squares optimizers. @@ -183,7 +184,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul ++jacobianEvaluations; jacobian = jF.value(point); if (jacobian.length != rows) { - throw new FunctionEvaluationException(point, "dimension mismatch {0} != {1}", + throw new FunctionEvaluationException(point, LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, jacobian.length, rows); } for (int i = 0; i < rows; i++) { @@ -210,7 +211,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul } objective = function.value(point); if (objective.length != rows) { - throw new FunctionEvaluationException(point, "dimension mismatch {0} != {1}", + throw new FunctionEvaluationException(point, LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, objective.length, rows); } cost = 0; @@ -290,7 +291,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj)).getSolver().getInverse(); return inverse.getData(); } catch (InvalidMatrixException ime) { - throw new OptimizationException("unable to compute covariances: singular problem"); + throw new OptimizationException(LocalizedFormats.UNABLE_TO_COMPUTE_COVARIANCE_SINGULAR_PROBLEM); } } @@ -308,7 +309,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul throws FunctionEvaluationException, OptimizationException { if (rows <= cols) { throw new OptimizationException( - "no degrees of freedom ({0} measurements, {1} parameters)", + LocalizedFormats.NO_DEGREES_OF_FREEDOM, rows, cols); } double[] errors = new double[cols]; @@ -327,7 +328,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul throws FunctionEvaluationException, OptimizationException, IllegalArgumentException { if (target.length != weights.length) { - throw new OptimizationException("dimension mismatch {0} != {1}", + throw new OptimizationException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, target.length, weights.length); } diff --git a/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java index 78dfe5657..df856592c 100644 --- a/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java @@ -26,6 +26,7 @@ import org.apache.commons.math.linear.QRDecompositionImpl; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.VectorialPointValuePair; +import org.apache.commons.math.util.LocalizedFormats; /** * Gauss-Newton least-squares solver. @@ -116,7 +117,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer { } } catch(InvalidMatrixException e) { - throw new OptimizationException("unable to solve: singular problem"); + throw new OptimizationException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM); } // check convergence diff --git a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java index a603e2b3b..a83dc1a76 100644 --- a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java @@ -21,6 +21,7 @@ import java.util.Arrays; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.VectorialPointValuePair; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; @@ -451,18 +452,13 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer { // tests for termination and stringent tolerances // (2.2204e-16 is the machine epsilon for IEEE754) if ((Math.abs(actRed) <= 2.2204e-16) && (preRed <= 2.2204e-16) && (ratio <= 2.0)) { - throw new OptimizationException("cost relative tolerance is too small ({0})," + - " no further reduction in the" + - " sum of squares is possible", + throw new OptimizationException(LocalizedFormats.TOO_SMALL_COST_RELATIVE_TOLERANCE, costRelativeTolerance); } else if (delta <= 2.2204e-16 * xNorm) { - throw new OptimizationException("parameters relative tolerance is too small" + - " ({0}), no further improvement in" + - " the approximate solution is possible", + throw new OptimizationException(LocalizedFormats.TOO_SMALL_PARAMETERS_RELATIVE_TOLERANCE, parRelativeTolerance); } else if (maxCosine <= 2.2204e-16) { - throw new OptimizationException("orthogonality tolerance is too small ({0})," + - " solution is orthogonal to the jacobian", + throw new OptimizationException(LocalizedFormats.TOO_SMALL_ORTHOGONALITY_TOLERANCE, orthoTolerance); } @@ -815,8 +811,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer { norm2 += aki * aki; } if (Double.isInfinite(norm2) || Double.isNaN(norm2)) { - throw new OptimizationException( - "unable to perform Q.R decomposition on the {0}x{1} jacobian matrix", + throw new OptimizationException(LocalizedFormats.UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JACOBIAN, rows, cols); } if (norm2 > ak2) { diff --git a/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java index 35f704665..6c3310992 100644 --- a/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java @@ -26,6 +26,7 @@ import org.apache.commons.math.optimization.GoalType; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.DifferentiableMultivariateRealOptimizer; import org.apache.commons.math.optimization.RealPointValuePair; +import org.apache.commons.math.util.LocalizedFormats; /** * Non-linear conjugate gradient optimizer. @@ -233,7 +234,7 @@ public class NonLinearConjugateGradientOptimizer return b; } } - throw new OptimizationException("unable to bracket optimum in line search"); + throw new OptimizationException(LocalizedFormats.UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH); } /** Default identity preconditioner. */ diff --git a/src/main/java/org/apache/commons/math/optimization/linear/NoFeasibleSolutionException.java b/src/main/java/org/apache/commons/math/optimization/linear/NoFeasibleSolutionException.java index 0dd8a54fd..fbd5ef5f2 100644 --- a/src/main/java/org/apache/commons/math/optimization/linear/NoFeasibleSolutionException.java +++ b/src/main/java/org/apache/commons/math/optimization/linear/NoFeasibleSolutionException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.optimization.linear; import org.apache.commons.math.optimization.OptimizationException; +import org.apache.commons.math.util.LocalizedFormats; /** * This class represents exceptions thrown by optimizers when no solution @@ -34,7 +35,7 @@ public class NoFeasibleSolutionException extends OptimizationException { * Simple constructor using a default message. */ public NoFeasibleSolutionException() { - super("no feasible solution"); + super(LocalizedFormats.NO_FEASIBLE_SOLUTION); } } diff --git a/src/main/java/org/apache/commons/math/optimization/linear/UnboundedSolutionException.java b/src/main/java/org/apache/commons/math/optimization/linear/UnboundedSolutionException.java index 50a1616b4..4d1659a4d 100644 --- a/src/main/java/org/apache/commons/math/optimization/linear/UnboundedSolutionException.java +++ b/src/main/java/org/apache/commons/math/optimization/linear/UnboundedSolutionException.java @@ -18,6 +18,7 @@ package org.apache.commons.math.optimization.linear; import org.apache.commons.math.optimization.OptimizationException; +import org.apache.commons.math.util.LocalizedFormats; /** * This class represents exceptions thrown by optimizers when a solution @@ -34,7 +35,7 @@ public class UnboundedSolutionException extends OptimizationException { * Simple constructor using a default message. */ public UnboundedSolutionException() { - super("unbounded solution"); + super(LocalizedFormats.UNBOUNDED_SOLUTION); } } diff --git a/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java index 0f1862809..e17a82527 100644 --- a/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java @@ -23,6 +23,7 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MaxEvaluationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.optimization.UnivariateRealOptimizer; +import org.apache.commons.math.util.LocalizedFormats; /** * Provide a default implementation for several functions useful to generic @@ -69,7 +70,7 @@ public abstract class AbstractUnivariateRealOptimizer */ protected void checkResultComputed() throws IllegalStateException { if (!resultComputed) { - throw MathRuntimeException.createIllegalStateException("no result available"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE); } } diff --git a/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java b/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java index c41cf547f..9dd1dc90d 100644 --- a/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java +++ b/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java @@ -17,6 +17,7 @@ package org.apache.commons.math.random; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Abstract class implementing the {@link RandomGenerator} interface. @@ -155,7 +156,7 @@ public abstract class AbstractRandomGenerator implements RandomGenerator { public int nextInt(int n) { if (n <= 0 ) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound must be positive ({0})", n); + LocalizedFormats.NOT_POSITIVE_UPPER_BOUND, n); } int result = (int) (nextDouble() * n); return result < n ? result : n - 1; diff --git a/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java b/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java index 690009ea2..9031f2424 100644 --- a/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java +++ b/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java @@ -17,6 +17,7 @@ package org.apache.commons.math.random; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** Base class for random number generators that generates bits streams. @@ -123,7 +124,7 @@ public abstract class BitsStreamGenerator implements RandomGenerator { if (n < 1) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound must be positive ({0})", n); + LocalizedFormats.NOT_POSITIVE_UPPER_BOUND, n); } // find bit mask for n diff --git a/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index 5c51a499e..5ef3655c5 100644 --- a/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -30,6 +30,7 @@ import java.util.List; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.StatisticalSummary; import org.apache.commons.math.stat.descriptive.SummaryStatistics; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements EmpiricalDistribution interface. This implementation @@ -138,7 +139,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib DataAdapter da = new StreamDataAdapter(in); da.computeStats(); if (sampleStats.getN() == 0) { - throw MathRuntimeException.createEOFException("URL {0} contains no data", + throw MathRuntimeException.createEOFException(LocalizedFormats.URL_CONTAINS_NO_DATA, url); } in = new BufferedReader(new InputStreamReader(url.openStream())); @@ -370,7 +371,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib public double getNextValue() throws IllegalStateException { if (!loaded) { - throw MathRuntimeException.createIllegalStateException("distribution not loaded"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED); } // Start with a uniformly distributed random number in (0,1) @@ -390,7 +391,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib } } } - throw new MathRuntimeException("no bin selected"); + throw new MathRuntimeException(LocalizedFormats.NO_BIN_SELECTED); } /** diff --git a/src/main/java/org/apache/commons/math/random/RandomDataImpl.java b/src/main/java/org/apache/commons/math/random/RandomDataImpl.java index 7f43042bc..33f9c0825 100644 --- a/src/main/java/org/apache/commons/math/random/RandomDataImpl.java +++ b/src/main/java/org/apache/commons/math/random/RandomDataImpl.java @@ -39,6 +39,7 @@ import org.apache.commons.math.distribution.PascalDistributionImpl; import org.apache.commons.math.distribution.TDistributionImpl; import org.apache.commons.math.distribution.WeibullDistributionImpl; import org.apache.commons.math.distribution.ZipfDistributionImpl; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -148,7 +149,7 @@ public class RandomDataImpl implements RandomData, Serializable { public String nextHexString(int len) { if (len <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "length must be positive ({0})", len); + LocalizedFormats.NOT_POSITIVE_LENGTH, len); } // Get a random number generator @@ -194,7 +195,7 @@ public class RandomDataImpl implements RandomData, Serializable { public int nextInt(int lower, int upper) { if (lower >= upper) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound ({0}) must be greater than lower bound ({1})", + LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, upper, lower); } double r = getRan().nextDouble(); @@ -214,7 +215,7 @@ public class RandomDataImpl implements RandomData, Serializable { public long nextLong(long lower, long upper) { if (lower >= upper) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound ({0}) must be greater than lower bound ({1})", + LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, upper, lower); } double r = getRan().nextDouble(); @@ -244,7 +245,7 @@ public class RandomDataImpl implements RandomData, Serializable { public String nextSecureHexString(int len) { if (len <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "length must be positive ({0})", len); + LocalizedFormats.NOT_POSITIVE_LENGTH, len); } // Get SecureRandom and setup Digest provider @@ -305,7 +306,7 @@ public class RandomDataImpl implements RandomData, Serializable { public int nextSecureInt(int lower, int upper) { if (lower >= upper) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound ({0}) must be greater than lower bound ({1})", + LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, upper, lower); } SecureRandom sec = getSecRan(); @@ -326,7 +327,7 @@ public class RandomDataImpl implements RandomData, Serializable { public long nextSecureLong(long lower, long upper) { if (lower >= upper) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound ({0}) must be greater than lower bound ({1})", + LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, upper, lower); } SecureRandom sec = getSecRan(); @@ -352,7 +353,7 @@ public class RandomDataImpl implements RandomData, Serializable { public long nextPoisson(double mean) { if (mean <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "the Poisson mean must be positive ({0})", mean); + LocalizedFormats.NOT_POSITIVE_POISSON_MEAN, mean); } final RandomGenerator generator = getRan(); @@ -456,7 +457,7 @@ public class RandomDataImpl implements RandomData, Serializable { public double nextGaussian(double mu, double sigma) { if (sigma <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "standard deviation must be positive ({0})", sigma); + LocalizedFormats.NOT_POSITIVE_STANDARD_DEVIATION, sigma); } return sigma * getRan().nextGaussian() + mu; } @@ -477,7 +478,7 @@ public class RandomDataImpl implements RandomData, Serializable { public double nextExponential(double mean) { if (mean <= 0.0) { throw MathRuntimeException.createIllegalArgumentException( - "mean must be positive ({0})", mean); + LocalizedFormats.NOT_POSITIVE_MEAN, mean); } final RandomGenerator generator = getRan(); double unif = generator.nextDouble(); @@ -506,7 +507,7 @@ public class RandomDataImpl implements RandomData, Serializable { public double nextUniform(double lower, double upper) { if (lower >= upper) { throw MathRuntimeException.createIllegalArgumentException( - "upper bound ({0}) must be greater than lower bound ({1})", + LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, upper, lower); } final RandomGenerator generator = getRan(); @@ -830,11 +831,11 @@ public class RandomDataImpl implements RandomData, Serializable { public int[] nextPermutation(int n, int k) { if (k > n) { throw MathRuntimeException.createIllegalArgumentException( - "permutation k ({0}) exceeds n ({1})", k, n); + LocalizedFormats.PERMUTATION_EXCEEDS_N, k, n); } if (k == 0) { throw MathRuntimeException.createIllegalArgumentException( - "permutation k ({0}) must be positive", k); + LocalizedFormats.NOT_POSITIVE_PERMUTATION, k); } int[] index = getNatural(n); @@ -867,11 +868,11 @@ public class RandomDataImpl implements RandomData, Serializable { int len = c.size(); if (k > len) { throw MathRuntimeException.createIllegalArgumentException( - "sample size ({0}) exceeds collection size ({1})"); + LocalizedFormats.SAMPLE_SIZE_EXCEEDS_COLLECTION_SIZE); } if (k <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "sample size must be positive ({0})", k); + LocalizedFormats.NOT_POSITIVE_SAMPLE_SIZE, k); } Object[] objects = c.toArray(); diff --git a/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java b/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java index f4e71fb05..4c68471ea 100644 --- a/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java +++ b/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java @@ -20,6 +20,7 @@ package org.apache.commons.math.random; import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * A {@link RandomVectorGenerator} that generates vectors with uncorrelated @@ -55,7 +56,7 @@ public class UncorrelatedRandomVectorGenerator NormalizedRandomGenerator generator) { if (mean.length != standardDeviation.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, mean.length, standardDeviation.length); } this.mean = mean.clone(); diff --git a/src/main/java/org/apache/commons/math/random/ValueServer.java b/src/main/java/org/apache/commons/math/random/ValueServer.java index 2f198dcc2..ce37f312e 100644 --- a/src/main/java/org/apache/commons/math/random/ValueServer.java +++ b/src/main/java/org/apache/commons/math/random/ValueServer.java @@ -23,6 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Generates values for use in simulation applications. @@ -313,7 +314,7 @@ public class ValueServer { private double getNextDigest() { if ((empiricalDistribution == null) || (empiricalDistribution.getBinStats().size() == 0)) { - throw MathRuntimeException.createIllegalStateException("digest not initialized"); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED); } return empiricalDistribution.getNextValue(); } @@ -346,7 +347,7 @@ public class ValueServer { closeReplayFile(); resetReplayFile(); if ((str = filePointer.readLine()) == null) { - throw MathRuntimeException.createEOFException("URL {0} contains no data", + throw MathRuntimeException.createEOFException(LocalizedFormats.URL_CONTAINS_NO_DATA, valuesFileURL); } } diff --git a/src/main/java/org/apache/commons/math/stat/Frequency.java b/src/main/java/org/apache/commons/math/stat/Frequency.java index da31c0965..461cb6a9f 100644 --- a/src/main/java/org/apache/commons/math/stat/Frequency.java +++ b/src/main/java/org/apache/commons/math/stat/Frequency.java @@ -23,6 +23,7 @@ import java.util.Comparator; import java.util.TreeMap; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Maintains a frequency distribution. @@ -114,7 +115,7 @@ public class Frequency implements Serializable { addValue((Comparable) v); } else { throw MathRuntimeException.createIllegalArgumentException( - "class ({0}) does not implement Comparable", + LocalizedFormats.CLASS_DOESNT_IMPLEMENT_COMPARABLE, v.getClass().getName()); } } @@ -144,7 +145,7 @@ public class Frequency implements Serializable { } catch (ClassCastException ex) { //TreeMap will throw ClassCastException if v is not comparable throw MathRuntimeException.createIllegalArgumentException( - "instance of class {0} not comparable to existing values", + LocalizedFormats.INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES, v.getClass().getName()); } } diff --git a/src/main/java/org/apache/commons/math/stat/StatUtils.java b/src/main/java/org/apache/commons/math/stat/StatUtils.java index f859db3b9..b86508163 100644 --- a/src/main/java/org/apache/commons/math/stat/StatUtils.java +++ b/src/main/java/org/apache/commons/math/stat/StatUtils.java @@ -28,6 +28,7 @@ import org.apache.commons.math.stat.descriptive.summary.Product; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import org.apache.commons.math.util.LocalizedFormats; /** * StatUtils provides static methods for computing statistics based on data @@ -564,10 +565,13 @@ public final class StatUtils { public static double sumDifference(final double[] sample1, final double[] sample2) throws IllegalArgumentException { int n = sample1.length; - if ((n != sample2.length) || (n < 1)) { + if (n != sample2.length) { throw MathRuntimeException.createIllegalArgumentException( - "input arrays must have the same positive length ({0} and {1})", - n, sample2.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, sample2.length); + } + if (n < 1) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.INSUFFICIENT_DIMENSION, sample2.length, 1); } double result = 0; for (int i = 0; i < n; i++) { @@ -609,10 +613,13 @@ public final class StatUtils { double sum2 = 0d; double diff = 0d; int n = sample1.length; - if (n < 2 || n != sample2.length) { + if (n != sample2.length) { throw MathRuntimeException.createIllegalArgumentException( - "input arrays must have the same length and at least two elements ({0} and {1})", - n, sample2.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, sample2.length); + } + if (n < 2) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.INSUFFICIENT_DIMENSION, n, 2); } for (int i = 0; i < n; i++) { diff = sample1[i] - sample2[i]; diff --git a/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java b/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java index 748373052..e83600dc9 100644 --- a/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java +++ b/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java @@ -21,6 +21,7 @@ import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.BlockRealMatrix; import org.apache.commons.math.stat.descriptive.moment.Mean; import org.apache.commons.math.stat.descriptive.moment.Variance; +import org.apache.commons.math.util.LocalizedFormats; /** * Computes covariances for pairs of arrays or columns of a matrix. @@ -221,7 +222,13 @@ public class Covariance { Mean mean = new Mean(); double result = 0d; int length = xArray.length; - if(length == yArray.length && length > 1) { + if (length != yArray.length) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length); + } else if (length < 2) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.INSUFFICIENT_DIMENSION, length, 2); + } else { double xMean = mean.evaluate(xArray); double yMean = mean.evaluate(yArray); for (int i = 0; i < length; i++) { @@ -230,12 +237,6 @@ public class Covariance { result += (xDev * yDev - result) / (i + 1); } } - else { - throw MathRuntimeException.createIllegalArgumentException( - "arrays must have the same length and both must have at " + - "least two elements. xArray has size {0}, yArray has {1} elements", - length, yArray.length); - } return biasCorrected ? result * ((double) length / (double)(length - 1)) : result; } @@ -266,7 +267,7 @@ public class Covariance { int nCols = matrix.getColumnDimension(); if (nRows < 2 || nCols < 2) { throw MathRuntimeException.createIllegalArgumentException( - "insufficient data: only {0} rows and {1} columns.", + LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS, nRows, nCols); } } diff --git a/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java b/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java index dc83314f6..7b56dd328 100644 --- a/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java +++ b/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java @@ -23,6 +23,7 @@ import org.apache.commons.math.distribution.TDistributionImpl; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.BlockRealMatrix; import org.apache.commons.math.stat.regression.SimpleRegression; +import org.apache.commons.math.util.LocalizedFormats; /** * Computes Pearson's product-moment correlation coefficients for pairs of arrays @@ -91,7 +92,7 @@ public class PearsonsCorrelation { public PearsonsCorrelation(Covariance covariance) { RealMatrix covarianceMatrix = covariance.getCovarianceMatrix(); if (covarianceMatrix == null) { - throw MathRuntimeException.createIllegalArgumentException("covariance matrix is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_COVARIANCE_MATRIX); } nObs = covariance.getN(); correlationMatrix = covarianceToCorrelation(covarianceMatrix); @@ -223,17 +224,18 @@ public class PearsonsCorrelation { */ public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException { SimpleRegression regression = new SimpleRegression(); - if(xArray.length == yArray.length && xArray.length > 1) { + if (xArray.length != yArray.length) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, xArray.length, yArray.length); + } else if (xArray.length < 2) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); + } else { for(int i=0; iSpearman's rank correlation. This implementation performs a rank @@ -145,15 +146,16 @@ public class SpearmansCorrelation { */ public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException { - if (xArray.length == yArray.length && xArray.length > 1) { + if (xArray.length != yArray.length) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, xArray.length, yArray.length); + } else if (xArray.length < 2) { + throw MathRuntimeException.createIllegalArgumentException( + LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); + } else { return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(xArray), rankingAlgorithm.rank(yArray)); } - else { - throw MathRuntimeException.createIllegalArgumentException( - "invalid array dimensions. xArray has size {0}; yArray has {1} elements", - xArray.length, yArray.length); - } } /** diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java index 1f115041d..0588540c0 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java @@ -17,6 +17,7 @@ package org.apache.commons.math.stat.descriptive; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -55,7 +56,7 @@ public abstract class AbstractStorelessUnivariateStatistic @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); } return evaluate(values, 0, values.length); } @@ -123,7 +124,7 @@ public abstract class AbstractStorelessUnivariateStatistic */ public void incrementAll(double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); } incrementAll(values, 0, values.length); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java index 95a18949e..1fa88aae6 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java @@ -17,6 +17,7 @@ package org.apache.commons.math.stat.descriptive; import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.util.LocalizedFormats; /** * Abstract base class for all implementations of the @@ -77,22 +78,22 @@ public abstract class AbstractUnivariateStatistic final int length) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); } if (begin < 0) { throw MathRuntimeException.createIllegalArgumentException( - "start position cannot be negative ({0})", begin); + LocalizedFormats.NEGATIVE_START_POSITION, begin); } if (length < 0) { throw MathRuntimeException.createIllegalArgumentException( - "length cannot be negative ({0})", length); + LocalizedFormats.NEGATIVE_LENGTH, length); } if (begin + length > values.length) { throw MathRuntimeException.createIllegalArgumentException( - "subarray ends after array end"); + LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END); } if (length == 0) { diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java index 550e9309f..7eaf51451 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java @@ -31,6 +31,7 @@ import org.apache.commons.math.stat.descriptive.rank.Min; import org.apache.commons.math.stat.descriptive.rank.Percentile; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.ResizableDoubleArray; @@ -68,14 +69,6 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { /** 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; @@ -314,7 +307,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { if (windowSize < 1) { if (windowSize != INFINITE_WINDOW) { throw MathRuntimeException.createIllegalArgumentException( - "window size must be positive ({0})", windowSize); + LocalizedFormats.NOT_POSITIVE_WINDOW_SIZE, windowSize); } } @@ -393,11 +386,11 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw MathRuntimeException.createIllegalArgumentException( - UNSUPPORTED_METHOD_MESSAGE, + LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw MathRuntimeException.createIllegalArgumentException( - ILLEGAL_ACCESS_MESSAGE, + LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); @@ -580,7 +573,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { percentileImpl.getClass().getName()); } catch (IllegalAccessException e2) { throw MathRuntimeException.createIllegalArgumentException( - ILLEGAL_ACCESS_MESSAGE, + LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java index ac5f0bd9f..af385219e 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java @@ -30,6 +30,7 @@ import org.apache.commons.math.stat.descriptive.rank.Min; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -613,7 +614,7 @@ public class MultivariateSummaryStatistics private void checkEmpty() { if (n > 0) { throw MathRuntimeException.createIllegalStateException( - "{0} values have been added before statistic is configured", + LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, n); } } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java b/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java index b456922cc..2d8b5bd74 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java @@ -28,6 +28,7 @@ import org.apache.commons.math.stat.descriptive.rank.Min; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import org.apache.commons.math.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; /** @@ -628,7 +629,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { private void checkEmpty() { if (n > 0) { throw MathRuntimeException.createIllegalStateException( - "{0} values have been added before statistic is configured", + LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, n); } } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java index 8883a1c40..be1c31bde 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java @@ -22,6 +22,7 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; +import org.apache.commons.math.util.LocalizedFormats; /** * Returns the @@ -194,7 +195,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen private void checkEmpty() { if (getN() > 0) { throw MathRuntimeException.createIllegalStateException( - "{0} values have been added before statistic is configured", + LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, getN()); } } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java index 5145de57c..5b488756a 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java @@ -20,6 +20,7 @@ import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -95,7 +96,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S moment.increment(d); } else { throw MathRuntimeException.createIllegalStateException( - "statistics constructed from external moments cannot be incremented"); + LocalizedFormats.CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS); } } @@ -129,7 +130,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S moment.clear(); } else { throw MathRuntimeException.createIllegalStateException( - "statistics constructed from external moments cannot be cleared"); + LocalizedFormats.CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS); } } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java index eac4788eb..3a219b496 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java @@ -20,6 +20,7 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic; +import org.apache.commons.math.util.LocalizedFormats; /** *

Computes the semivariance of a set of values with respect to a given cutoff value. @@ -175,7 +176,7 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); } return evaluate(values, 0, values.length); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java index 93f39b81e..1a0e43758 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.WeightedEvaluation; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.util.LocalizedFormats; /** * Computes the variance of the available values. By default, the unbiased @@ -213,7 +214,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); } return evaluate(values, 0, values.length); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java index 2fef265f0..06597769d 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java @@ -21,6 +21,7 @@ import java.util.Arrays; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic; +import org.apache.commons.math.util.LocalizedFormats; /** * Provides percentile computation. @@ -199,7 +200,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa if ((p > 100) || (p <= 0)) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds quantile value: {0}, must be in (0, 100]", p); + LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p); } if (length == 0) { return Double.NaN; @@ -248,7 +249,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa public void setQuantile(final double p) { if (p <= 0 || p > 100) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds quantile value: {0}, must be in (0, 100]", p); + LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p); } quantile = p; } diff --git a/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java b/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java index ec1a3951c..fa4263ae8 100644 --- a/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java +++ b/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java @@ -20,6 +20,7 @@ import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.distribution.ChiSquaredDistribution; import org.apache.commons.math.distribution.ChiSquaredDistributionImpl; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements Chi-Square test statistics defined in the @@ -65,12 +66,11 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { throws IllegalArgumentException { if (expected.length < 2) { throw MathRuntimeException.createIllegalArgumentException( - "expected array length = {0}, must be at least 2", - expected.length); + LocalizedFormats.INSUFFICIENT_DIMENSION, expected.length, 2); } if (expected.length != observed.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", expected.length, observed.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, expected.length, observed.length); } checkPositive(expected); checkNonNegative(observed); @@ -136,7 +136,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { double alpha) throws IllegalArgumentException, MathException { if ((alpha <= 0) || (alpha > 0.5)) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds significance level {0}, must be between {1} and {2}", + LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(expected, observed) < alpha; @@ -204,7 +204,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { throws IllegalArgumentException, MathException { if ((alpha <= 0) || (alpha > 0.5)) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds significance level {0}, must be between {1} and {2}", + LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0.0, 0.5); } return chiSquareTest(counts) < alpha; @@ -223,12 +223,11 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { // Make sure lengths are same if (observed1.length < 2) { throw MathRuntimeException.createIllegalArgumentException( - "observed array length = {0}, must be at least 2", - observed1.length); + LocalizedFormats.INSUFFICIENT_DIMENSION, observed1.length, 2); } if (observed1.length != observed2.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, observed1.length, observed2.length); } @@ -248,11 +247,11 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { // Ensure neither sample is uniformly 0 if (countSum1 == 0) { throw MathRuntimeException.createIllegalArgumentException( - "observed counts are all 0 in first observed array"); + LocalizedFormats.OBSERVED_COUNTS_ALL_ZERO, 1); } if (countSum2 == 0) { throw MathRuntimeException.createIllegalArgumentException( - "observed counts are all 0 in second observed array"); + LocalizedFormats.OBSERVED_COUNTS_ALL_ZERO, 2); } // Compare and compute weight only if different unequalCounts = countSum1 != countSum2; @@ -267,7 +266,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { for (int i = 0; i < observed1.length; i++) { if (observed1[i] == 0 && observed2[i] == 0) { throw MathRuntimeException.createIllegalArgumentException( - "observed counts are both zero for entry {0}", i); + LocalizedFormats.OBSERVED_COUNTS_BOTTH_ZERO_FOR_ENTRY, i); } else { obs1 = observed1[i]; obs2 = observed2[i]; @@ -311,7 +310,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { double alpha) throws IllegalArgumentException, MathException { if ((alpha <= 0) || (alpha > 0.5)) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds significance level {0}, must be between {1} and {2}", + LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0.0, 0.5); } return chiSquareTestDataSetsComparison(observed1, observed2) < alpha; @@ -329,14 +328,12 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { if (in.length < 2) { throw MathRuntimeException.createIllegalArgumentException( - "invalid row dimension: {0} (must be at least 2)", - in.length); + LocalizedFormats.INSUFFICIENT_DIMENSION, in.length, 2); } if (in[0].length < 2) { throw MathRuntimeException.createIllegalArgumentException( - "invalid column dimension: {0} (must be at least 2)", - in[0].length); + LocalizedFormats.INSUFFICIENT_DIMENSION, in[0].length, 2); } checkRectangular(in); @@ -357,7 +354,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { for (int i = 1; i < in.length; i++) { if (in[i].length != in[0].length) { throw MathRuntimeException.createIllegalArgumentException( - "some rows have length {0} while others have length {1}", + LocalizedFormats.DIFFERENT_ROWS_LENGTHS, in[i].length, in[0].length); } } @@ -373,7 +370,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { for (int i = 0; i < in.length; i++) { if (in[i] <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "element {0} is not positive: {1}", + LocalizedFormats.NOT_POSITIVE_ELEMENT_AT_INDEX, i, in[i]); } } @@ -389,7 +386,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { for (int i = 0; i < in.length; i++) { if (in[i] < 0) { throw MathRuntimeException.createIllegalArgumentException( - "element {0} is negative: {1}", + LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, i, in[i]); } } @@ -406,7 +403,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { for (int j = 0; j < in[i].length; j++) { if (in[i][j] < 0) { throw MathRuntimeException.createIllegalArgumentException( - "element ({0}, {1}) is negative: {2}", + LocalizedFormats.NEGATIVE_ELEMENT_AT_2D_INDEX, i, j, in[i][j]); } } diff --git a/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java b/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java index d5b6dbeb5..1e3862822 100644 --- a/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java +++ b/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java @@ -24,6 +24,7 @@ import org.apache.commons.math.distribution.FDistribution; import org.apache.commons.math.distribution.FDistributionImpl; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import org.apache.commons.math.util.LocalizedFormats; /** @@ -102,7 +103,7 @@ public class OneWayAnovaImpl implements OneWayAnova { throws IllegalArgumentException, MathException { if ((alpha <= 0) || (alpha > 0.5)) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds significance level {0}, must be between {1} and {2}", + LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return anovaPValue(categoryData) < alpha; @@ -125,7 +126,7 @@ public class OneWayAnovaImpl implements OneWayAnova { // check if we have enough categories if (categoryData.size() < 2) { throw MathRuntimeException.createIllegalArgumentException( - "two or more categories required, got {0}", + LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED, categoryData.size()); } @@ -133,7 +134,7 @@ public class OneWayAnovaImpl implements OneWayAnova { for (double[] array : categoryData) { if (array.length <= 1) { throw MathRuntimeException.createIllegalArgumentException( - "two or more values required in each category, one has {0}", + LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED, array.length); } } diff --git a/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java b/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java index 887fe71f2..2c552e1c5 100644 --- a/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java +++ b/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.math.distribution.TDistribution; import org.apache.commons.math.distribution.TDistributionImpl; import org.apache.commons.math.stat.StatUtils; import org.apache.commons.math.stat.descriptive.StatisticalSummary; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements t-test statistics defined in the {@link TTest} interface. @@ -33,10 +34,6 @@ 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; @@ -1030,7 +1027,7 @@ public class TTestImpl implements TTest { throws IllegalArgumentException { if ((alpha <= 0) || (alpha > 0.5)) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds significance level {0}, must be between {1} and {2}", + LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0.0, 0.5); } } @@ -1043,7 +1040,7 @@ public class TTestImpl implements TTest { throws IllegalArgumentException { if ((data == null) || (data.length < 2)) { throw MathRuntimeException.createIllegalArgumentException( - INSUFFICIENT_DATA_MESSAGE, + LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC, (data == null) ? 0 : data.length); } } @@ -1056,7 +1053,7 @@ public class TTestImpl implements TTest { throws IllegalArgumentException { if ((stat == null) || (stat.getN() < 2)) { throw MathRuntimeException.createIllegalArgumentException( - INSUFFICIENT_DATA_MESSAGE, + LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC, (stat == null) ? 0 : stat.getN()); } } diff --git a/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java b/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java index 6dc95e341..d8e68aadd 100644 --- a/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java +++ b/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java @@ -21,6 +21,7 @@ import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.Array2DRowRealMatrix; import org.apache.commons.math.linear.RealVector; import org.apache.commons.math.linear.ArrayRealVector; +import org.apache.commons.math.util.LocalizedFormats; /** * Abstract base class for implementations of MultipleLinearRegression. @@ -88,12 +89,12 @@ public abstract class AbstractMultipleLinearRegression implements protected void validateSampleData(double[][] x, double[] y) { if ((x == null) || (y == null) || (x.length != y.length)) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, (x == null) ? 0 : x.length, (y == null) ? 0 : y.length); } else if ((x.length > 0) && (x[0].length > x.length)) { throw MathRuntimeException.createIllegalArgumentException( - "not enough data ({0} rows) for this many predictors ({1} predictors)", + LocalizedFormats.NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS, x.length, x[0].length); } } @@ -109,11 +110,11 @@ public abstract class AbstractMultipleLinearRegression implements protected void validateCovarianceData(double[][] x, double[][] covariance) { if (x.length != covariance.length) { throw MathRuntimeException.createIllegalArgumentException( - "dimension mismatch {0} != {1}", x.length, covariance.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, x.length, covariance.length); } if (covariance.length > 0 && covariance.length != covariance[0].length) { throw MathRuntimeException.createIllegalArgumentException( - "a {0}x{1} matrix was provided instead of a square matrix", + LocalizedFormats.NON_SQUARE_MATRIX, covariance.length, covariance[0].length); } } diff --git a/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java b/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java index 78be61e70..f941c6e23 100644 --- a/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java +++ b/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java @@ -22,6 +22,7 @@ import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.distribution.TDistribution; import org.apache.commons.math.distribution.TDistributionImpl; +import org.apache.commons.math.util.LocalizedFormats; /** * Estimates an ordinary least squares regression model @@ -548,7 +549,7 @@ public class SimpleRegression implements Serializable { throws MathException { if (alpha >= 1 || alpha <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "out of bounds significance level {0}, must be between {1} and {2}", + LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0.0, 1.0); } return getSlopeStdErr() * diff --git a/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java b/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java index bcf61f3a8..9e9c1e6eb 100644 --- a/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java +++ b/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java @@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.complex.Complex; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the @@ -48,18 +49,6 @@ 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}])"; @@ -448,7 +437,7 @@ public class FastFourierTransformer implements Serializable { if (n <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "number of sample is not positive: {0}", + LocalizedFormats.NOT_POSITIVE_NUMBER_OF_SAMPLES, n); } verifyInterval(min, max); @@ -510,7 +499,7 @@ public class FastFourierTransformer implements Serializable { public static void verifyDataSet(double d[]) throws IllegalArgumentException { if (!isPowerOf2(d.length)) { throw MathRuntimeException.createIllegalArgumentException( - NOT_POWER_OF_TWO_MESSAGE, d.length); + LocalizedFormats.NOT_POWER_OF_TWO_CONSIDER_PADDING, d.length); } } @@ -523,7 +512,7 @@ public class FastFourierTransformer implements Serializable { public static void verifyDataSet(Object o[]) throws IllegalArgumentException { if (!isPowerOf2(o.length)) { throw MathRuntimeException.createIllegalArgumentException( - NOT_POWER_OF_TWO_MESSAGE, o.length); + LocalizedFormats.NOT_POWER_OF_TWO_CONSIDER_PADDING, o.length); } } @@ -677,13 +666,13 @@ public class FastFourierTransformer implements Serializable { if (vector == null) { if (dimensionSize.length > 0) { throw MathRuntimeException.createIllegalArgumentException( - DIMENSION_MISMATCH_MESSAGE, 0, dimensionSize.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, 0, dimensionSize.length); } return null; } if (vector.length != dimensionSize.length) { throw MathRuntimeException.createIllegalArgumentException( - DIMENSION_MISMATCH_MESSAGE, vector.length, dimensionSize.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, vector.length, dimensionSize.length); } Object lastDimension = multiDimensionalComplexArray; @@ -706,13 +695,13 @@ public class FastFourierTransformer implements Serializable { if (vector == null) { if (dimensionSize.length > 0) { throw MathRuntimeException.createIllegalArgumentException( - DIMENSION_MISMATCH_MESSAGE, 0, dimensionSize.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, 0, dimensionSize.length); } return null; } if (vector.length != dimensionSize.length) { throw MathRuntimeException.createIllegalArgumentException( - DIMENSION_MISMATCH_MESSAGE, vector.length,dimensionSize.length); + LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, vector.length,dimensionSize.length); } Object[] lastDimension = (Object[]) multiDimensionalComplexArray; @@ -827,8 +816,7 @@ public class FastFourierTransformer implements Serializable { public synchronized boolean isForward() throws IllegalStateException { if (omegaCount == 0) { - throw MathRuntimeException.createIllegalStateException( - MISSING_ROOTS_OF_UNITY_MESSAGE); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } return isForward; @@ -847,7 +835,7 @@ public class FastFourierTransformer implements Serializable { if (n == 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot compute 0-th root of unity, indefinite result"); + LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY); } isForward = n > 0; @@ -891,8 +879,7 @@ public class FastFourierTransformer implements Serializable { throws IllegalStateException, IllegalArgumentException { if (omegaCount == 0) { - throw MathRuntimeException.createIllegalStateException( - MISSING_ROOTS_OF_UNITY_MESSAGE); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } if ((k < 0) || (k >= omegaCount)) { throw MathRuntimeException.createIllegalArgumentException( @@ -914,8 +901,7 @@ public class FastFourierTransformer implements Serializable { throws IllegalStateException, IllegalArgumentException { if (omegaCount == 0) { - throw MathRuntimeException.createIllegalStateException( - MISSING_ROOTS_OF_UNITY_MESSAGE); + throw MathRuntimeException.createIllegalStateException(LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } if ((k < 0) || (k >= omegaCount)) { throw MathRuntimeException.createIllegalArgumentException( diff --git a/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java b/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java index 9b554ad40..c6a2c59d3 100644 --- a/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java +++ b/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java @@ -19,6 +19,7 @@ package org.apache.commons.math.transform; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the Fast Hadamard Transform (FHT). @@ -160,7 +161,7 @@ public class FastHadamardTransformer implements RealTransformer { // n has to be of the form n = 2^p !! if (!FastFourierTransformer.isPowerOf2(n)) { throw MathRuntimeException.createIllegalArgumentException( - "{0} is not a power of 2", + LocalizedFormats.NOT_POWER_OF_TWO, n); } @@ -211,7 +212,7 @@ public class FastHadamardTransformer implements RealTransformer { // n has to be of the form n = 2^p !! if (!FastFourierTransformer.isPowerOf2(n)) { throw MathRuntimeException.createIllegalArgumentException( - "{0} is not a power of 2", + LocalizedFormats.NOT_POWER_OF_TWO, n); } diff --git a/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java b/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java index 0ff9b77c6..e71385568 100644 --- a/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java +++ b/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java @@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.complex.Complex; +import org.apache.commons.math.util.LocalizedFormats; /** * Implements the = maxIterations) { throw new MaxIterationsExceededException(maxIterations, - "Continued fraction convergents failed to converge for value {0}", + LocalizedFormats.NON_CONVERGENT_CONTINUED_FRACTION, x); } diff --git a/src/main/java/org/apache/commons/math/util/DefaultTransformer.java b/src/main/java/org/apache/commons/math/util/DefaultTransformer.java index c40921e2e..63ceb5a70 100644 --- a/src/main/java/org/apache/commons/math/util/DefaultTransformer.java +++ b/src/main/java/org/apache/commons/math/util/DefaultTransformer.java @@ -44,7 +44,7 @@ public class DefaultTransformer implements NumberTransformer, Serializable { public double transform(Object o) throws MathException{ if (o == null) { - throw new MathException("Conversion Exception in Transformation, Object is null"); + throw new MathException(LocalizedFormats.NULL_OBJECT_TRANSFORMATION); } if (o instanceof Number) { @@ -55,7 +55,7 @@ public class DefaultTransformer implements NumberTransformer, Serializable { return Double.valueOf(o.toString()).doubleValue(); } catch (NumberFormatException e) { throw new MathException(e, - "Conversion Exception in Transformation: {0}", e.getMessage()); + LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, e.getMessage()); } } diff --git a/src/main/java/org/apache/commons/math/util/DummyLocalizable.java b/src/main/java/org/apache/commons/math/util/DummyLocalizable.java new file mode 100644 index 000000000..1de06d050 --- /dev/null +++ b/src/main/java/org/apache/commons/math/util/DummyLocalizable.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.util; + +import java.util.Locale; + +/** + * Dummy implementation of the {@link Localizable} interface, without localization. + * + * @version $Revision$ $Date$ + * @since 2.2 + */ +public class DummyLocalizable implements Localizable { + + /** Serializable version identifier. */ + private static final long serialVersionUID = 8843275624471387299L; + + /** Source string. */ + private final String source; + + /** Simple constructor. */ + public DummyLocalizable(final String source) { + this.source = source; + } + + /** {@inheritDoc} */ + public String getSourceString() { + return source; + } + + /** {@inheritDoc} */ + public String getLocalizedString(Locale locale) { + return source; + } + + /** {@inheritDoc} */ + public String toString() { + return source; + } + +} diff --git a/src/main/java/org/apache/commons/math/util/Localizable.java b/src/main/java/org/apache/commons/math/util/Localizable.java new file mode 100644 index 000000000..a3e12fe89 --- /dev/null +++ b/src/main/java/org/apache/commons/math/util/Localizable.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.util; + +import java.io.Serializable; +import java.util.Locale; + +/** + * Interface for localizable strings. + * + * @version $Revision$ $Date$ + * @since 2.2 + */ +public interface Localizable extends Serializable { + + /** + * Get the source (non-localized) string. + * @return source string + */ + String getSourceString(); + + /** + * Get the localized string. + * @param locale locale into which to get the string + * @return localized string or the source string if no localized version is available + */ + String getLocalizedString(Locale locale); + +} diff --git a/src/main/java/org/apache/commons/math/util/LocalizedFormats.java b/src/main/java/org/apache/commons/math/util/LocalizedFormats.java new file mode 100644 index 000000000..b3face8dc --- /dev/null +++ b/src/main/java/org/apache/commons/math/util/LocalizedFormats.java @@ -0,0 +1,314 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.util; + +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Enumeration for localized messages formats used for exemple + * in exceptions messages. + *

+ * The constants in this enumeration represent the available + * formats as localized strings. These formats are intended to be + * localized using simple properties files, using the constant + * name as the key and the property value as the message format. + * The source English format is provided in the constants themselves + * to serve both as a reminder for developers to understand the parameters + * needed by each format, as a basis for translators to create + * localized properties files, and as a default format if some + * translation is missing. + *

+ * @since 2.1 + * @version $Revision$ $Date$ + */ +public enum LocalizedFormats implements Localizable { + + // CHECKSTYLE: stop MultipleVariableDeclarations + + ARGUMENT_OUTSIDE_DOMAIN("Argument {0} outside domain [{1} ; {2}]"), + ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1("array sizes should have difference 1 ({0} != {1} + 1)"), + ASSYMETRIC_EIGEN_NOT_SUPPORTED("eigen decomposition of assymetric matrices not supported yet"), + AT_LEAST_ONE_COLUMN("matrix must have at least one column"), + AT_LEAST_ONE_ROW("matrix must have at least one row"), + BANDWIDTH_OUT_OF_INTERVAL("bandwidth must be in the interval [0,1], but got {0}"), + BINOMIAL_INVALID_PARAMETERS_ORDER("must have n >= k for binomial coefficient (n,k), got n = {0}, k = {1}"), + BINOMIAL_NEGATIVE_PARAMETER("must have n >= 0 for binomial coefficient (n,k), got n = {0}"), + CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS("statistics constructed from external moments cannot be cleared"), + CANNOT_COMPUTE_0TH_ROOT_OF_UNITY("cannot compute 0-th root of unity, indefinite result"), + CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N("cannot compute nth root for null or negative n: {0}"), + CANNOT_CONVERT_OBJECT_TO_FRACTION("cannot convert given object to a fraction number: {0}"), + CANNOT_DISCARD_NEGATIVE_NUMBER_OF_ELEMENTS("cannot discard a negative number of elements ({0})"), + CANNOT_FORMAT_INSTANCE_AS_3D_VECTOR("cannot format a {0} instance as a 3D vector"), + CANNOT_FORMAT_INSTANCE_AS_COMPLEX("cannot format a {0} instance as a complex number"), + CANNOT_FORMAT_INSTANCE_AS_REAL_VECTOR("cannot format a {0} instance as a real vector"), + CANNOT_FORMAT_OBJECT_TO_FRACTION("cannot format given object as a fraction number"), + CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS("statistics constructed from external moments cannot be incremented"), + CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR("cannot normalize a zero norm vector"), + CANNOT_RETRIEVE_AT_NEGATIVE_INDEX("elements cannot be retrieved from a negative array index {0}"), + CANNOT_SET_AT_NEGATIVE_INDEX("cannot set an element at a negative index {0}"), + CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY("cannot substitute an element from an empty array"), + CANNOT_TRANSFORM_TO_DOUBLE("Conversion Exception in Transformation: {0}"), + CARDAN_ANGLES_SINGULARITY("Cardan angles singularity"), + CLASS_DOESNT_IMPLEMENT_COMPARABLE("class ({0}) does not implement Comparable"), + CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT("the closest orthogonal matrix has a negative determinant {0}"), + COLUMN_INDEX_OUT_OF_RANGE("column index {0} out of allowed range [{1}, {2}]"), + CONTINUED_FRACTION_INFINITY_DIVERGENCE("Continued fraction convergents diverged to +/- infinity for value {0}"), + CONTINUED_FRACTION_NAN_DIVERGENCE("Continued fraction diverged to NaN for value {0}"), + CONTRACTION_CRITERIA_SMALLER_THAN_EXPANSION_FACTOR("contraction criteria ({0}) smaller than the expansion factor ({1}). This would lead to a never ending loop of expansion and contraction as a newly expanded internal storage array would immediately satisfy the criteria for contraction."), + CONTRACTION_CRITERIA_SMALLER_THAN_ONE("contraction criteria smaller than one ({0}). This would lead to a never ending loop of expansion and contraction as an internal storage array length equal to the number of elements would satisfy the contraction criteria."), + CONVERGENCE_FAILED("convergence failed"), + CUMULATIVE_PROBABILITY_RETURNED_NAN("Cumulative probability function returned NaN for argument {0} p = {1}"), + DIFFERENT_ROWS_LENGTHS("some rows have length {0} while others have length {1}"), + DIGEST_NOT_INITIALIZED("digest not initialized"), + DIMENSIONS_MISMATCH_2x2("dimensions mismatch: got {0}x{1} but expected {2}x{3}"), + DIMENSIONS_MISMATCH_SIMPLE("dimensions mismatch {0} != {1}"), + DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN("Discrete cumulative probability function returned NaN for argument {0}"), + DISTRIBUTION_NOT_LOADED("distribution not loaded"), + DUPLICATED_ABSCISSA("Abscissa {0} is duplicated at both indices {1} and {2}"), + EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY("empty polynomials coefficients array"), + EMPTY_SELECTED_COLUMN_INDEX_ARRAY("empty selected column index array"), + EMPTY_SELECTED_ROW_INDEX_ARRAY("empty selected row index array"), + EMPTY_STRING_FOR_IMAGINARY_CHARACTER("empty string for imaginary character"), + ENDPOINTS_NOT_AN_INTERVAL("endpoints do not specify an interval: [{0}, {1}]"), + EQUAL_VERTICES_IN_SIMPLEX("equal vertices {0} and {1} in simplex configuration"), + EULER_ANGLES_SINGULARITY("Euler angles singularity"), + EVALUATION_FAILED("evaluation failed for argument = {0}"), + EXPANSION_FACTOR_SMALLER_THAN_ONE("expansion factor smaller than one ({0})"), + FACTORIAL_NEGATIVE_PARAMETER("must have n >= 0 for n!, got n = {0}"), + FAILED_BRACKETING("number of iterations={0}, maximum iterations={1}, initial={2}, lower bound={3}, upper bound={4}, final a value={5}, final b value={6}, f(a)={7}, f(b)={8}"), + FAILED_FRACTION_CONVERSION("Unable to convert {0} to fraction after {1} iterations"), + FIRST_COLUMNS_NOT_INITIALIZED_YET("first {0} columns are not initialized yet"), + FIRST_ELEMENT_NOT_ZERO("first element is not 0: {0}"), + FIRST_ROWS_NOT_INITIALIZED_YET("first {0} rows are not initialized yet"), + FRACTION_CONVERSION_OVERFLOW("Overflow trying to convert {0} to fraction ({1}/{2})"), + FUNCTION_NOT_DIFFERENTIABLE("function is not differentiable"), + FUNCTION_NOT_POLYNOMIAL("function is not polynomial"), + GCD_OVERFLOW_32_BITS("overflow: gcd({0}, {1}) is 2^31"), + GCD_OVERFLOW_64_BITS("overflow: gcd({0}, {1}) is 2^63"), + HOLE_BETWEEN_MODELS_TIME_RANGES("{0} wide hole between models time ranges"), + IDENTICAL_ABSCISSAS_DIVISION_BY_ZERO("identical abscissas x[{0}] == x[{1}] == {2} cause division by zero"), + INDEX_LARGER_THAN_MAX("the index specified: {0} is larger than the current maximal index {1}"), + INDEX_NOT_POSITIVE("index ({0}) is not positive"), + INDEX_OUT_OF_RANGE("index {0} out of allowed range [{1}, {2}]"), + INFINITE_ARRAY_ELEMENT("Array contains an infinite element, {0} at index {1}"), + INFINITE_VALUE_CONVERSION("cannot convert infinite value"), + INITIAL_CAPACITY_NOT_POSITIVE("initial capacity ({0}) is not positive"), + INITIAL_COLUMN_AFTER_FINAL_COLUMN("initial column {0} after final column {1}"), + INITIAL_ROW_AFTER_FINAL_ROW("initial row {0} after final row {1}"), + INPUT_DATA_FROM_UNSUPPORTED_DATASOURCE("input data comes from unsupported datasource: {0}, supported sources: {1}, {2}"), + INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES("instance of class {0} not comparable to existing values"), + INSUFFICIENT_DATA_FOR_T_STATISTIC("insufficient data for t statistic, needs at least 2, got {0}"), + INSUFFICIENT_DIMENSION("insufficient dimension {0}, must be at least {1}"), + INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE("sample contains {0} observed points, at least {1} are required"), + INSUFFICIENT_ROWS_AND_COLUMNS("insufficient data: only {0} rows and {1} columns."), + INTEGRATION_METHOD_NEEDS_AT_LEAST_ONE_PREVIOUS_POINT("{0} method needs at least one previous point"), + INTERNAL_ERROR("internal error, please fill a bug report at {0}"), + INVALID_BRACKETING_PARAMETERS("invalid bracketing parameters: lower bound={0}, initial={1}, upper bound={2}"), + INVALID_INTERVAL_INITIAL_VALUE_PARAMETERS("invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}"), + INVALID_ITERATIONS_LIMITS("invalid iteration limits: min={0}, max={1}"), + INVALID_MAX_ITERATIONS("bad value for maximum iterations number: {0}"), + INVALID_ROUNDING_METHOD("invalid rounding method {0}, valid methods: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})"), + ITERATOR_EXHAUSTED("iterator exhausted"), + LCM_OVERFLOW_32_BITS("overflow: lcm({0}, {1}) is 2^31"), + LCM_OVERFLOW_64_BITS("overflow: lcm({0}, {1}) is 2^63"), + LOESS_EXPECTS_AT_LEAST_ONE_POINT("Loess expects at least 1 point"), + LOWER_BOUND_NOT_BELOW_UPPER_BOUND("upper bound ({0}) must be greater than lower bound ({1})"), + LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT("lower endpoint ({0}) must be less than or equal to upper endpoint ({1})"), + MAP_MODIFIED_WHILE_ITERATING("map has been modified while iterating"), + MAX_EVALUATIONS_EXCEEDED("maximal number of evaluations ({0}) exceeded"), + MAX_ITERATIONS_EXCEEDED("maximal number of iterations ({0}) exceeded"), + MINIMAL_STEPSIZE_REACHED_DURING_INTEGRATION("minimal step size ({0,number,0.00E00}) reached, integration needs {1,number,0.00E00}"), + MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS("Loess expects the abscissa and ordinate arrays to be of the same size, but got {0} abscissae and {1} ordinatae"), + NAN_VALUE_CONVERSION("cannot convert NaN value"), + NEGATIVE_BRIGHTNESS_EXPONENT("brightness exponent should be positive or null, but got {0}"), + NEGATIVE_COMPLEX_MODULE("negative complex module {0}"), + NEGATIVE_ELEMENT_AT_2D_INDEX("element ({0}, {1}) is negative: {2}"), + NEGATIVE_ELEMENT_AT_INDEX("element {0} is negative: {1}"), + NEGATIVE_LENGTH("length cannot be negative ({0})"), + NEGATIVE_NUMBER_OF_SUCCESSES("number of successes must be non-negative ({0})"), + NEGATIVE_NUMBER_OF_TRIALS("number of trials must be non-negative ({0})"), + NEGATIVE_ROBUSTNESS_ITERATIONS("the number of robustness iterations must be non-negative, but got {0}"), + NEGATIVE_START_POSITION("start position cannot be negative ({0})"), + NON_CONVERGENT_CONTINUED_FRACTION("Continued fraction convergents failed to converge for value {0}"), + NON_POSITIVE_MICROSPHERE_ELEMENTS("number of microsphere elements must be positive, but got {0}"), + NON_POSITIVE_POLYNOMIAL_DEGREE("polynomial degree must be positive: degree={0}"), + NON_REAL_FINITE_ABSCISSA("all abscissae must be finite real numbers, but {0}-th is {1}"), + NON_REAL_FINITE_ORDINATE("all ordinatae must be finite real numbers, but {0}-th is {1}"), + NON_REAL_FINITE_WEIGHT("all weights must be finite real numbers, but {0}-th is {1}"), + NON_SQUARE_MATRIX("a {0}x{1} matrix was provided instead of a square matrix"), + NORMALIZE_INFINITE("Cannot normalize to an infinite value"), + NORMALIZE_NAN("Cannot normalize to NaN"), + NOT_ADDITION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not addition compatible"), + NOT_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not decreasing ({2} < {3})"), + NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS("not enough data ({0} rows) for this many predictors ({1} predictors)"), + NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION("spline partition must have at least {0} points, got {1}"), + NOT_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not increasing ({2} > {3})"), + NOT_MULTIPLICATION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not multiplication compatible"), + NOT_POSITIVE_ALPHA("alpha must be positive ({0})"), + NOT_POSITIVE_BETA("beta must be positive ({0})"), + NOT_POSITIVE_COLUMNDIMENSION("invalid column dimension: {0} (must be positive)"), + NOT_POSITIVE_DEFINITE_MATRIX("not positive definite matrix"), + NOT_POSITIVE_DEGREES_OF_FREEDOM("degrees of freedom must be positive ({0})"), + NOT_POSITIVE_ELEMENT_AT_INDEX("element {0} is not positive: {1}"), + NOT_POSITIVE_EXPONENT("invalid exponent {0} (must be positive)"), + NOT_POSITIVE_LENGTH("length must be positive ({0})"), + NOT_POSITIVE_MEAN("mean must be positive ({0})"), + NOT_POSITIVE_NUMBER_OF_SAMPLES("number of sample is not positive: {0}"), + NOT_POSITIVE_PERMUTATION("permutation k ({0}) must be positive"), + NOT_POSITIVE_POISSON_MEAN("the Poisson mean must be positive ({0})"), + NOT_POSITIVE_POPULATION_SIZE("population size must be positive ({0})"), + NOT_POSITIVE_ROW_DIMENSION("invalid row dimension: {0} (must be positive)"), + NOT_POSITIVE_SAMPLE_SIZE("sample size must be positive ({0})"), + NOT_POSITIVE_SCALE("scale must be positive ({0})"), + NOT_POSITIVE_SHAPE("shape must be positive ({0})"), + NOT_POSITIVE_STANDARD_DEVIATION("standard deviation must be positive ({0})"), + NOT_POSITIVE_UPPER_BOUND("upper bound must be positive ({0})"), + NOT_POSITIVE_WINDOW_SIZE("window size must be positive ({0})"), + NOT_POWER_OF_TWO("{0} is not a power of 2"), + NOT_POWER_OF_TWO_CONSIDER_PADDING("{0} is not a power of 2, consider padding for fix"), + NOT_POWER_OF_TWO_PLUS_ONE("{0} is not a power of 2 plus one"), + NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not strictly decreasing ({2} <= {3})"), + NOT_STRICTLY_INCREASING_KNOT_VALUES("knot values must be strictly increasing"), + NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not strictly increasing ({2} >= {3})"), + NOT_SUBTRACTION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not subtraction compatible"), + NOT_SYMMETRIC_MATRIX("not symmetric matrix"), + NO_BIN_SELECTED("no bin selected"), + NO_CONVERGENCE_WITH_ANY_START_POINT("none of the {0} start points lead to convergence"), + NO_DATA("no data"), + NO_DEGREES_OF_FREEDOM("no degrees of freedom ({0} measurements, {1} parameters)"), + NO_DENSITY_FOR_THIS_DISTRIBUTION("This distribution does not have a density function implemented"), + NO_FEASIBLE_SOLUTION("no feasible solution"), + NO_OPTIMUM_COMPUTED_YET("no optimum computed yet"), + NO_RESULT_AVAILABLE("no result available"), + NO_SUCH_MATRIX_ENTRY("no entry at indices ({0}, {1}) in a {2}x{3} matrix"), + NULL_COVARIANCE_MATRIX("covariance matrix is null"), + NULL_DENOMINATOR("denominator is null"), + NULL_DENOMINATOR_FORMAT("denominator format can not be null"), + NULL_FRACTION("null fraction"), + NULL_FUNCTION("function is null"), + NULL_IMAGINARY_FORMAT("null imaginary format"), + NULL_INPUT_ARRAY("input values array is null"), + NULL_NUMERATOR("numerator is null"), + NULL_NUMERATOR_FORMAT("numerator format can not be null"), + NULL_OBJECT_TRANSFORMATION("Conversion Exception in Transformation, Object is null"), + NULL_REAL_FORMAT("null real format"), + NULL_WHOLE_FORMAT("whole format can not be null"), + NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE("number of successes ({0}) must be less than or equal to population size ({1})"), + NUMERATOR_OVERFLOW_AFTER_MULTIPLY("overflow, numerator too large after multiply: {0}"), + N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED("{0} points Legendre-Gauss integrator not supported, number of points must be in the {1}-{2} range"), + OBSERVED_COUNTS_ALL_ZERO("observed counts are all 0 in observed array {0}"), + OBSERVED_COUNTS_BOTTH_ZERO_FOR_ENTRY("observed counts are both zero for entry {0}"), + OUT_OF_BOUNDS_QUANTILE_VALUE("out of bounds quantile value: {0}, must be in (0, 100]"), + OUT_OF_BOUND_SIGNIFICANCE_LEVEL("out of bounds significance level {0}, must be between {1} and {2}"), + OUT_OF_ORDER_ABSCISSA_ARRAY("the abscissae array must be sorted in a strictly increasing order, but the {0}-th element is {1} whereas {2}-th is {3}"), + OUT_OF_RANGE_ROOT_OF_UNITY_INDEX("out of range root of unity index {0} (must be in [{1};{2}])"), + OUT_OF_RANGE_SIMPLE("{0} out of [{1}, {2}] range"), + OVERFLOW_IN_FRACTION("overflow in fraction {0}/{1}, cannot negate"), + PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD("cannot access {0} method in percentile implementation {1}"), + PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD("percentile implementation {0} does not support {1}"), + PERMUTATION_EXCEEDS_N("permutation k ({0}) exceeds n ({1})"), + POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS("number of polynomial interpolants must match the number of segments ({0} != {1} - 1)"), + POSITION_SIZE_MISMATCH_INPUT_ARRAY("position {0} and size {1} don't fit to the size of the input array {2}"), + POWER_NEGATIVE_PARAMETERS("cannot raise an integral value to a negative power ({0}^{1})"), + PROPAGATION_DIRECTION_MISMATCH("propagation direction mismatch"), + ROOTS_OF_UNITY_NOT_COMPUTED_YET("roots of unity have not been computed yet"), + ROTATION_MATRIX_DIMENSIONS("a {0}x{1} matrix cannot be a rotation matrix"), + ROW_INDEX_OUT_OF_RANGE("row index {0} out of allowed range [{1}, {2}]"), + SAME_SIGN_AT_ENDPOINTS("function values at endpoints do not have different signs, endpoints: [{0}, {1}], values: [{2}, {3}]"), + SAMPLE_SIZE_EXCEEDS_COLLECTION_SIZE("sample size ({0}) exceeds collection size ({1})"), + SAMPLE_SIZE_LARGER_THAN_POPULATION_SIZE("sample size ({0}) must be less than or equal to population size ({1})"), + SIMPLEX_NEED_ONE_POINT("simplex must contain at least one point"), + SIMPLE_MESSAGE("{0}"), + SINGULAR_MATRIX("matrix is singular"), + SUBARRAY_ENDS_AFTER_ARRAY_END("subarray ends after array end"), + TOO_LARGE_CUTOFF_SINGULAR_VALUE("cutoff singular value is {0}, should be at most {1}"), + TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY("cannot discard {0} elements from a {1} elements array"), + TOO_SMALL_BANDWIDTH("the bandwidth must be large enough to accomodate at least 2 points. There are {0} data points, and bandwidth must be at least {1} but it is only {2}"), + TOO_SMALL_COST_RELATIVE_TOLERANCE("cost relative tolerance is too small ({0}), no further reduction in the sum of squares is possible"), + TOO_SMALL_INTEGRATION_INTERVAL("too small integration interval: length = {0}"), + TOO_SMALL_ORTHOGONALITY_TOLERANCE("orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian"), + TOO_SMALL_PARAMETERS_RELATIVE_TOLERANCE("parameters relative tolerance is too small ({0}), no further improvement in the approximate solution is possible"), + TWO_OR_MORE_CATEGORIES_REQUIRED("two or more categories required, got {0}"), + TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED("two or more values required in each category, one has {0}"), + UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH("unable to bracket optimum in line search"), + UNABLE_TO_COMPUTE_COVARIANCE_SINGULAR_PROBLEM("unable to compute covariances: singular problem"), + UNABLE_TO_FIRST_GUESS_HARMONIC_COEFFICIENTS("unable to first guess the harmonic coefficients"), + UNABLE_TO_ORTHOGONOLIZE_MATRIX("unable to orthogonalize matrix in {0} iterations"), + UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JACOBIAN("unable to perform Q.R decomposition on the {0}x{1} jacobian matrix"), + UNABLE_TO_SOLVE_SINGULAR_PROBLEM("unable to solve: singular problem"), + UNBOUNDED_SOLUTION("unbounded solution"), + UNKNOWN_MODE("unknown mode {0}, known modes: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) and {11} ({12})"), + UNPARSEABLE_3D_VECTOR("unparseable 3D vector: \"{0}\""), + UNPARSEABLE_COMPLEX_NUMBER("unparseable complex number: \"{0}\""), + UNPARSEABLE_FRACTION_NUMBER("unparseable fraction number: \"{0}\""), + UNPARSEABLE_REAL_VECTOR("unparseable real vector: \"{0}\""), + UNSUPPORTED_EXPANSION_MODE("unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})"), + URL_CONTAINS_NO_DATA("URL {0} contains no data"), + VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC("{0} values have been added before statistic is configured"), + VECTOR_LENGTH_MISMATCH("vector length mismatch: got {0} but expected {1}"), + VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT("vector must have at least one element"), + WRONG_BLOCK_LENGTH("wrong array shape (block length = {0}, expected {1})"), + WRONG_NUMBER_OF_POINTS("{0} points are required, got only {1}"), + ZERO_DENOMINATOR("denominator must be different from 0"), + ZERO_DENOMINATOR_IN_FRACTION("zero denominator in fraction {0}/{1}"), + ZERO_FRACTION_TO_DIVIDE_BY("the fraction to divide by must not be zero: {0}/{1}"), + ZERO_NORM("zero norm"), + ZERO_NORM_FOR_ROTATION_AXIS("zero norm for rotation axis"), + ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR("zero norm for rotation defining vector"); + + // CHECKSTYLE: resume MultipleVariableDeclarations + + + /** Source English format. */ + private final String sourceFormat; + + /** Simple constructor. + * @param sourceFormat source English format to use when no + * localized version is available + */ + private LocalizedFormats(final String sourceFormat) { + this.sourceFormat = sourceFormat; + } + + /** {@inheritDoc} */ + public String getSourceString() { + return sourceFormat; + } + + /** {@inheritDoc} */ + public String getLocalizedString(final Locale locale) { + try { + ResourceBundle bundle = + ResourceBundle.getBundle("META-INF/localization/LocalizedFormats", locale); + if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) { + // the value of the resource is the translated format + return bundle.getString(toString()); + } + + } catch (MissingResourceException mre) { + // do nothing here + } + + // either the locale is not supported or the resource is unknown + // don't translate and fall back to using the source format + return sourceFormat; + + } + +} diff --git a/src/main/java/org/apache/commons/math/util/MathUtils.java b/src/main/java/org/apache/commons/math/util/MathUtils.java index 3eea7fc4d..d1fc5f8d4 100644 --- a/src/main/java/org/apache/commons/math/util/MathUtils.java +++ b/src/main/java/org/apache/commons/math/util/MathUtils.java @@ -362,12 +362,12 @@ public final class MathUtils { throws IllegalArgumentException { if (n < k) { throw MathRuntimeException.createIllegalArgumentException( - "must have n >= k for binomial coefficient (n,k), got n = {0}, k = {1}", + LocalizedFormats.BINOMIAL_INVALID_PARAMETERS_ORDER, n, k); } if (n < 0) { throw MathRuntimeException.createIllegalArgumentException( - "must have n >= 0 for binomial coefficient (n,k), got n = {0}", + LocalizedFormats.BINOMIAL_NEGATIVE_PARAMETER, n); } } @@ -593,7 +593,7 @@ public final class MathUtils { public static long factorial(final int n) { if (n < 0) { throw MathRuntimeException.createIllegalArgumentException( - "must have n >= 0 for n!, got n = {0}", + LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n); } if (n > 20) { @@ -626,7 +626,7 @@ public final class MathUtils { public static double factorialDouble(final int n) { if (n < 0) { throw MathRuntimeException.createIllegalArgumentException( - "must have n >= 0 for n!, got n = {0}", + LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n); } if (n < 21) { @@ -651,7 +651,7 @@ public final class MathUtils { public static double factorialLog(final int n) { if (n < 0) { throw MathRuntimeException.createIllegalArgumentException( - "must have n >= 0 for n!, got n = {0}", + LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n); } if (n < 21) { @@ -699,7 +699,7 @@ public final class MathUtils { if ((u == 0) || (v == 0)) { if ((u == Integer.MIN_VALUE) || (v == Integer.MIN_VALUE)) { throw MathRuntimeException.createArithmeticException( - "overflow: gcd({0}, {1}) is 2^31", + LocalizedFormats.GCD_OVERFLOW_32_BITS, p, q); } return Math.abs(u) + Math.abs(v); @@ -725,7 +725,7 @@ public final class MathUtils { } if (k == 31) { throw MathRuntimeException.createArithmeticException( - "overflow: gcd({0}, {1}) is 2^31", + LocalizedFormats.GCD_OVERFLOW_32_BITS, p, q); } // B2. Initialize: u and v have been divided by 2^k and at least @@ -788,7 +788,7 @@ public final class MathUtils { if ((u == 0) || (v == 0)) { if ((u == Long.MIN_VALUE) || (v == Long.MIN_VALUE)){ throw MathRuntimeException.createArithmeticException( - "overflow: gcd({0}, {1}) is 2^63", + LocalizedFormats.GCD_OVERFLOW_64_BITS, p, q); } return Math.abs(u) + Math.abs(v); @@ -814,7 +814,7 @@ public final class MathUtils { } if (k == 63) { throw MathRuntimeException.createArithmeticException( - "overflow: gcd({0}, {1}) is 2^63", + LocalizedFormats.GCD_OVERFLOW_64_BITS, p, q); } // B2. Initialize: u and v have been divided by 2^k and at least @@ -964,7 +964,7 @@ public final class MathUtils { int lcm = Math.abs(mulAndCheck(a / gcd(a, b), b)); if (lcm == Integer.MIN_VALUE) { throw MathRuntimeException.createArithmeticException( - "overflow: lcm({0}, {1}) is 2^31", + LocalizedFormats.LCM_OVERFLOW_32_BITS, a, b); } return lcm; @@ -999,7 +999,7 @@ public final class MathUtils { long lcm = Math.abs(mulAndCheck(a / gcd(a, b), b)); if (lcm == Long.MIN_VALUE){ throw MathRuntimeException.createArithmeticException( - "overflow: lcm({0}, {1}) is 2^63", + LocalizedFormats.LCM_OVERFLOW_64_BITS, a, b); } return lcm; @@ -1230,11 +1230,11 @@ public final class MathUtils { throws ArithmeticException, IllegalArgumentException { if (Double.isInfinite(normalizedSum)) { throw MathRuntimeException.createIllegalArgumentException( - "Cannot normalize to an infinite value"); + LocalizedFormats.NORMALIZE_INFINITE); } if (Double.isNaN(normalizedSum)) { throw MathRuntimeException.createIllegalArgumentException( - "Cannot normalize to NaN"); + LocalizedFormats.NORMALIZE_NAN); } double sum = 0d; final int len = values.length; @@ -1242,7 +1242,7 @@ public final class MathUtils { for (int i = 0; i < len; i++) { if (Double.isInfinite(values[i])) { throw MathRuntimeException.createArithmeticException( - "Array contains an infinite element, {0} at index {1}", values[i], i); + LocalizedFormats.INFINITE_ARRAY_ELEMENT, values[i], i); } if (!Double.isNaN(values[i])) { sum += values[i]; @@ -1588,7 +1588,7 @@ public final class MathUtils { if (e < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1618,7 +1618,7 @@ public final class MathUtils { if (e < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1648,7 +1648,7 @@ public final class MathUtils { if (e < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1678,7 +1678,7 @@ public final class MathUtils { if (e < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1708,7 +1708,7 @@ public final class MathUtils { if (e < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1728,7 +1728,7 @@ public final class MathUtils { if (e < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1758,7 +1758,7 @@ public final class MathUtils { if (e.compareTo(BigInteger.ZERO) < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot raise an integral value to a negative power ({0}^{1})", + LocalizedFormats.POWER_NEGATIVE_PARAMETERS, k, e); } @@ -1884,24 +1884,24 @@ public final class MathUtils { if (dir > 0) { if (strict) { if (val[i] <= previous) { - throw MathRuntimeException.createIllegalArgumentException("points {0} and {1} are not strictly increasing ({2} >= {3})", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS, i - 1, i, previous, val[i]); } } else { if (val[i] < previous) { - throw MathRuntimeException.createIllegalArgumentException("points {0} and {1} are not increasing ({2} > {3})", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_INCREASING_NUMBER_OF_POINTS, i - 1, i, previous, val[i]); } } } else { if (strict) { if (val[i] >= previous) { - throw MathRuntimeException.createIllegalArgumentException("points {0} and {1} are not strictly decreasing ({2} <= {3})", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS, i - 1, i, previous, val[i]); } } else { if (val[i] > previous) { - throw MathRuntimeException.createIllegalArgumentException("points {0} and {1} are not decreasing ({2} < {3})", + throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_DECREASING_NUMBER_OF_POINTS, i - 1, i, previous, val[i]); } } diff --git a/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java b/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java index e0f38ae16..447e29dcd 100644 --- a/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java +++ b/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java @@ -50,14 +50,6 @@ 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; @@ -534,11 +526,10 @@ public class OpenIntToDoubleHashMap implements Serializable { public int key() throws ConcurrentModificationException, NoSuchElementException { if (referenceCount != count) { - throw MathRuntimeException.createConcurrentModificationException( - CONCURRENT_MODIFICATION_MESSAGE); + throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING); } if (current < 0) { - throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE); + throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED); } return keys[current]; } @@ -552,11 +543,10 @@ public class OpenIntToDoubleHashMap implements Serializable { public double value() throws ConcurrentModificationException, NoSuchElementException { if (referenceCount != count) { - throw MathRuntimeException.createConcurrentModificationException( - CONCURRENT_MODIFICATION_MESSAGE); + throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING); } if (current < 0) { - throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE); + throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED); } return values[current]; } @@ -570,8 +560,7 @@ public class OpenIntToDoubleHashMap implements Serializable { throws ConcurrentModificationException, NoSuchElementException { if (referenceCount != count) { - throw MathRuntimeException.createConcurrentModificationException( - CONCURRENT_MODIFICATION_MESSAGE); + throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING); } // advance on step @@ -585,7 +574,7 @@ public class OpenIntToDoubleHashMap implements Serializable { } catch (ArrayIndexOutOfBoundsException e) { next = -2; if (current < 0) { - throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE); + throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED); } } diff --git a/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java b/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java index 61867f8b1..925cf9a31 100644 --- a/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java +++ b/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java @@ -53,14 +53,6 @@ public class OpenIntToFieldHashMap> 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; @@ -546,11 +538,10 @@ public class OpenIntToFieldHashMap> implements Seriali public int key() throws ConcurrentModificationException, NoSuchElementException { if (referenceCount != count) { - throw MathRuntimeException.createConcurrentModificationException( - CONCURRENT_MODIFICATION_MESSAGE); + throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING); } if (current < 0) { - throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE); + throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED); } return keys[current]; } @@ -564,11 +555,10 @@ public class OpenIntToFieldHashMap> implements Seriali public T value() throws ConcurrentModificationException, NoSuchElementException { if (referenceCount != count) { - throw MathRuntimeException.createConcurrentModificationException( - CONCURRENT_MODIFICATION_MESSAGE); + throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING); } if (current < 0) { - throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE); + throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED); } return values[current]; } @@ -582,8 +572,7 @@ public class OpenIntToFieldHashMap> implements Seriali throws ConcurrentModificationException, NoSuchElementException { if (referenceCount != count) { - throw MathRuntimeException.createConcurrentModificationException( - CONCURRENT_MODIFICATION_MESSAGE); + throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING); } // advance on step @@ -597,7 +586,7 @@ public class OpenIntToFieldHashMap> implements Seriali } catch (ArrayIndexOutOfBoundsException e) { next = -2; if (current < 0) { - throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE); + throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED); } } diff --git a/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java b/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java index 9ae790db0..6d49756bc 100644 --- a/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java +++ b/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java @@ -321,7 +321,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { public synchronized double substituteMostRecentElement(double value) { if (numElements < 1) { throw MathRuntimeException.createArrayIndexOutOfBoundsException( - "cannot substitute an element from an empty array"); + LocalizedFormats.CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY); } double discarded = internalArray[startIndex + (numElements - 1)]; @@ -362,7 +362,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { if (expansion <= 1.0) { throw MathRuntimeException.createIllegalArgumentException( - "expansion factor smaller than one ({0})", + LocalizedFormats.EXPANSION_FACTOR_SMALLER_THAN_ONE, expansion); } } @@ -449,11 +449,11 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { private synchronized void discardExtremeElements(int i,boolean front) { if (i > numElements) { throw MathRuntimeException.createIllegalArgumentException( - "cannot discard {0} elements from a {1} elements array", + LocalizedFormats.TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY, i, numElements); } else if (i < 0) { throw MathRuntimeException.createIllegalArgumentException( - "cannot discard a negative number of elements ({0})", + LocalizedFormats.CANNOT_DISCARD_NEGATIVE_NUMBER_OF_ELEMENTS, i); } else { // "Subtract" this number of discarded from numElements @@ -533,13 +533,13 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { public synchronized double getElement(int index) { if (index >= numElements) { throw MathRuntimeException.createArrayIndexOutOfBoundsException( - "the index specified: {0} is larger than the current maximal index {1}", + LocalizedFormats.INDEX_LARGER_THAN_MAX, index, numElements - 1); } else if (index >= 0) { return internalArray[startIndex + index]; } else { throw MathRuntimeException.createArrayIndexOutOfBoundsException( - "elements cannot be retrieved from a negative array index {0}", + LocalizedFormats.CANNOT_RETRIEVE_AT_NEGATIVE_INDEX, index); } } @@ -668,7 +668,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { public synchronized void setElement(int index, double value) { if (index < 0) { throw MathRuntimeException.createArrayIndexOutOfBoundsException( - "cannot set an element at a negative index {0}", + LocalizedFormats.CANNOT_SET_AT_NEGATIVE_INDEX, index); } if (index + 1 > numElements) { @@ -710,7 +710,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { if (expansionMode != MULTIPLICATIVE_MODE && expansionMode != ADDITIVE_MODE) { throw MathRuntimeException.createIllegalArgumentException( - "unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})", + LocalizedFormats.UNSUPPORTED_EXPANSION_MODE, expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE", ADDITIVE_MODE, "ADDITIVE_MODE"); } @@ -733,7 +733,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { } } else { throw MathRuntimeException.createIllegalArgumentException( - "initial capacity ({0}) is not positive", + LocalizedFormats.INITIAL_CAPACITY_NOT_POSITIVE, initialCapacity); } } @@ -751,7 +751,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { // If index is negative thrown an error if (i < 0) { throw MathRuntimeException.createIllegalArgumentException( - "index ({0}) is not positive", + LocalizedFormats.INDEX_NOT_POSITIVE, i); } diff --git a/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties b/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties new file mode 100644 index 000000000..1aa6cdd95 --- /dev/null +++ b/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties @@ -0,0 +1,230 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1 = les tableaux devraient avoir une diff\u00e9rence de taille de 1 ({0} != {1} + 1) +ASSYMETRIC_EIGEN_NOT_SUPPORTED = la d\u00e9composition en valeurs/vecteurs propres de matrices +AT_LEAST_ONE_COLUMN = une matrice doit comporter au moins une colonne +AT_LEAST_ONE_ROW = une matrice doit comporter au moins une ligne +BINOMIAL_INVALID_PARAMETERS_ORDER = n doit \u00eatre sup\u00e9rieur ou \u00e9gal \u00e0 k pour le coefficient du bin\u00f4me (n,k), or n = {0}, k = {1} +BINOMIAL_NEGATIVE_PARAMETER = n doit \u00eatre positif pour le coefficient du bin\u00f4me (n,k), or n = {0} +CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS = les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro +CANNOT_COMPUTE_0TH_ROOT_OF_UNITY = impossible de calculer la racine z\u00e9roi\u00e8me de l''unit\u00e9, +CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N = impossible de calculer la racine ni\u00e8me pour n n\u00e9gatif ou nul : {0} +CANNOT_CONVERT_OBJECT_TO_FRACTION = impossible de convertir l''objet sous forme d''un nombre rationnel : {0} +CANNOT_DISCARD_NEGATIVE_NUMBER_OF_ELEMENTS = impossible d''enlever un nombre d''\u00e9l\u00e9ments{0} n\u00e9gatif +CANNOT_FORMAT_INSTANCE_AS_3D_VECTOR = impossible de formater une instance de {0} comme un vecteur de dimension 3 +CANNOT_FORMAT_INSTANCE_AS_COMPLEX = impossible de formater une instance de {0} comme un nombre complexe +CANNOT_FORMAT_INSTANCE_AS_REAL_VECTOR = impossible de formater une instance de {0} comme un vecteur r\u00e9el +CANNOT_FORMAT_OBJECT_TO_FRACTION = impossible de formater l''objet sous forme d''un nombre rationnel +CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS = les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre incr\u00e9ment\u00e9es +CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR = impossible de normer un vecteur de norme nulle +CANNOT_RETRIEVE_AT_NEGATIVE_INDEX = impossible d''extraire un \u00e9l\u00e9ment \u00e0 un index n\u00e9gatif ({0}) +CANNOT_SET_AT_NEGATIVE_INDEX = impossible de mettre un \u00e9l\u00e9ment \u00e0 un index n\u00e9gatif ({0}) +CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY = impossible de substituer un \u00e9l\u00e9ment dans un tableau vide +CANNOT_TRANSFORM_TO_DOUBLE = Exception de conversion dans une transformation : {0} +CARDAN_ANGLES_SINGULARITY = singularit\u00e9 d''angles de Cardan +CLASS_DOESNT_IMPLEMENT_COMPARABLE = la classe ({0}) n''implante pas l''interface Comparable +CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT = la matrice orthogonale la plus proche a un d\u00e9terminant n\u00e9gatif {0} +CONTINUED_FRACTION_INFINITY_DIVERGENCE = Divergence de fraction continue \u00e0 l''infini pour la valeur {0} +CONTINUED_FRACTION_NAN_DIVERGENCE = Divergence de fraction continue \u00e0 NaN pour la valeur {0} +CONTRACTION_CRITERIA_SMALLER_THAN_EXPANSION_FACTO = crit\u00e8re de contraction ({0}) inf\u00e9rieur au facteur d''extension. Ceci induit une boucle infinie d''extensions/contractions car tout tableau de stockage fra\u00eechement \u00e9tendu respecte imm\u00e9diatement le crit\u00e8re de contraction. +CONTRACTION_CRITERIA_SMALLER_THAN_ONE = crit\u00e8re de contraction inf\u00e9rieur \u00e0 un ({0}). Ceci induit une boucle infinie d''extensions/contractions car tout tableau de stockage de longueur \u00e9gale au nombre d''\u00e9l\u00e9ments respecte le crit\u00e8re de contraction. +CONVERGENCE_FAILED = \u00c9chec de convergence +CUMULATIVE_PROBABILITY_RETURNED_NAN = Fonction de probabilit\u00e9 cumulative retourn\u00e9 NaN \u00e0 l''argument de {0} p = {1} +DIFFERENT_ROWS_LENGTHS = certaines lignes ont une longueur de {0} alors que d''autres ont une longueur de {1} +DIGEST_NOT_INITIALIZED = mod\u00e8le empirique non initialis\u00e9 +DIMENSIONS_MISMATCH_2x2 = dimensions incoh\u00e9rentes : {0}x{1} \u00e0 la place de {2}x{3} +DIMENSIONS_MISMATCH_SIMPLE = dimensions incoh\u00e9rentes {0} != {1} +DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN = Discr\u00e8tes fonction de probabilit\u00e9 cumulative retourn\u00e9 NaN \u00e0 l''argument de {0} +DISTRIBUTION_NOT_LOADED = aucune distribution n''a \u00e9t\u00e9 charg\u00e9e +DUPLICATED_ABSCISSA = Abscisse {0} dupliqu\u00e9e aux indices {1} et {2} +EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY = tableau de coefficients polyn\u00f4miaux vide +EMPTY_SELECTED_COLUMN_INDEX_ARRAY = tableau des indices de colonnes s\u00e9lectionn\u00e9es vide +EMPTY_SELECTED_ROW_INDEX_ARRAY = tableau des indices de lignes s\u00e9lectionn\u00e9es vide +EMPTY_STRING_FOR_IMAGINARY_CHARACTER = cha\u00eene vide pour le caract\u00e8 imaginaire +EQUAL_VERTICES_IN_SIMPLEX = sommets {0} et {1} \u00e9gaux dans la configuration du simplex +EULER_ANGLES_SINGULARITY = singularit\u00e9 d''angles d''Euler +EVALUATION_FAILED = erreur d''\u00e9valuation pour l''argument {0} +EXPANSION_FACTOR_SMALLER_THAN_ONE = facteur d''extension inf\u00e9rieur \u00e0 un ({0}) +FACTORIAL_NEGATIVE_PARAMETER = n doit \u00eatre positif pour le calcul de n!, or n = {0} +FAILED_BRACKETING = nombre d''it\u00e9rations = {0}, it\u00e9rations maximum = {1}, valeur initiale = {2}, borne inf\u00e9rieure = {3}, borne sup\u00e9rieure = {4}, valeur a finale = {5}, valeur b finale = {6}, f(a) = {7}, f(b) = {8} +FAILED_FRACTION_CONVERSION = Impossible de convertir {0} en fraction apr\u00e8s {1} it\u00e9rations +FIRST_COLUMNS_NOT_INITIALIZED_YET = les {0} premi\u00e8res colonnes ne sont pas encore initialis\u00e9es +FIRST_ELEMENT_NOT_ZERO = le premier \u00e9l\u00e9ment n''est pas nul : {0} +FIRST_ROWS_NOT_INITIALIZED_YET = les {0} premi\u00e8res lignes ne sont pas encore initialis\u00e9es +FRACTION_CONVERSION_OVERFLOW = D\u00e9passement de capacit\u00e9 lors de la conversion de {0} en fraction ({1}/{2}) +FUNCTION_NOT_DIFFERENTIABLE = la fonction n''est pas diff\u00e9rentiable +FUNCTION_NOT_POLYNOMIAL = la fonction n''est pas p\u00f4lynomiale +GCD_OVERFLOW_32_BITS = d\u00e9passement de capacit\u00e9 : le PGCD de {0} et {1} vaut 2^31 +GCD_OVERFLOW_64_BITS = d\u00e9passement de capacit\u00e9 : le PGCD de {0} et {1} vaut 2^63 +HOLE_BETWEEN_MODELS_TIME_RANGES = trou de longueur {0} entre les domaines temporels des mod\u00e8les +INDEX_LARGER_THAN_MAX = l''index sp\u00e9cifi\u00e9 ({0}) d\u00e9passe l''index maximal courant ({1}) +INDEX_NOT_POSITIVE = l''indice ({0}) n''est pas positif +INFINITE_ARRAY_ELEMENT = le tableau contient l''\u00e9l\u00e9ment infini {0} \u00e0 l''index {1} +INFINITE_VALUE_CONVERSION = les valeurs infinies ne peuvent \u00eatre converties +INITIAL_CAPACITY_NOT_POSITIVE = la capacit\u00e9 initiale ({0}) n''est pas positive +INITIAL_COLUMN_AFTER_FINAL_COLUMN = colonne initiale {0} apr\u00e8s la colonne finale {1} +INITIAL_ROW_AFTER_FINAL_ROW = ligne initiale {0} apr\u00e8s la ligne finale {1} +INPUT_DATA_FROM_UNSUPPORTED_DATASOURCE = les donn\u00e9es d''entr\u00e9e proviennent +INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES = l''instance de la classe {0} n''est pas comparable aux valeurs existantes +INSUFFICIENT_DATA_FOR_T_STATISTIC = deux valeurs ou plus sont n\u00e9cessaires pour la statistique t, il y en a {0} +INSUFFICIENT_DIMENSION = dimension {0} insuffisante, elle devrait \u00eatre au moins {1} +INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE = l''\u00e9chantillon ne contient que {0} points alors qu''au moins {1} sont n\u00e9cessaires +INSUFFICIENT_ROWS_AND_COLUMNS = donn\u00e9es insuffisantes : seulement {0} lignes et {1} colonnes. +INTEGRATION_METHOD_NEEDS_AT_LEAST_ONE_PREVIOUS_POINT = la m\u00e9thode {0} n\u00e9cessite au moins un point pr\u00e9c\u00e9dent +INTERNAL_ERROR = erreur interne, veuillez signaler l''erreur \u00e0 {0} +INVALID_BRACKETING_PARAMETERS = param\u00e8tres d''encadrement invalides : borne inf\u00e9rieure = {0}, valeur initiale = {1}, borne sup\u00e9rieure = {2} +INVALID_INTERVAL_INITIAL_VALUE_PARAMETERS = param\u00e8tres de l''intervalle initial invalides : borne inf = {0}, valeur initiale = {1}, borne sup = {2} +INVALID_ITERATIONS_LIMITS = limites d''it\u00e9rations invalides : min = {0}, max = {1} +INVALID_MAX_ITERATIONS = valeur invalide pour le nombre maximal d''it\u00e9rations : {0} +INVALID_ROUNDING_METHOD = 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}) +ITERATOR_EXHAUSTED = it\u00e9ration achev\u00e9e +LCM_OVERFLOW_32_BITS = d\u00e9passement de capacit\u00e9 : le MCM de {0} et {1} vaut 2^31 +LCM_OVERFLOW_64_BITS = d\u00e9passement de capacit\u00e9 : le MCM de {0} et {1} vaut 2^63 +LOESS_EXPECTS_AT_LEAST_ONE_POINT = la r\u00e9gression Loess n\u00e9cessite au moins un point +LOWER_BOUND_NOT_BELOW_UPPER_BOUND = la borne sup\u00e9rieure ({0}) doit \u00eatre sup\u00e9rieure +LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT = la borne inf\u00e9rieure ({0}) devrait \u00eatre inf\u00e9rieure +MAP_MODIFIED_WHILE_ITERATING = la table d''adressage a \u00e9t\u00e9 modifi\u00e9e pendant l''it\u00e9ration +MAX_EVALUATIONS_EXCEEDED = nombre maximal d''\u00e9valuations ({0}) d\u00e9pass\u00e9 +MAX_ITERATIONS_EXCEEDED = nombre maximal d''it\u00e9rations ({0}) d\u00e9pass\u00e9 +MINIMAL_STEPSIZE_REACHED_DURING_INTEGRATION = pas minimal ({0,number,0.00E00}) atteint, l''int\u00e9gration n\u00e9cessite {1,number,0.00E00} +NAN_VALUE_CONVERSION = les valeurs NaN ne peuvent \u00eatre converties +NEGATIVE_BRIGHTNESS_EXPONENT = l''exposant de brillance devrait \u00eatre positif ou null, or e = {0} +NEGATIVE_COMPLEX_MODULE = module n\u00e9gatif ({0}) pour un nombre complexe +NEGATIVE_ELEMENT_AT_2D_INDEX = l''\u00e9l\u00e9ment ({0}, {1}) est n\u00e9gatif : {2} +NEGATIVE_ELEMENT_AT_INDEX = l''\u00e9l\u00e9ment {0} est n\u00e9gatif : {1} +NEGATIVE_LENGTH = la longueur ne peut pas \u00eatre n\u00e9gative +NEGATIVE_NUMBER_OF_SUCCESSES = le nombre de succ\u00e8s ne doit pas \u00eatre n\u00e9gatif ({0}) +NEGATIVE_NUMBER_OF_TRIALS = le nombre d''essais ne doit pas \u00eatre n\u00e9gatif ({0}) +NEGATIVE_ROBUSTNESS_ITERATIONS = le nombre d''it\u00e9rations robuste ne peut \u00eatre n\u00e9gatif, alors qu''il est de {0} +NEGATIVE_START_POSITION = la position de d\u00e9part ne peut pas \u00eatre n\u00e9gative +NON_CONVERGENT_CONTINUED_FRACTION = \u00c9chec de convergence de fraction continue pour la valeur {0} +NON_POSITIVE_MICROSPHERE_ELEMENTS = le nombre d''\u00e9l\u00e9ments de la microsph\u00e8re devrait \u00eatre positif, or n = {0} +NON_POSITIVE_POLYNOMIAL_DEGREE = le polyn\u00f4me doit \u00eatre de degr\u00e9 positif : degr\u00e9 = {0} +NON_REAL_FINITE_ABSCISSA = toutes les abscisses doivent \u00eatre des nombres r\u00e9els finis, mais l''abscisse {0} vaut {1} +NON_REAL_FINITE_ORDINATE = toutes les ordonn\u00e9es doivent \u00eatre des nombres r\u00e9els finis, mais l''ordonn\u00e9e {0} vaut {1} +NON_REAL_FINITE_WEIGHT = tous les poids doivent \u00eatre des nombres r\u00e9els finis, mais le poids {0} vaut {1} +NON_SQUARE_MATRIX = une matrice {0}x{1} a \u00e9t\u00e9 fournie \u00e0 la place d''une matrice carr\u00e9e +NORMALIZE_INFINITE = impossible de normaliser vers une valeur infinie +NORMALIZE_NAN = impossible de normaliser vers NaN +NOT_ADDITION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour l''addition matricielle +NOT_DECREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas d\u00e9croissants ({2} < {3}) +NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS = pas assez de donn\u00e9es ({0} lignes) pour {1} pr\u00e9dicteurs +NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION = une partiction spline n\u00e9cessite au moins {0} points, seuls {1} ont \u00e9t\u00e9 fournis +NOT_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas croissants ({2} > {3}) +NOT_MULTIPLICATION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la multiplication matricielle +NOT_POSITIVE_ALPHA = alpha doit \u00eatre positif ({0}) +NOT_POSITIVE_BETA = beta doit \u00eatre positif ({0}) +NOT_POSITIVE_COLUMNDIMENSION = nombre de colonnes invalide : {0} (doit \u00eatre positif) +NOT_POSITIVE_DEFINITE_MATRIX = matrice non d\u00e9finie positive +NOT_POSITIVE_DEGREES_OF_FREEDOM = les degr\u00e9s de libert\u00e9 doivent \u00eatre positifs ({0}) +NOT_POSITIVE_ELEMENT_AT_INDEX = l''\u00e9l\u00e9ment {0} n''est pas positif : {1} +NOT_POSITIVE_EXPONENT = exposant {0} invalide (doit \u00eatre positif) +NOT_POSITIVE_LENGTH = la longueur doit \u00eatre positive ({0}) +NOT_POSITIVE_MEAN = la moyenne doit \u00eatre positive ({0}) +NOT_POSITIVE_NUMBER_OF_SAMPLES = le nombre d''\u00e9chantillons n''est pas positif : {0} +NOT_POSITIVE_PERMUTATION = la permutation k ({0}) doit \u00eatre positive +NOT_POSITIVE_POISSON_MEAN = la moyenne de Poisson doit \u00eatre positive ({0}) +NOT_POSITIVE_POPULATION_SIZE = la taille de la population doit \u00eatre positive ({0}) +NOT_POSITIVE_ROW_DIMENSION = nombre de lignes invalide : {0} (doit \u00eatre positif) +NOT_POSITIVE_SAMPLE_SIZE = la taille de l''\u00e9chantillon doit \u00eatre positive ({0}) +NOT_POSITIVE_SCALE = l''\u00e9chelle doit \u00eatre positive ({0}) +NOT_POSITIVE_SHAPE = le facteur de forme doit \u00eatre positif ({0}) +NOT_POSITIVE_STANDARD_DEVIATION = l''\u00e9cart type doit \u00eatre positif ({0}) +NOT_POSITIVE_UPPER_BOUND = la borne sup\u00e9rieure doit \u00eatre positive ({0}) +NOT_POSITIVE_WINDOW_SIZE = la taille de la fen\u00eatre doit \u00eatre positive ({0}) +NOT_POWER_OF_TWO = {0} n''est pas une puissance de 2 +NOT_POWER_OF_TWO_CONSIDER_PADDING = {0} n''est pas une puissance de 2, ajoutez des \u00e9l\u00e9ments pour corriger +NOT_POWER_OF_TWO_PLUS_ONE = {0} n''est pas une puissance de 2 plus un +NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas strictement d\u00e9croissants ({2} <= {3}) +NOT_STRICTLY_INCREASING_KNOT_VALUES = les n\u0153uds d''interpolation doivent \u00eatre strictement croissants +NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas strictement croissants ({2} >= {3}) +NOT_SUBTRACTION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la soustraction matricielle +NOT_SYMMETRIC_MATRIX = matrice non symm\u00e9trique +NO_BIN_SELECTED = aucun compartiment s\u00e9lectionn\u00e9 +NO_CONVERGENCE_WITH_ANY_START_POINT = aucun des {0} points de d\u00e9part n''aboutit \u00e0 une convergence +NO_DATA = aucune donn\u00e9e +NO_DEGREES_OF_FREEDOM = aucun degr\u00e9 de libert\u00e9 ({0} mesures, {1} param\u00e8tres) +NO_DENSITY_FOR_THIS_DISTRIBUTION = La fonction de densit\u00e9 pour cette distribution n''a pas \u00e9t\u00e9 mis en \u0153uvre +NO_FEASIBLE_SOLUTION = aucune solution r\u00e9alisable +NO_OPTIMUM_COMPUTED_YET = aucun optimum n''a encore \u00e9t\u00e9 calcul\u00e9 +NO_RESULT_AVAILABLE = aucun r\u00e9sultat n''est disponible +NO_SUCH_MATRIX_ENTRY = pas d''\u00e9l\u00e9ment ({0}, {1}) dans une matrice {2}x{3} +NULL_COVARIANCE_MATRIX = la matrice de covariance est nulle +NULL_DENOMINATOR = le d\u00e9nominateur est null +NULL_DENOMINATOR_FORMAT = le format du d\u00e9nominateur ne doit pas \u00eatre nul +NULL_FRACTION = fraction nulle +NULL_FUNCTION = la fonction est nulle +NULL_IMAGINARY_FORMAT = format imaginaire nul +NULL_INPUT_ARRAY = le tableau des valeurs d''entr\u00e9es est nul +NULL_NUMERATOR = le num\u00e9rateur est null +NULL_NUMERATOR_FORMAT = le format du num\u00e9rateur ne doit pas \u00eatre nul +NULL_OBJECT_TRANSFORMATION = Exception de conversion dans une transformation, l''objet est nul +NULL_REAL_FORMAT = format r\u00e9el nul +NULL_WHOLE_FORMAT = le format complet ne doit pas \u00eatre nul +NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE = le nombre de succ\u00e8s doit \u00eatre inf\u00e9rieur +NUMERATOR_OVERFLOW_AFTER_MULTIPLY = d\u00e9passement de capacit\u00e9 pour le num\u00e9rateur apr\u00e8s multiplication : {0} +OBSERVED_COUNTS_ALL_ZERO = aucune occurrence dans le tableau des observations {0} +OBSERVED_COUNTS_BOTTH_ZERO_FOR_ENTRY = les occurrences observ\u00e9es sont toutes deux nulles pour l''entr\u00e9e {0} +OUT_OF_BOUNDS_QUANTILE_VALUE = valeur de quantile {0} hors bornes, doit \u00eatre dans l''intervalle ]0, 100] +OUT_OF_BOUND_SIGNIFICANCE_LEVEL = niveau de signification {0} hors domaine, doit \u00eatre entre {1} et {2} +OUT_OF_ORDER_ABSCISSA_ARRAY = les abscisses doivent \u00eatre en ordre strictement croissant, mais l''\u00e9l\u00e9ment {0} vaut {1} alors que l''\u00e9l\u00e9ment {2} vaut {3} +OUT_OF_RANGE_SIMPLE = {0} hors du domaine [{1}, {2}] +OVERFLOW_IN_FRACTION = d\u00e9passement de capacit\u00e9 pour la fraction {0}/{1}, son signe ne peut \u00eatre chang\u00e9 +PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD = acc\u00e8s impossible \u00e0 la m\u00e9thode {0} +PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD = l''implantation de pourcentage {0} ne dispose pas de la m\u00e9thode {1} +PERMUTATION_EXCEEDS_N = la permutation k ({0}) d\u00e9passe n ({1}) +POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS = le nombre d''interpolants polyn\u00f4miaux doit correspondre au nombre de segments ({0} != {1} - 1) +POSITION_SIZE_MISMATCH_INPUT_ARRAY = la position {0} et la taille {1} sont incompatibles avec la taille du tableau d''entr\u00e9e {2} +POWER_NEGATIVE_PARAMETERS = impossible d''\u00e9lever une valeur enti\u00e8re +PROPAGATION_DIRECTION_MISMATCH = directions de propagation incoh\u00e9rentes +ROOTS_OF_UNITY_NOT_COMPUTED_YET = les racines de l''unit\u00e9 n''ont pas encore \u00e9t\u00e9 calcul\u00e9es +ROTATION_MATRIX_DIMENSIONS = une matrice {0}x{1} ne peut pas \u00eatre une matrice de rotation +SAMPLE_SIZE_EXCEEDS_COLLECTION_SIZE = la taille de l''\u00e9chantillon ({0}) d\u00e9passe la taille de la collection ({1}) +SAMPLE_SIZE_LARGER_THAN_POPULATION_SIZE = la taille de l''\u00e9chantillon doit \u00eatre inf\u00e9rieure +SIMPLEX_NEED_ONE_POINT = le simplex doit contenir au moins un point +SIMPLE_MESSAGE = {0} +SINGULAR_MATRIX = matrice singuli\u00e8re +SUBARRAY_ENDS_AFTER_ARRAY_END = le sous-tableau se termine apr\u00e8s la fin du tableau +TOO_LARGE_CUTOFF_SINGULAR_VALUE = la valeur singuli\u00e8re de coupure vaut {0}, elle ne devrait pas d\u00e9passer {1} +TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY = impossible d''enlever {0} \u00e9l\u00e9ments d''un tableau en contenant {1} +TOO_SMALL_BANDWIDTH = la largeur de bande doit \u00eatre assez grande pour supporter au moins 2 points. Il y a {0} donn\u00e9es et la largeur de bande doit \u00eatre au moins de {1}, or elle est seulement de {2} +TOO_SMALL_COST_RELATIVE_TOLERANCE = trop petite tol\u00e9rance relative sur le co\u00fbt ({0}), aucune r\u00e9duction de la somme des carr\u00e9s n''est possible +TOO_SMALL_INTEGRATION_INTERVAL = intervalle d''int\u00e9gration trop petit : {0} +TOO_SMALL_ORTHOGONALITY_TOLERANCE = trop petite tol\u00e9rance sur l''orthogonalit\u00e9 ({0}), la solution est orthogonale \u00e0 la jacobienne +TOO_SMALL_PARAMETERS_RELATIVE_TOLERANCE = trop petite tol\u00e9rance relative sur les param\u00e8tres ({0}), aucune am\u00e9lioration de la solution approximative n''est possible +TWO_OR_MORE_CATEGORIES_REQUIRED = deux cat\u00e9gories ou plus sont n\u00e9cessaires, il y en a {0} +TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED = deux valeurs ou plus sont n\u00e9cessaires pour chaque cat\u00e9gorie, une cat\u00e9gorie en a {0} +UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH = impossible d''encadrer l''optimum lors de la recherche lin\u00e9aire +UNABLE_TO_COMPUTE_COVARIANCE_SINGULAR_PROBLEM = impossible de calculer les covariances : probl\u00e8me singulier +UNABLE_TO_FIRST_GUESS_HARMONIC_COEFFICIENTS = impossible de faire une premi\u00e8re estimation des coefficients harmoniques +UNABLE_TO_ORTHOGONOLIZE_MATRIX = impossible de rendre la matrice orthogonale en {0} it\u00e9rations +UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JACOBIAN = impossible de calculer la factorisation Q.R de la matrice jacobienne {0}x{1} +UNABLE_TO_SOLVE_SINGULAR_PROBLEM = r\u00e9solution impossible : probl\u00e8me singulier +UNBOUNDED_SOLUTION = solution non born\u00e9e +UNKNOWN_MODE = mode {0} inconnu, modes connus : {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) et {11} ({12}) +UNSUPPORTED_EXPANSION_MODE = mode d''extension {0} no support\u00e9, les modes support\u00e9s sont {1} ({2}) et {3} ({4}) +URL_CONTAINS_NO_DATA = l''adresse {0} ne contient aucune donn\u00e9e +VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC = {0} valeurs ont \u00e9t\u00e9 ajout\u00e9es +VECTOR_LENGTH_MISMATCH = taille de vecteur invalide : {0} au lieu de {1} attendue +VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT = un vecteur doit comporter au moins un \u00e9l\u00e9ment +WRONG_BLOCK_LENGTH = forme de tableau erron\u00e9e (bloc de longueur {0} au lieu des {1} attendus +WRONG_NUMBER_OF_POINTS = {0} sont n\u00e9cessaires, seuls {1} ont \u00e9t\u00e9 fournis +ZERO_DENOMINATOR = le d\u00e9nominateur doit \u00eatre diff\u00e9rent de 0 +ZERO_DENOMINATOR_IN_FRACTION = d\u00e9nominateur null dans le nombre rationnel {0}/{1} +ZERO_FRACTION_TO_DIVIDE_BY = division par un nombre rationnel nul : {0}/{1} +ZERO_NORM = norme nulle +ZERO_NORM_FOR_ROTATION_AXIS = norme nulle pour un axe de rotation +ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR = norme nulle pour un axe de d\u00e9finition de rotation diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index f9014d9d1..913301fbd 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -52,6 +52,9 @@ The type attribute can be add,update,fix,remove. If the output is not quite correct, check for invisible trailing spaces! --> + + Improved localization of error messages. + Allow multiple optimizations with a default simplex. diff --git a/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java b/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java index fdc74356e..55d071ac3 100644 --- a/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java +++ b/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java @@ -21,6 +21,8 @@ import junit.framework.TestCase; import java.util.Locale; +import org.apache.commons.math.util.LocalizedFormats; + /** * @version $Revision$ $Date$ */ @@ -35,11 +37,11 @@ public class ConvergenceExceptionTest extends TestCase { } public void testConstructorPatternArguments(){ - String pattern = "a {0}x{1} matrix cannot be a rotation matrix"; + LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS; Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) }; ConvergenceException ex = new ConvergenceException(pattern, arguments); assertNull(ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -56,13 +58,13 @@ public class ConvergenceExceptionTest extends TestCase { } public void testConstructorPatternArgumentsCause(){ - String pattern = "a {0}x{1} matrix cannot be a rotation matrix"; + LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS; Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) }; String inMsg = "inner message"; Exception cause = new Exception(inMsg); ConvergenceException ex = new ConvergenceException(cause, pattern, arguments); assertEquals(cause, ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); diff --git a/src/test/java/org/apache/commons/math/FunctionEvaluationExceptionTest.java b/src/test/java/org/apache/commons/math/FunctionEvaluationExceptionTest.java index 87f845bd1..de52150f9 100644 --- a/src/test/java/org/apache/commons/math/FunctionEvaluationExceptionTest.java +++ b/src/test/java/org/apache/commons/math/FunctionEvaluationExceptionTest.java @@ -19,6 +19,8 @@ package org.apache.commons.math; import java.util.Locale; +import org.apache.commons.math.util.LocalizedFormats; + import junit.framework.TestCase; /** @@ -46,11 +48,11 @@ public class FunctionEvaluationExceptionTest extends TestCase { } public void testConstructorPatternArguments(){ - String pattern = "evaluation failed for argument = {0}"; + LocalizedFormats pattern = LocalizedFormats.EVALUATION_FAILED; Object[] arguments = { Double.valueOf(0.0) }; FunctionEvaluationException ex = new FunctionEvaluationException(0.0, pattern, arguments); assertNull(ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -60,12 +62,12 @@ public class FunctionEvaluationExceptionTest extends TestCase { } public void testConstructorArrayPatternArguments(){ - String pattern = "evaluation failed for argument = {0}"; + LocalizedFormats pattern = LocalizedFormats.EVALUATION_FAILED; Object[] arguments = { Double.valueOf(0.0) }; FunctionEvaluationException ex = new FunctionEvaluationException(new double[] { 0, 1, 2 }, pattern, arguments); assertNull(ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -78,13 +80,13 @@ public class FunctionEvaluationExceptionTest extends TestCase { } public void testConstructorPatternArgumentsCause(){ - String pattern = "evaluation failed for argument = {0}"; + LocalizedFormats pattern = LocalizedFormats.EVALUATION_FAILED; Object[] arguments = { Double.valueOf(0.0) }; String inMsg = "inner message"; Exception cause = new Exception(inMsg); FunctionEvaluationException ex = new FunctionEvaluationException(cause, 0.0, pattern, arguments); assertEquals(cause, ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -94,14 +96,14 @@ public class FunctionEvaluationExceptionTest extends TestCase { } public void testConstructorArrayPatternArgumentsCause(){ - String pattern = "evaluation failed for argument = {0}"; + LocalizedFormats pattern = LocalizedFormats.EVALUATION_FAILED; Object[] arguments = { Double.valueOf(0.0) }; String inMsg = "inner message"; Exception cause = new Exception(inMsg); FunctionEvaluationException ex = new FunctionEvaluationException(cause, new double[] { 0, 1, 2 }, pattern, arguments); assertEquals(cause, ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); diff --git a/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java b/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java index a96ed097c..e831126d3 100644 --- a/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java +++ b/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java @@ -21,6 +21,8 @@ import junit.framework.TestCase; import java.util.Locale; +import org.apache.commons.math.util.LocalizedFormats; + /** * @version $Revision$ $Date$ */ @@ -34,11 +36,11 @@ public class MathConfigurationExceptionTest extends TestCase { } public void testConstructorPatternArguments(){ - String pattern = "a {0}x{1} matrix cannot be a rotation matrix"; + LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS; Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) }; MathConfigurationException ex = new MathConfigurationException(pattern, arguments); assertNull(ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -55,13 +57,13 @@ public class MathConfigurationExceptionTest extends TestCase { } public void testConstructorPatternArgumentsCause(){ - String pattern = "a {0}x{1} matrix cannot be a rotation matrix"; + LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS; Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) }; String inMsg = "inner message"; Exception cause = new Exception(inMsg); MathConfigurationException ex = new MathConfigurationException(cause, pattern, arguments); assertEquals(cause, ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); diff --git a/src/test/java/org/apache/commons/math/MathExceptionTest.java b/src/test/java/org/apache/commons/math/MathExceptionTest.java index 693b7f181..7698b9920 100644 --- a/src/test/java/org/apache/commons/math/MathExceptionTest.java +++ b/src/test/java/org/apache/commons/math/MathExceptionTest.java @@ -24,6 +24,10 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.util.Locale; +import org.apache.commons.math.util.DummyLocalizable; +import org.apache.commons.math.util.Localizable; +import org.apache.commons.math.util.LocalizedFormats; + /** * @version $Revision$ $Date$ */ @@ -37,11 +41,11 @@ public class MathExceptionTest extends TestCase { } public void testConstructorPatternArguments(){ - String pattern = "a {0}x{1} matrix cannot be a rotation matrix"; + LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS; Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) }; MathException ex = new MathException(pattern, arguments); assertNull(ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -58,13 +62,13 @@ public class MathExceptionTest extends TestCase { } public void testConstructorPatternArgumentsCause(){ - String pattern = "a {0}x{1} matrix cannot be a rotation matrix"; + LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS; Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) }; String inMsg = "inner message"; Exception cause = new Exception(inMsg); MathException ex = new MathException(cause, pattern, arguments); assertEquals(cause, ex.getCause()); - assertEquals(pattern, ex.getPattern()); + assertEquals(pattern, ex.getLocalizablePattern()); assertEquals(arguments.length, ex.getArguments().length); for (int i = 0; i < arguments.length; ++i) { assertEquals(arguments[i], ex.getArguments()[i]); @@ -77,8 +81,8 @@ public class MathExceptionTest extends TestCase { * Tests the printStackTrace() operation. */ public void testPrintStackTrace() { - String outMsg = "outer message"; - String inMsg = "inner message"; + Localizable outMsg = new DummyLocalizable("outer message"); + Localizable inMsg = new DummyLocalizable("inner message"); MathException cause = new MathConfigurationException(inMsg); MathException ex = new MathException(cause, outMsg); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -102,8 +106,8 @@ public class MathExceptionTest extends TestCase { * Test serialization */ public void testSerialization() { - String outMsg = "outer message"; - String inMsg = "inner message"; + Localizable outMsg = new DummyLocalizable("outer message"); + Localizable inMsg = new DummyLocalizable("inner message"); MathException cause = new MathConfigurationException(inMsg); MathException ex = new MathException(cause, outMsg); MathException image = (MathException) TestUtils.serializeAndRecover(ex); @@ -131,7 +135,7 @@ public class MathExceptionTest extends TestCase { if (jdkSupportsNesting) { assertEquals(stack, stack2); } else { - assertTrue(stack2.indexOf(inMsg) != -1); + assertTrue(stack2.indexOf(inMsg.getSourceString()) != -1); assertTrue(stack2.indexOf("MathConfigurationException") != -1); } } diff --git a/src/test/java/org/apache/commons/math/MaxIterationsExceededExceptionTest.java b/src/test/java/org/apache/commons/math/MaxIterationsExceededExceptionTest.java index 6c04ae9a6..c12d69f50 100644 --- a/src/test/java/org/apache/commons/math/MaxIterationsExceededExceptionTest.java +++ b/src/test/java/org/apache/commons/math/MaxIterationsExceededExceptionTest.java @@ -19,6 +19,8 @@ package org.apache.commons.math; import java.util.Locale; +import org.apache.commons.math.util.LocalizedFormats; + import junit.framework.TestCase; /** @@ -38,7 +40,7 @@ public class MaxIterationsExceededExceptionTest extends TestCase { public void testComplexConstructor(){ MaxIterationsExceededException ex = new MaxIterationsExceededException(1000000, - "Continued fraction convergents failed to converge for value {0}", + LocalizedFormats.NON_CONVERGENT_CONTINUED_FRACTION, 1234567); assertNull(ex.getCause()); assertNotNull(ex.getMessage()); diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java index 56663c9a8..d57b89f47 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java @@ -33,6 +33,7 @@ import org.apache.commons.math.ode.events.EventException; import org.apache.commons.math.ode.events.EventHandler; import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepInterpolator; +import org.apache.commons.math.util.LocalizedFormats; public class HighamHall54IntegratorTest extends TestCase { @@ -51,7 +52,7 @@ public class HighamHall54IntegratorTest public void computeDerivatives(double t, double[] y, double[] dot) throws DerivativeException { if (t < -0.5) { - throw new DerivativeException("{0}", "oops"); + throw new DerivativeException(LocalizedFormats.SIMPLE_MESSAGE, "oops"); } else { throw new DerivativeException(new RuntimeException("oops")); } @@ -217,7 +218,7 @@ public class HighamHall54IntegratorTest double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2; double offset = t - middle; if (offset > 0) { - throw new EventException("Evaluation failed for argument = {0}", t); + throw new EventException(LocalizedFormats.EVALUATION_FAILED, t); } return offset; } diff --git a/src/test/java/org/apache/commons/math/util/TestBean.java b/src/test/java/org/apache/commons/math/util/TestBean.java index 2b7fa6c31..d8bb0be71 100644 --- a/src/test/java/org/apache/commons/math/util/TestBean.java +++ b/src/test/java/org/apache/commons/math/util/TestBean.java @@ -59,7 +59,7 @@ public class TestBean { * */ public Double getZ() { - throw new MathRuntimeException("?"); + throw new MathRuntimeException(LocalizedFormats.SIMPLE_MESSAGE, "?"); } /**