You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2010/06/17 01:03:42 UTC
svn commit: r955423 [5/6] - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/
main/java/org/apache/commons/math/analysis/integration/
main/java/org/apache/commons/math/analysis/interpolation/
main/java/org/apache/commons/math/analys...
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java Wed Jun 16 23:03:38 2010
@@ -39,6 +39,7 @@ import org.apache.commons.math.distribut
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 R
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 R
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 R
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 R
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 R
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 R
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 R
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 R
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 R
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 R
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 R
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 R
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();
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java Wed Jun 16 23:03:38 2010
@@ -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 UncorrelatedRandomVectorGen
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();
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/ValueServer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/ValueServer.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/ValueServer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/ValueServer.java Wed Jun 16 23:03:38 2010
@@ -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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java Wed Jun 16 23:03:38 2010
@@ -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 Serial
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 Serial
} 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());
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/StatUtils.java Wed Jun 16 23:03:38 2010
@@ -28,6 +28,7 @@ import org.apache.commons.math.stat.desc
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(
+ LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, sample2.length);
+ }
+ if (n < 2) {
throw MathRuntimeException.createIllegalArgumentException(
- "input arrays must have the same length and at least two elements ({0} and {1})",
- n, sample2.length);
+ LocalizedFormats.INSUFFICIENT_DIMENSION, n, 2);
}
for (int i = 0; i < n; i++) {
diff = sample1[i] - sample2[i];
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/Covariance.java Wed Jun 16 23:03:38 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.linear.Re
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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java Wed Jun 16 23:03:38 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.distribut
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; i<xArray.length; i++) {
regression.addData(xArray[i], yArray[i]);
}
return regression.getR();
}
- else {
- throw MathRuntimeException.createIllegalArgumentException(
- "invalid array dimensions. xArray has size {0}; yArray has {1} elements",
- xArray.length, yArray.length);
- }
}
/**
@@ -274,7 +276,7 @@ public class PearsonsCorrelation {
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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/SpearmansCorrelation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/SpearmansCorrelation.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/SpearmansCorrelation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/SpearmansCorrelation.java Wed Jun 16 23:03:38 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.linear.Bl
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.stat.ranking.NaturalRanking;
import org.apache.commons.math.stat.ranking.RankingAlgorithm;
+import org.apache.commons.math.util.LocalizedFormats;
/**
* <p>Spearman'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);
- }
}
/**
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java Wed Jun 16 23:03:38 2010
@@ -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 AbstractStorelessU
@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 AbstractStorelessU
*/
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);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java Wed Jun 16 23:03:38 2010
@@ -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 AbstractUnivariate
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) {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java Wed Jun 16 23:03:38 2010
@@ -31,6 +31,7 @@ import org.apache.commons.math.stat.desc
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 imple
/** 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 imple
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 imple
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 imple
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());
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java Wed Jun 16 23:03:38 2010
@@ -30,6 +30,7 @@ import org.apache.commons.math.stat.desc
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 MultivariateSummaryStatisti
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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java Wed Jun 16 23:03:38 2010
@@ -28,6 +28,7 @@ import org.apache.commons.math.stat.desc
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 implement
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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java Wed Jun 16 23:03:38 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.MathRunti
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 <a href="http://www.xycoon.com/geometric_mean.htm">
@@ -194,7 +195,7 @@ public class GeometricMean extends Abstr
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());
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java Wed Jun 16 23:03:38 2010
@@ -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 AbstractSt
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 AbstractSt
moment.clear();
} else {
throw MathRuntimeException.createIllegalStateException(
- "statistics constructed from external moments cannot be cleared");
+ LocalizedFormats.CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java Wed Jun 16 23:03:38 2010
@@ -20,6 +20,7 @@ package org.apache.commons.math.stat.des
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;
/**
* <p>Computes the semivariance of a set of values with respect to a given cutoff value.
@@ -175,7 +176,7 @@ public class SemiVariance extends Abstra
@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);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java Wed Jun 16 23:03:38 2010
@@ -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 AbstractSt
@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);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java Wed Jun 16 23:03:38 2010
@@ -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 Abstract
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 Abstract
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;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java Wed Jun 16 23:03:38 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
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 implement
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 implement
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 implement
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 implement
// 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 implement
// 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 implement
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 implement
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 implement
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 implement
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 implement
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 implement
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 implement
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]);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java Wed Jun 16 23:03:38 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.distribut
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
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
// 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
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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java Wed Jun 16 23:03:38 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.distribut
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.desc
*/
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());
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java Wed Jun 16 23:03:38 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.linear.Re
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 AbstractMultipleLi
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 AbstractMultipleLi
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);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java Wed Jun 16 23:03:38 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.MathExcep
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
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() *
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java Wed Jun 16 23:03:38 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionE
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 <a href="http://documents.wolfram.com/v5/Add-onsLinks/
@@ -223,7 +224,7 @@ public class FastCosineTransformer imple
final int n = f.length - 1;
if (!FastFourierTransformer.isPowerOf2(n)) {
throw MathRuntimeException.createIllegalArgumentException(
- "{0} is not a power of 2 plus one",
+ LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE,
f.length);
}
if (n == 1) { // trivial case
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java Wed Jun 16 23:03:38 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.FunctionE
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 <a href="http://mathworld.wolfram.com/FastFourierTransform.html">
@@ -48,18 +49,6 @@ public class FastFourierTransformer impl
/** 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 impl
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 impl
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 impl
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 impl
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 impl
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 impl
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 impl
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 impl
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 impl
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(
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java Wed Jun 16 23:03:38 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.transfor
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 <a href="http://www.archive.chipcenter.com/dsp/DSP000517F1.html">Fast Hadamard Transform</a> (FHT).
@@ -160,7 +161,7 @@ public class FastHadamardTransformer imp
// 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 imp
// 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);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java Wed Jun 16 23:03:38 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionE
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 <a href="http://documents.wolfram.com/v5/Add-onsLinks/
@@ -217,7 +218,7 @@ public class FastSineTransformer impleme
FastFourierTransformer.verifyDataSet(f);
if (f[0] != 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
- "first element is not 0: {0}",
+ LocalizedFormats.FIRST_ELEMENT_NOT_ZERO,
f[0]);
}
final int n = f.length;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java Wed Jun 16 23:03:38 2010
@@ -151,7 +151,7 @@ public abstract class ContinuedFraction
final double scale = Math.max(a,b);
if (scale <= 0) { // Can't scale
throw new ConvergenceException(
- "Continued fraction convergents diverged to +/- infinity for value {0}",
+ LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
x);
}
infinite = true;
@@ -175,7 +175,7 @@ public abstract class ContinuedFraction
if (infinite) {
// Scaling failed
throw new ConvergenceException(
- "Continued fraction convergents diverged to +/- infinity for value {0}",
+ LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
x);
}
@@ -183,7 +183,7 @@ public abstract class ContinuedFraction
if (Double.isNaN(r)) {
throw new ConvergenceException(
- "Continued fraction diverged to NaN for value {0}",
+ LocalizedFormats.CONTINUED_FRACTION_NAN_DIVERGENCE,
x);
}
relativeError = Math.abs(r / c - 1.0);
@@ -198,7 +198,7 @@ public abstract class ContinuedFraction
if (n >= maxIterations) {
throw new MaxIterationsExceededException(maxIterations,
- "Continued fraction convergents failed to converge for value {0}",
+ LocalizedFormats.NON_CONVERGENT_CONTINUED_FRACTION,
x);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java?rev=955423&r1=955422&r2=955423&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DefaultTransformer.java Wed Jun 16 23:03:38 2010
@@ -44,7 +44,7 @@ public class DefaultTransformer implemen
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 implemen
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());
}
}
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DummyLocalizable.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DummyLocalizable.java?rev=955423&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DummyLocalizable.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DummyLocalizable.java Wed Jun 16 23:03:38 2010
@@ -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;
+ }
+
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DummyLocalizable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/DummyLocalizable.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Localizable.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Localizable.java?rev=955423&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Localizable.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Localizable.java Wed Jun 16 23:03:38 2010
@@ -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);
+
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Localizable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Localizable.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision