diff --git a/src/java/org/apache/commons/math/MathRuntimeException.java b/src/java/org/apache/commons/math/MathRuntimeException.java
index 58877eac8..9c32573f1 100644
--- a/src/java/org/apache/commons/math/MathRuntimeException.java
+++ b/src/java/org/apache/commons/math/MathRuntimeException.java
@@ -293,6 +293,19 @@ public class MathRuntimeException extends RuntimeException {
};
}
+ /**
+ * Constructs a new IllegalArgumentException
with specified nested
+ * Throwable
root cause.
+ * @param rootCause the exception or error that caused this exception
+ * to be thrown.
+ * @return built exception
+ */
+ public static IllegalArgumentException createIllegalArgumentException(final Throwable rootCause) {
+ IllegalArgumentException iae = new IllegalArgumentException(rootCause.getLocalizedMessage());
+ iae.initCause(rootCause);
+ return iae;
+ }
+
/**
* Constructs a new IllegalStateException
with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
diff --git a/src/java/org/apache/commons/math/MessagesResources_fr.java b/src/java/org/apache/commons/math/MessagesResources_fr.java
index c738ea1ea..63f23ad11 100644
--- a/src/java/org/apache/commons/math/MessagesResources_fr.java
+++ b/src/java/org/apache/commons/math/MessagesResources_fr.java
@@ -46,11 +46,23 @@ public class MessagesResources_fr
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" },
{ "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})" },
-
+ "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})" },
+
// org.apache.commons.math.FunctionEvaluationException
{ "evaluation failed for argument = {0}",
"erreur d''\u00e9valuation pour l''argument {0}" },
@@ -77,6 +89,8 @@ public class MessagesResources_fr
// 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
{ "dimension mismatch {0} != {1}",
"dimensions incompatibles {0} != {1}" },
@@ -265,20 +279,58 @@ public class MessagesResources_fr
// 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
+ { "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" },
+ "la d\u00e9composition en valeurs/vecteurs propres de matrices " +
+ "non sym\u00e9triques n''est pas encore disponible" },
// org.apache.commons.math.linear.decomposition.NonSquareMatrixException
{ "a {0}x{1} matrix was provided instead of a square matrix",
@@ -332,6 +384,20 @@ public class MessagesResources_fr
"une matrice doit comporter au moins une colonne" },
{ "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",
@@ -343,43 +409,37 @@ public class MessagesResources_fr
{ "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.linear.BigMatrixImpl
- // org.apache.commons.math.linear.RealMatrixImpl
- { "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}]" },
- { "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
- "pas d''entr\u00e9e aux indices ({0}, {1}) dans une matrice {2}x{3}" },
- { "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" },
-
- // 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.complex.Complex
- { "cannot compute nth root for null or negative n: {0}",
+ // 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}",
@@ -480,10 +540,14 @@ public class MessagesResources_fr
"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.RealVectorImpl
@@ -502,20 +566,24 @@ public class MessagesResources_fr
{ "first {0} columns are not initialized yet",
"les {0} premi\u00e8res colonnes ne sont pas encore initialis\u00e9es" },
- // org.apache.commons.math.random.EmpiricalDistributionImpl
- { "distribution not loaded",
- "aucune distribution n''a \u00e9t\u00e9 charg\u00e9e" },
+ // 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.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.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. " +
+ "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." },
@@ -524,19 +592,127 @@ public class MessagesResources_fr
{ "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" },
+ "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 setQuantile",
+ "l''implantation de pourcentage {0} ne dispose pas de la m\u00e9thode setQuantile" },
+ { "cannot access setQuantile method in percentile implementation {0}",
+ "acc\u00e8s impossible \u00e0 la m\u00e9thode setQuantile" +
+ " dans l''implantation de pourcentage {0}" },
+ { "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.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" },
+ "{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" },
+ "les statistiques bas\u00e9es sur des moments externes " +
+ "ne peuvent pas \u00eatre incr\u00e9ment\u00e9es" },
{ "statistics constructed from external moments cannot be cleared",
- "les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
+ "les statistiques bas\u00e9es sur des moments externes " +
+ "ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
+
+ // org.apache.commons.math.stat.Regression
+ { "out of bounds significance level {0}, must be in (0, 1)",
+ "niveau de signification {0} hors domaine, doit \u00eatre dans l''intervalle ]0, 1[" },
+
+ // 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.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)",
@@ -550,7 +726,8 @@ public class MessagesResources_fr
// 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" },
+ "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}])",
diff --git a/src/java/org/apache/commons/math/complex/ComplexFormat.java b/src/java/org/apache/commons/math/complex/ComplexFormat.java
index d46f914df..9d30ec6a6 100644
--- a/src/java/org/apache/commons/math/complex/ComplexFormat.java
+++ b/src/java/org/apache/commons/math/complex/ComplexFormat.java
@@ -192,7 +192,9 @@ public class ComplexFormat extends CompositeFormat {
ret = format( new Complex(((Number)obj).doubleValue(), 0.0),
toAppendTo, pos);
} else {
- throw new IllegalArgumentException("Cannot format given Object as a Complex");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "cannot format a {0} instance as a complex number",
+ obj.getClass().getName());
}
return ret;
@@ -347,8 +349,8 @@ public class ComplexFormat extends CompositeFormat {
*/
public void setImaginaryCharacter(String imaginaryCharacter) {
if (imaginaryCharacter == null || imaginaryCharacter.length() == 0) {
- throw new IllegalArgumentException(
- "imaginaryCharacter must be a non-empty string.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "empty string for imaginary character");
}
this.imaginaryCharacter = imaginaryCharacter;
}
@@ -361,8 +363,8 @@ public class ComplexFormat extends CompositeFormat {
*/
public void setImaginaryFormat(NumberFormat imaginaryFormat) {
if (imaginaryFormat == null) {
- throw new IllegalArgumentException(
- "imaginaryFormat can not be null.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "null imaginary format");
}
this.imaginaryFormat = imaginaryFormat;
}
@@ -375,8 +377,8 @@ public class ComplexFormat extends CompositeFormat {
*/
public void setRealFormat(NumberFormat realFormat) {
if (realFormat == null) {
- throw new IllegalArgumentException(
- "realFormat can not be null.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "null real format");
}
this.realFormat = realFormat;
}
diff --git a/src/java/org/apache/commons/math/complex/ComplexUtils.java b/src/java/org/apache/commons/math/complex/ComplexUtils.java
index 80faa9e05..cc28a2662 100644
--- a/src/java/org/apache/commons/math/complex/ComplexUtils.java
+++ b/src/java/org/apache/commons/math/complex/ComplexUtils.java
@@ -17,6 +17,8 @@
package org.apache.commons.math.complex;
+import org.apache.commons.math.MathRuntimeException;
+
/**
* Static implementations of common
* {@link org.apache.commons.math.complex.Complex} utilities functions.
@@ -59,8 +61,8 @@ public class ComplexUtils {
*/
public static Complex polar2Complex(double r, double theta) {
if (r < 0) {
- throw new IllegalArgumentException
- ("Complex modulus must not be negative");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "negative complex module {0}", r);
}
return new Complex(r * Math.cos(theta), r * Math.sin(theta));
}
diff --git a/src/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java b/src/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
index 4d32d1fc0..484355d14 100644
--- a/src/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
+++ b/src/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
@@ -59,7 +60,8 @@ public abstract class AbstractContinuousDistribution
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException("p must be between 0.0 and 1.0, inclusive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
}
// by default, do simple root finding using bracketing and default solver.
diff --git a/src/java/org/apache/commons/math/distribution/AbstractDistribution.java b/src/java/org/apache/commons/math/distribution/AbstractDistribution.java
index eece53cf5..a695eb338 100644
--- a/src/java/org/apache/commons/math/distribution/AbstractDistribution.java
+++ b/src/java/org/apache/commons/math/distribution/AbstractDistribution.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
/**
* Base class for probability distributions.
@@ -58,8 +59,9 @@ public abstract class AbstractDistribution
public double cumulativeProbability(double x0, double x1)
throws MathException {
if (x0 > x1) {
- throw new IllegalArgumentException
- ("lower endpoint must be less than or equal to upper endpoint");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "lower endpoint ({0}) must be less than or equal to upper endpoint ({1})",
+ x0, x1);
}
return cumulativeProbability(x1) - cumulativeProbability(x0);
}
diff --git a/src/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java b/src/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
index b6fe5f1e2..b6e0d9526 100644
--- a/src/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
+++ b/src/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
/**
@@ -77,8 +78,9 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
public double cumulativeProbability(double x0, double x1)
throws MathException {
if (x0 > x1) {
- throw new IllegalArgumentException
- ("lower endpoint must be less than or equal to upper endpoint");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "lower endpoint ({0}) must be less than or equal to upper endpoint ({1})",
+ x0, x1);
}
if (Math.floor(x0) < x0) {
return cumulativeProbability(((int) Math.floor(x0)) + 1,
@@ -134,8 +136,9 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
*/
public double cumulativeProbability(int x0, int x1) throws MathException {
if (x0 > x1) {
- throw new IllegalArgumentException
- ("lower endpoint must be less than or equal to upper endpoint");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "lower endpoint ({0}) must be less than or equal to upper endpoint ({1})",
+ x0, x1);
}
return cumulativeProbability(x1) - cumulativeProbability(x0 - 1);
}
@@ -153,8 +156,8 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
*/
public int inverseCumulativeProbability(final double p) throws MathException{
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException(
- "p must be between 0 and 1.0 (inclusive)");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
}
// by default, do simple bisection.
diff --git a/src/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java b/src/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
index 685151eae..b9cb396e6 100644
--- a/src/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
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.MathUtils;
@@ -76,7 +77,8 @@ public class BinomialDistributionImpl
*/
public void setNumberOfTrials(int trials) {
if (trials < 0) {
- throw new IllegalArgumentException("number of trials must be non-negative.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "number of trials must be non-negative ({0})", trials);
}
numberOfTrials = trials;
}
@@ -89,7 +91,8 @@ public class BinomialDistributionImpl
*/
public void setProbabilityOfSuccess(double p) {
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException("probability of success must be between 0.0 and 1.0, inclusive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
}
probabilityOfSuccess = p;
}
diff --git a/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java b/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
index 23847a23b..0ce9acfad 100644
--- a/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
@@ -19,6 +19,8 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
+import org.apache.commons.math.MathRuntimeException;
+
/**
* Default implementation of
* {@link org.apache.commons.math.distribution.CauchyDistribution}.
@@ -98,8 +100,8 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
public double inverseCumulativeProbability(double p) {
double ret;
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException
- ("probability argument must be between 0 and 1 (inclusive)");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
} else if (p == 0) {
ret = Double.NEGATIVE_INFINITY;
} else if (p == 1) {
@@ -125,8 +127,8 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
*/
public void setScale(double s) {
if (s <= 0.0) {
- throw new IllegalArgumentException(
- "Scale must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "scale must be positive ({0})", s);
}
scale = s;
}
diff --git a/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java b/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
index 79529f918..0f29b7a5d 100644
--- a/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
/**
* The default implementation of {@link ExponentialDistribution}.
@@ -50,7 +51,8 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
*/
public void setMean(double mean) {
if (mean <= 0.0) {
- throw new IllegalArgumentException("mean must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "mean must be positive ({0})", mean);
}
this.mean = mean;
}
@@ -118,8 +120,8 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
double ret;
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException
- ("probability argument must be between 0 and 1 (inclusive)");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
} else if (p == 1.0) {
ret = Double.POSITIVE_INFINITY;
} else {
diff --git a/src/java/org/apache/commons/math/distribution/FDistributionImpl.java b/src/java/org/apache/commons/math/distribution/FDistributionImpl.java
index 02fe62bbd..10da08846 100644
--- a/src/java/org/apache/commons/math/distribution/FDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/FDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.special.Beta;
/**
@@ -162,8 +163,9 @@ public class FDistributionImpl
*/
public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
- throw new IllegalArgumentException(
- "degrees of freedom must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "degrees of freedom must be positive ({0})",
+ degreesOfFreedom);
}
this.numeratorDegreesOfFreedom = degreesOfFreedom;
}
@@ -184,8 +186,9 @@ public class FDistributionImpl
*/
public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
- throw new IllegalArgumentException(
- "degrees of freedom must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "degrees of freedom must be positive ({0})",
+ degreesOfFreedom);
}
this.denominatorDegreesOfFreedom = degreesOfFreedom;
}
diff --git a/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java b/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
index 8bd4e2c76..e1ab2e103 100644
--- a/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.special.Gamma;
/**
@@ -110,7 +111,9 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
*/
public void setAlpha(double alpha) {
if (alpha <= 0.0) {
- throw new IllegalArgumentException("alpha must be positive");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "alpha must be positive ({0})",
+ alpha);
}
this.alpha = alpha;
}
@@ -130,7 +133,9 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
*/
public void setBeta(double beta) {
if (beta <= 0.0) {
- throw new IllegalArgumentException("beta must be positive");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "beta must be positive ({0})",
+ beta);
}
this.beta = beta;
}
diff --git a/src/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java b/src/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
index 6e3d98401..c6f5e91c3 100644
--- a/src/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
+import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.util.MathUtils;
/**
@@ -53,13 +54,14 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
int numberOfSuccesses, int sampleSize) {
super();
if (numberOfSuccesses > populationSize) {
- throw new IllegalArgumentException(
- "number of successes must be less than or equal to " +
- "population size");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "number of successes ({0}) must be less than or equal to population size ({1})",
+ numberOfSuccesses, populationSize);
}
if (sampleSize > populationSize) {
- throw new IllegalArgumentException(
- "sample size must be less than or equal to population size");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "sample size ({0}) must be less than or equal to population size ({1})",
+ sampleSize, populationSize);
}
setPopulationSize(populationSize);
setSampleSize(sampleSize);
@@ -226,8 +228,9 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
*/
public void setNumberOfSuccesses(int num) {
if(num < 0){
- throw new IllegalArgumentException(
- "number of successes must be non-negative.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "number of successes must be non-negative ({0})",
+ num);
}
numberOfSuccesses = num;
}
@@ -239,8 +242,9 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
*/
public void setPopulationSize(int size) {
if(size <= 0){
- throw new IllegalArgumentException(
- "population size must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "population size must be positive ({0})",
+ size);
}
populationSize = size;
}
@@ -252,8 +256,9 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
*/
public void setSampleSize(int size) {
if (size < 0) {
- throw new IllegalArgumentException(
- "sample size must be non-negative.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "sample size must be positive ({0})",
+ size);
}
sampleSize = size;
}
diff --git a/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java b/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
index e386a195f..19ad7662f 100644
--- a/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
@@ -20,6 +20,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
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;
@@ -94,8 +95,9 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
*/
public void setStandardDeviation(double sd) {
if (sd <= 0.0) {
- throw new IllegalArgumentException(
- "Standard deviation must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "standard deviation must be positive ({0})",
+ sd);
}
standardDeviation = sd;
}
diff --git a/src/java/org/apache/commons/math/distribution/PascalDistributionImpl.java b/src/java/org/apache/commons/math/distribution/PascalDistributionImpl.java
index 9cb63831f..5a632b0db 100644
--- a/src/java/org/apache/commons/math/distribution/PascalDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/PascalDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
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.MathUtils;
@@ -75,8 +76,9 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
*/
public void setNumberOfSuccesses(int successes) {
if (successes < 0) {
- throw new IllegalArgumentException(
- "number of successes must be non-negative.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "number of successes must be non-negative ({0})",
+ successes);
}
numberOfSuccesses = successes;
}
@@ -89,8 +91,8 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
*/
public void setProbabilityOfSuccess(double p) {
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException(
- "probability of success must be between 0.0 and 1.0, inclusive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
}
probabilityOfSuccess = p;
}
diff --git a/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java b/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
index 2cb5e4828..a9e55b95e 100644
--- a/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
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.MathUtils;
@@ -88,8 +89,9 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
*/
public void setMean(double p) {
if (p <= 0) {
- throw new IllegalArgumentException(
- "The Poisson mean must be positive");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "the Poisson mean must be positive ({0})",
+ p);
}
this.mean = p;
normal.setMean(p);
diff --git a/src/java/org/apache/commons/math/distribution/TDistributionImpl.java b/src/java/org/apache/commons/math/distribution/TDistributionImpl.java
index dfe1698b5..4af2261a5 100644
--- a/src/java/org/apache/commons/math/distribution/TDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/TDistributionImpl.java
@@ -19,6 +19,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.special.Beta;
/**
@@ -52,7 +53,9 @@ public class TDistributionImpl
*/
public void setDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
- throw new IllegalArgumentException("degrees of freedom must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "degrees of freedom must be positive ({0})",
+ degreesOfFreedom);
}
this.degreesOfFreedom = degreesOfFreedom;
}
diff --git a/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java b/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
index 1aa1383a5..37a8d9daf 100644
--- a/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
+++ b/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
@@ -19,6 +19,8 @@ package org.apache.commons.math.distribution;
import java.io.Serializable;
+import org.apache.commons.math.MathRuntimeException;
+
/**
* Default implementation of
* {@link org.apache.commons.math.distribution.WeibullDistribution}.
@@ -97,8 +99,8 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
public double inverseCumulativeProbability(double p) {
double ret;
if (p < 0.0 || p > 1.0) {
- throw new IllegalArgumentException
- ("probability argument must be between 0 and 1 (inclusive)");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "{0} out of [{1}, {2}] range", p, 0.0, 1.0);
} else if (p == 0) {
ret = 0.0;
} else if (p == 1) {
@@ -115,8 +117,9 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
*/
public void setShape(double alpha) {
if (alpha <= 0.0) {
- throw new IllegalArgumentException(
- "Shape must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "shape must be positive ({0})",
+ alpha);
}
this.alpha = alpha;
}
@@ -127,8 +130,9 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
*/
public void setScale(double beta) {
if (beta <= 0.0) {
- throw new IllegalArgumentException(
- "Scale must be positive.");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "scale must be positive ({0})",
+ beta);
}
this.beta = beta;
}
diff --git a/src/java/org/apache/commons/math/fraction/Fraction.java b/src/java/org/apache/commons/math/fraction/Fraction.java
index 1177ec30b..463b3e889 100644
--- a/src/java/org/apache/commons/math/fraction/Fraction.java
+++ b/src/java/org/apache/commons/math/fraction/Fraction.java
@@ -476,7 +476,7 @@ public class Fraction extends Number implements FieldElement
* The Nordsieck form for a dimension n state history at step k is composed of the @@ -81,6 +83,7 @@ import org.apache.commons.math.linear.decomposition.FieldLUDecompositionImpl; * @see org.apache.commons.math.ode.MultistepIntegrator * @see org.apache.commons.math.ode.nonstiff.AdamsBashforthIntegrator * @see org.apache.commons.math.ode.nonstiff.AdamsMoultonIntegrator + * @see org.apache.commons.math.ode.stiff.BDFIntegrator * @version $Revision$ $Date$ * @since 2.0 */ diff --git a/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java b/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java index aee3b37c2..6d4a477a8 100644 --- a/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java +++ b/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java @@ -16,6 +16,8 @@ */ package org.apache.commons.math.random; +import org.apache.commons.math.MathRuntimeException; + /** * Abstract class implementing the {@link RandomGenerator} interface. * Default implementations for all methods other than {@link #nextDouble()} and @@ -138,7 +140,8 @@ public abstract class AbstractRandomGenerator implements RandomGenerator { */ public int nextInt(int n) { if (n <= 0 ) { - throw new IllegalArgumentException("upper bound must be positive"); + throw MathRuntimeException.createIllegalArgumentException( + "upper bound must be positive ({0})", n); } int result = (int) (nextDouble() * n); return result < n ? result : n - 1; diff --git a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index 959ea2fe7..893cb0954 100644 --- a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -228,8 +228,11 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib double[] inputArray = (double[]) in; return new ArrayDataAdapter(inputArray); } else { - throw new IllegalArgumentException( - "Input data comes from the" + " unsupported source"); + throw MathRuntimeException.createIllegalArgumentException( + "input data comes from unsupported datasource: {0}, " + + "supported sources: {1}, {2}", + in.getClass().getName(), + BufferedReader.class.getName(), double[].class.getName()); } } } diff --git a/src/java/org/apache/commons/math/random/RandomDataImpl.java b/src/java/org/apache/commons/math/random/RandomDataImpl.java index e785f47ab..cded24f36 100644 --- a/src/java/org/apache/commons/math/random/RandomDataImpl.java +++ b/src/java/org/apache/commons/math/random/RandomDataImpl.java @@ -24,6 +24,7 @@ import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.util.Collection; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.util.MathUtils; /** @@ -132,7 +133,8 @@ public class RandomDataImpl implements RandomData, Serializable { */ public String nextHexString(int len) { if (len <= 0) { - throw new IllegalArgumentException("length must be positive"); + throw MathRuntimeException.createIllegalArgumentException( + "length must be positive ({0})", len); } // Get a random number generator @@ -177,8 +179,9 @@ public class RandomDataImpl implements RandomData, Serializable { */ public int nextInt(int lower, int upper) { if (lower >= upper) { - throw new IllegalArgumentException( - "upper bound must be > lower bound"); + throw MathRuntimeException.createIllegalArgumentException( + "upper bound ({0}) must be greater than lower bound ({1})", + upper, lower); } RandomGenerator rand = getRan(); double r = rand.nextDouble(); @@ -197,8 +200,9 @@ public class RandomDataImpl implements RandomData, Serializable { */ public long nextLong(long lower, long upper) { if (lower >= upper) { - throw new IllegalArgumentException( - "upper bound must be > lower bound"); + throw MathRuntimeException.createIllegalArgumentException( + "upper bound ({0}) must be greater than lower bound ({1})", + upper, lower); } RandomGenerator rand = getRan(); double r = rand.nextDouble(); @@ -227,7 +231,8 @@ public class RandomDataImpl implements RandomData, Serializable { */ public String nextSecureHexString(int len) { if (len <= 0) { - throw new IllegalArgumentException("length must be positive"); + throw MathRuntimeException.createIllegalArgumentException( + "length must be positive ({0})", len); } // Get SecureRandom and setup Digest provider @@ -286,8 +291,9 @@ public class RandomDataImpl implements RandomData, Serializable { */ public int nextSecureInt(int lower, int upper) { if (lower >= upper) { - throw new IllegalArgumentException( - "lower bound must be < upper bound"); + throw MathRuntimeException.createIllegalArgumentException( + "upper bound ({0}) must be greater than lower bound ({1})", + upper, lower); } SecureRandom sec = getSecRan(); return lower + (int) (sec.nextDouble() * (upper - lower + 1)); @@ -306,8 +312,9 @@ public class RandomDataImpl implements RandomData, Serializable { */ public long nextSecureLong(long lower, long upper) { if (lower >= upper) { - throw new IllegalArgumentException( - "lower bound must be < upper bound"); + throw MathRuntimeException.createIllegalArgumentException( + "upper bound ({0}) must be greater than lower bound ({1})", + upper, lower); } SecureRandom sec = getSecRan(); return lower + (long) (sec.nextDouble() * (upper - lower + 1)); @@ -344,7 +351,8 @@ public class RandomDataImpl implements RandomData, Serializable { */ public long nextPoisson(double mean) { if (mean <= 0) { - throw new IllegalArgumentException("Poisson mean must be > 0"); + throw MathRuntimeException.createIllegalArgumentException( + "the Poisson mean must be positive ({0})", mean); } RandomGenerator rand = getRan(); @@ -446,7 +454,8 @@ public class RandomDataImpl implements RandomData, Serializable { */ public double nextGaussian(double mu, double sigma) { if (sigma <= 0) { - throw new IllegalArgumentException("Gaussian std dev must be > 0"); + throw MathRuntimeException.createIllegalArgumentException( + "standard deviation must be positive ({0})", sigma); } RandomGenerator rand = getRan(); return sigma * rand.nextGaussian() + mu; @@ -468,7 +477,8 @@ public class RandomDataImpl implements RandomData, Serializable { */ public double nextExponential(double mean) { if (mean < 0.0) { - throw new IllegalArgumentException("Exponential mean must be >= 0"); + throw MathRuntimeException.createIllegalArgumentException( + "mean must be positive ({0})", mean); } RandomGenerator rand = getRan(); double unif = rand.nextDouble(); @@ -496,8 +506,9 @@ public class RandomDataImpl implements RandomData, Serializable { */ public double nextUniform(double lower, double upper) { if (lower >= upper) { - throw new IllegalArgumentException( - "lower bound must be < upper bound"); + throw MathRuntimeException.createIllegalArgumentException( + "upper bound ({0}) must be greater than lower bound ({1})", + upper, lower); } RandomGenerator rand = getRan(); @@ -655,10 +666,12 @@ public class RandomDataImpl implements RandomData, Serializable { */ public int[] nextPermutation(int n, int k) { if (k > n) { - throw new IllegalArgumentException("permutation k exceeds n"); + throw MathRuntimeException.createIllegalArgumentException( + "permutation k ({0}) exceeds n ({1})", k, n); } if (k == 0) { - throw new IllegalArgumentException("permutation k must be > 0"); + throw MathRuntimeException.createIllegalArgumentException( + "permutation k ({0}) must be positive", k); } int[] index = getNatural(n); @@ -690,11 +703,12 @@ public class RandomDataImpl implements RandomData, Serializable { public Object[] nextSample(Collection> c, int k) { int len = c.size(); if (k > len) { - throw new IllegalArgumentException( - "sample size exceeds collection size"); + throw MathRuntimeException.createIllegalArgumentException( + "sample size ({0}) exceeds collection size ({1})"); } - if (k == 0) { - throw new IllegalArgumentException("sample size must be > 0"); + if (k <= 0) { + throw MathRuntimeException.createIllegalArgumentException( + "sample size must be positive ({0})", k); } Object[] objects = c.toArray(); @@ -745,4 +759,5 @@ public class RandomDataImpl implements RandomData, Serializable { } return natural; } + } diff --git a/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java b/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java index cf0ee0e63..5f86a1262 100644 --- a/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java +++ b/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java @@ -19,6 +19,8 @@ package org.apache.commons.math.random; import java.util.Arrays; +import org.apache.commons.math.MathRuntimeException; + /** * A {@link RandomVectorGenerator} that generates vectors with uncorrelated * components. Components of generated vectors follow (independent) Gaussian @@ -46,7 +48,9 @@ public class UncorrelatedRandomVectorGenerator double[] standardDeviation, NormalizedRandomGenerator generator) { if (mean.length != standardDeviation.length) { - throw new IllegalArgumentException("dimension mismatch"); + throw MathRuntimeException.createIllegalArgumentException( + "dimension mismatch {0} != {1}", + mean.length, standardDeviation.length); } this.mean = mean.clone(); this.standardDeviation = standardDeviation.clone(); diff --git a/src/java/org/apache/commons/math/stat/Frequency.java b/src/java/org/apache/commons/math/stat/Frequency.java index 7780b7f9f..4cf1da589 100644 --- a/src/java/org/apache/commons/math/stat/Frequency.java +++ b/src/java/org/apache/commons/math/stat/Frequency.java @@ -22,6 +22,8 @@ import java.util.Iterator; import java.util.Comparator; import java.util.TreeMap; +import org.apache.commons.math.MathRuntimeException; + /** * Maintains a frequency distribution. *
@@ -110,7 +112,9 @@ public class Frequency implements Serializable { if (v instanceof Comparable>){ addValue((Comparable>) v); } else { - throw new IllegalArgumentException("Object must implement Comparable"); + throw MathRuntimeException.createIllegalArgumentException( + "class ({0}) does not implement Comparable", + v.getClass().getName()); } } @@ -138,7 +142,9 @@ public class Frequency implements Serializable { } } catch (ClassCastException ex) { //TreeMap will throw ClassCastException if v is not comparable - throw new IllegalArgumentException("Value not comparable to existing values."); + throw MathRuntimeException.createIllegalArgumentException( + "instance of class {0} not comparable to existing values", + v.getClass().getName()); } } diff --git a/src/java/org/apache/commons/math/stat/StatUtils.java b/src/java/org/apache/commons/math/stat/StatUtils.java index cf1d4b521..389013d35 100644 --- a/src/java/org/apache/commons/math/stat/StatUtils.java +++ b/src/java/org/apache/commons/math/stat/StatUtils.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.stat; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.UnivariateStatistic; import org.apache.commons.math.stat.descriptive.moment.GeometricMean; import org.apache.commons.math.stat.descriptive.moment.Mean; @@ -563,9 +564,10 @@ 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) { - throw new IllegalArgumentException - ("Input arrays must have the same (positive) length."); + if ((n != sample2.length) || (n < 1)) { + throw MathRuntimeException.createIllegalArgumentException( + "input arrays must have the same positive length ({0} and {1})", + n, sample2.length); } double result = 0; for (int i = 0; i < n; i++) { @@ -608,7 +610,9 @@ public final class StatUtils { double diff = 0d; int n = sample1.length; if (n < 2 || n != sample2.length) { - throw new IllegalArgumentException("Input array lengths must be equal and at least 2."); + throw MathRuntimeException.createIllegalArgumentException( + "input arrays must have the same length and at least two elements ({0} and {1})", + n, sample2.length); } for (int i = 0; i < n; i++) { diff = sample1[i] - sample2[i]; diff --git a/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java b/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java index bfe8e8b6f..27dcc80b4 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java +++ b/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.stat.descriptive; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.util.MathUtils; import java.io.Serializable; @@ -58,7 +59,7 @@ public abstract class AbstractStorelessUnivariateStatistic @Override public double evaluate(final double[] values) { if (values == null) { - throw new IllegalArgumentException("input value array is null"); + throw MathRuntimeException.createIllegalArgumentException("input values array is null"); } return evaluate(values, 0, values.length); } @@ -126,7 +127,7 @@ public abstract class AbstractStorelessUnivariateStatistic */ public void incrementAll(double[] values) { if (values == null) { - throw new IllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException("input values array is null"); } incrementAll(values, 0, values.length); } diff --git a/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java b/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java index 68281f69f..0bcdb1823 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java +++ b/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java @@ -18,6 +18,8 @@ package org.apache.commons.math.stat.descriptive; import java.io.Serializable; +import org.apache.commons.math.MathRuntimeException; + /** * Abstract base class for all implementations of the * {@link UnivariateStatistic} interface. @@ -80,20 +82,22 @@ public abstract class AbstractUnivariateStatistic final int length) { if (values == null) { - throw new IllegalArgumentException("input value array is null"); + throw MathRuntimeException.createIllegalArgumentException("input values array is null"); } if (begin < 0) { - throw new IllegalArgumentException("start position cannot be negative"); + throw MathRuntimeException.createIllegalArgumentException( + "start position cannot be negative ({0})", begin); } if (length < 0) { - throw new IllegalArgumentException("length cannot be negative"); + throw MathRuntimeException.createIllegalArgumentException( + "length cannot be negative ({0})", length); } if (begin + length > values.length) { - throw new IllegalArgumentException( - "begin + length > values.length"); + throw MathRuntimeException.createIllegalArgumentException( + "subarray ends after array end"); } if (length == 0) { diff --git a/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java b/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java index 4066f30b4..288b0807f 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java +++ b/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.moment.GeometricMean; import org.apache.commons.math.stat.descriptive.moment.Kurtosis; import org.apache.commons.math.stat.descriptive.moment.Mean; @@ -301,7 +302,8 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { public void setWindowSize(int windowSize) { if (windowSize < 1) { if (windowSize != INFINITE_WINDOW) { - throw new IllegalArgumentException("window size must be positive."); + throw MathRuntimeException.createIllegalArgumentException( + "window size must be positive ({0})", windowSize); } } @@ -379,14 +381,15 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent - throw new IllegalArgumentException( - "Percentile implementation does not support setQuantile"); + throw MathRuntimeException.createIllegalArgumentException( + "percentile implementation {0} does not support setQuantile", + percentileImpl.getClass().getName()); } catch (IllegalAccessException e2) { - throw new IllegalArgumentException( - "IllegalAccessException setting quantile"); + throw MathRuntimeException.createIllegalArgumentException( + "cannot access setQuantile method in percentile implementation {0}", + percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { - throw new IllegalArgumentException( - "Error setting quantile" + e3.toString()); + throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); } } return apply(percentileImpl); @@ -561,14 +564,15 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(50.0d)}); } catch (NoSuchMethodException e1) { - throw new IllegalArgumentException( - "Percentile implementation does not support setQuantile"); + throw MathRuntimeException.createIllegalArgumentException( + "percentile implementation {0} does not support setQuantile", + percentileImpl.getClass().getName()); } catch (IllegalAccessException e2) { - throw new IllegalArgumentException( - "IllegalAccessException setting quantile"); + throw MathRuntimeException.createIllegalArgumentException( + "cannot access setQuantile method in percentile implementation {0}", + percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { - throw new IllegalArgumentException( - "Error setting quantile" + e3.toString()); + throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); } this.percentileImpl = percentileImpl; } diff --git a/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java b/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java index f3d8903d2..ed259e483 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java +++ b/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java @@ -18,6 +18,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.AbstractStorelessUnivariateStatistic; /** @@ -211,7 +212,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se @Override public double evaluate(final double[] values) { if (values == null) { - throw new IllegalArgumentException("input values array is null"); + throw MathRuntimeException.createIllegalArgumentException("input values array is null"); } return evaluate(values, 0, values.length); } diff --git a/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java b/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java index 30fa01f4e..267ed018d 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java +++ b/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java @@ -18,6 +18,8 @@ package org.apache.commons.math.stat.descriptive.rank; import java.io.Serializable; import java.util.Arrays; + +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic; /** @@ -196,7 +198,8 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa test(values, begin, length); if ((p > 100) || (p <= 0)) { - throw new IllegalArgumentException("invalid quantile value: " + p); + throw MathRuntimeException.createIllegalArgumentException( + "out of bounds quantile value: {0}, must be in (0, 100]", p); } if (length == 0) { return Double.NaN; @@ -244,7 +247,8 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa */ public void setQuantile(final double p) { if (p <= 0 || p > 100) { - throw new IllegalArgumentException("Illegal quantile value: " + p); + throw MathRuntimeException.createIllegalArgumentException( + "out of bounds quantile value: {0}, must be in (0, 100]", p); } quantile = p; } diff --git a/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java b/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java index fb2825ffc..64716d5ec 100644 --- a/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java +++ b/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java @@ -18,6 +18,8 @@ package org.apache.commons.math.stat.regression; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.RealMatrixImpl; +import org.apache.commons.math.linear.RealVector; +import org.apache.commons.math.linear.RealVectorImpl; /** * Abstract base class for implementations of MultipleLinearRegression. @@ -31,7 +33,7 @@ public abstract class AbstractMultipleLinearRegression implements protected RealMatrix X; /** Y sample data. */ - protected RealMatrix Y; + protected RealVector Y; /** * Loads model x and y sample data from a flat array of data, overriding any previous sample. @@ -39,7 +41,7 @@ public abstract class AbstractMultipleLinearRegression implements * * @param data input data array * @param nobs number of observations (rows) - * @param nvars number of independent variables (columnns, not counting y) + * @param nvars number of independent variables (columns, not counting y) */ public void newSampleData(double[] data, int nobs, int nvars) { double[] y = new double[nobs]; @@ -53,7 +55,7 @@ public abstract class AbstractMultipleLinearRegression implements } } this.X = new RealMatrixImpl(x); - this.Y = new RealMatrixImpl(y); + this.Y = new RealVectorImpl(y); } /** @@ -62,7 +64,7 @@ public abstract class AbstractMultipleLinearRegression implements * @param y the [n,1] array representing the y sample */ protected void newYSampleData(double[] y) { - this.Y = new RealMatrixImpl(y); + this.Y = new RealVectorImpl(y); } /** @@ -120,17 +122,17 @@ public abstract class AbstractMultipleLinearRegression implements * {@inheritDoc} */ public double[] estimateRegressionParameters() { - RealMatrix b = calculateBeta(); - return b.getColumn(0); + RealVector b = calculateBeta(); + return b.getData(); } /** * {@inheritDoc} */ public double[] estimateResiduals() { - RealMatrix b = calculateBeta(); - RealMatrix e = Y.subtract(X.multiply(b)); - return e.getColumn(0); + RealVector b = calculateBeta(); + RealVector e = Y.subtract(X.operate(b)); + return e.getData(); } /** @@ -166,7 +168,7 @@ public abstract class AbstractMultipleLinearRegression implements * * @return beta */ - protected abstract RealMatrix calculateBeta(); + protected abstract RealVector calculateBeta(); /** * Calculates the beta variance of multiple linear regression in matrix @@ -193,9 +195,9 @@ public abstract class AbstractMultipleLinearRegression implements * * @return The residuals [n,1] matrix */ - protected RealMatrix calculateResiduals() { - RealMatrix b = calculateBeta(); - return Y.subtract(X.multiply(b)); + protected RealVector calculateResiduals() { + RealVector b = calculateBeta(); + return Y.subtract(X.operate(b)); } } diff --git a/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java b/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java index aea4a0cd2..64d5f8209 100644 --- a/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java +++ b/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java @@ -19,6 +19,7 @@ package org.apache.commons.math.stat.regression; import java.io.Serializable; 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; @@ -546,7 +547,9 @@ public class SimpleRegression implements Serializable { public double getSlopeConfidenceInterval(double alpha) throws MathException { if (alpha >= 1 || alpha <= 0) { - throw new IllegalArgumentException(); + throw MathRuntimeException.createIllegalArgumentException( + "out of bounds significance level {0}, must be in (0, 1)", + alpha); } return getSlopeStdErr() * distribution.inverseCumulativeProbability(1d - alpha / 2d); diff --git a/src/java/org/apache/commons/math/util/MathUtils.java b/src/java/org/apache/commons/math/util/MathUtils.java index d8d3e3741..28ee4a937 100644 --- a/src/java/org/apache/commons/math/util/MathUtils.java +++ b/src/java/org/apache/commons/math/util/MathUtils.java @@ -176,14 +176,7 @@ public final class MathUtils { * by a long integer. */ public static long binomialCoefficient(final int n, final int k) { - if (n < k) { - throw new IllegalArgumentException( - "must have n >= k for binomial coefficient (n,k)"); - } - if (n < 0) { - throw new IllegalArgumentException( - "must have n >= 0 for binomial coefficient (n,k)"); - } + checkBinomial(n, k); if ((n == k) || (k == 0)) { return 1; } @@ -253,14 +246,7 @@ public final class MathUtils { * @throws IllegalArgumentException if preconditions are not met. */ public static double binomialCoefficientDouble(final int n, final int k) { - if (n < k) { - throw new IllegalArgumentException( - "must have n >= k for binomial coefficient (n,k)"); - } - if (n < 0) { - throw new IllegalArgumentException( - "must have n >= 0 for binomial coefficient (n,k)"); - } + checkBinomial(n, k); if ((n == k) || (k == 0)) { return 1d; } @@ -301,14 +287,7 @@ public final class MathUtils { * @throws IllegalArgumentException if preconditions are not met. */ public static double binomialCoefficientLog(final int n, final int k) { - if (n < k) { - throw new IllegalArgumentException( - "must have n >= k for binomial coefficient (n,k)"); - } - if (n < 0) { - throw new IllegalArgumentException( - "must have n >= 0 for binomial coefficient (n,k)"); - } + checkBinomial(n, k); if ((n == k) || (k == 0)) { return 0; } @@ -353,6 +332,26 @@ public final class MathUtils { return logSum; } + + /** + * Check binomial preconditions. + * @param n the size of the set + * @param k the size of the subsets to be counted + * @exception IllegalArgumentException if preconditions are not met. + */ + private static void checkBinomial(final int n, final int k) + throws IllegalArgumentException { + if (n < k) { + throw MathRuntimeException.createIllegalArgumentException( + "must have n >= k for binomial coefficient (n,k), got n = {0}, k = {1}", + n, k); + } + if (n < 0) { + throw MathRuntimeException.createIllegalArgumentException( + "must have n >= 0 for binomial coefficient (n,k), got n = {0}", + n); + } + } /** * Compares two numbers given some amount of allowed error. @@ -501,7 +500,9 @@ public final class MathUtils { */ public static long factorial(final int n) { if (n < 0) { - throw new IllegalArgumentException("must have n >= 0 for n!"); + throw MathRuntimeException.createIllegalArgumentException( + "must have n >= 0 for n!, got n = {0}", + n); } if (n > 20) { throw new ArithmeticException( @@ -532,7 +533,9 @@ public final class MathUtils { */ public static double factorialDouble(final int n) { if (n < 0) { - throw new IllegalArgumentException("must have n >= 0 for n!"); + throw MathRuntimeException.createIllegalArgumentException( + "must have n >= 0 for n!, got n = {0}", + n); } if (n < 21) { return factorial(n); @@ -555,7 +558,9 @@ public final class MathUtils { */ public static double factorialLog(final int n) { if (n < 0) { - throw new IllegalArgumentException("must have n > 0 for n!"); + throw MathRuntimeException.createIllegalArgumentException( + "must have n >= 0 for n!, got n = {0}", + n); } if (n < 21) { return Math.log(factorial(n)); @@ -1132,7 +1137,18 @@ public final class MathUtils { unscaled = Math.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY)); break; default : - throw new IllegalArgumentException("Invalid rounding method."); + throw MathRuntimeException.createIllegalArgumentException( + "invalid rounding method {0}, valid methods: {1} ({2}), {3} ({4})," + + " {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})", + roundingMethod, + "ROUND_CEILING", BigDecimal.ROUND_CEILING, + "ROUND_DOWN", BigDecimal.ROUND_DOWN, + "ROUND_FLOOR", BigDecimal.ROUND_FLOOR, + "ROUND_HALF_DOWN", BigDecimal.ROUND_HALF_DOWN, + "ROUND_HALF_EVEN", BigDecimal.ROUND_HALF_EVEN, + "ROUND_HALF_UP", BigDecimal.ROUND_HALF_UP, + "ROUND_UNNECESSARY", BigDecimal.ROUND_UNNECESSARY, + "ROUND_UP", BigDecimal.ROUND_UP); } return unscaled; }