Submitted by:	Brent Worden
Reviewed by:	Mark Diggory


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark R. Diggory 2003-09-07 03:12:56 +00:00
parent 606b836061
commit ffa6aac264
21 changed files with 169 additions and 111 deletions

View File

@ -1,8 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.1//EN"
"http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
<!-- commons math customization of default Checkstyle behavior -->
<module name="Checker">
@ -18,6 +16,16 @@
<module name="OperatorWrap">
<property name="option" value="eol"/>
</module>
<module name="JavadocType">
<property name="versionFormat" value="\$Revision.*\$ \$Date.*\$"/>
</module>
<module name="JavadocMethod">
<property name="allowUndeclaredRTE" value="true"/>
</module>
<module name="JavadocVariable"/>
</module>
</module>

View File

@ -58,12 +58,9 @@ import org.apache.commons.math.MathException;
/**
* Utility class comprised of root finding techniques.
*
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:02:43 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*/
public class RootFinding {
/** Maximum allowed numerical error. */
private static final double EPSILON = 10e-9;
/**
* Default constructor. Prohibit construction.
*/

View File

@ -56,10 +56,11 @@ package org.apache.commons.math.analysis;
/**
* Computes a natural spline interpolation for the data set.
*
* @version $Revision: 1.3 $ $Date: 2003/07/30 21:58:10 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*
*/
public class SplineInterpolator implements UnivariateRealInterpolator {
/** the natural spline coefficients. */
private double[][] c = null;
/**
@ -67,8 +68,6 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
* @param xval the arguments for the interpolation points
* @param yval the values for the interpolation points
* @return a function which interpolates the data set
* @throws MathException if arguments violate assumptions made by the
* interpolationg algorithm
*/
public UnivariateRealFunction interpolate(double[] xval, double[] yval) {
if (xval.length != yval.length) {

View File

@ -61,7 +61,7 @@ package org.apache.commons.math.analysis;
* (this may be controversial, because the configuration data
* may also be used for the default solver used by the static
* solve() method).
* @version $Revision: 1.4 $ $Date: 2003/07/30 21:58:10 $
* @version $Revision: 1.5 $ $Date: 2003/09/07 03:12:56 $
*/
public abstract class UnivariateRealSolverFactory {
/**
@ -71,8 +71,8 @@ public abstract class UnivariateRealSolverFactory {
}
/**
* Create a new factory.
* @return a new factory.
* @todo add comment
* @todo for now, return the only concrete factory. Later, allow for a
* plugable implementation, possibly using SPI and commons-discovery.
*/

View File

@ -56,8 +56,8 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.MathException;
/**
* @version $Revision: 1.1 $ $Date: 2003/07/30 22:06:37 $
* @todo add comment
* Utility routines for {@link UnivariateRealSolver} objects.
* @version $Revision: 1.2 $ $Date: 2003/09/07 03:12:56 $
*/
public class UnivariateRealSolverUtil {
/**

View File

@ -80,7 +80,7 @@ import org.apache.commons.math.stat.Univariate;
* build grouped frequnecy histograms representing the input data or to
* generate random values "like" those in the input file -- i.e., the values
* generated will follow the distribution of the values in the file.
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:02:59 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*/
public interface EmpiricalDistribution {
@ -102,6 +102,7 @@ public interface EmpiricalDistribution {
* Generates a random value from this distribution<p>
* <strong>Preconditions:</strong><ul>
* <li>the distribution must be loaded before invoking this method</li></ul>
* @return the random value.
* @throws IllegalStateException if the distribution has not been loaded
*/
double getNextValue() throws IllegalStateException;
@ -111,9 +112,10 @@ public interface EmpiricalDistribution {
* <p>Returns a Univariate describing this distribution</p>
* <strong>Preconditions:</strong><ul>
* <li>the distribution must be loaded before invoking this method</li></ul>
* @return the sample statistics
* @throws IllegalStateException if the distribution has not been loaded
*/
Univariate getSampleStats();
Univariate getSampleStats() throws IllegalStateException;
/**
* Loads a saved distribution from a file.

View File

@ -89,7 +89,7 @@ import org.apache.commons.math.stat.UnivariateImpl;
* entry per line.</li>
* </ol></p>
*
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:02:59 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*/
public class EmpiricalDistributionImpl implements Serializable,EmpiricalDistribution {
@ -217,7 +217,11 @@ public class EmpiricalDistributionImpl implements Serializable,EmpiricalDistribu
loaded = true;
}
/** Generates a random value from this distribution */
/**
* Generates a random value from this distribution
* @return the random value.
* @throws IllegalStateException if the distribution has not been loaded
*/
public double getNextValue() throws IllegalStateException {
if (!loaded) {

View File

@ -104,7 +104,7 @@ import java.util.Collection;
* (so secure sequences started with calls to reseedSecure(long) won't be
* identical).</li></ul>
*
* @version $Revision: 1.2 $ $Date: 2003/07/07 23:19:21 $
* @version $Revision: 1.3 $ $Date: 2003/09/07 03:12:56 $
*/
public class RandomDataImpl implements RandomData {
@ -127,6 +127,8 @@ public class RandomDataImpl implements RandomData {
* len/2+1 binary bytes are generated using the underlying Random</li>
* <li>
* Each binary byte is translated into 2 hex digits</li></ol>
* @param len the desired string length.
* @return the random string.
*/
public String nextHexString(int len) {
if (len <= 0) {
@ -162,7 +164,14 @@ public class RandomDataImpl implements RandomData {
}
return outBuffer.toString().substring(0, len);
}
/**
* Generate a random int value uniformly distributed between
* <code>lower</code> and <code>upper</code>, inclusive.
* @param lower the lower bound.
* @param upper the upper bound.
* @return the random integer.
*/
public int nextInt(int lower, int upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@ -172,6 +181,13 @@ public class RandomDataImpl implements RandomData {
return lower + (int) (rand.nextDouble() * (upper - lower + 1));
}
/**
* Generate a random long value uniformly distributed between
* <code>lower</code> and <code>upper</code>, inclusive.
* @param lower the lower bound.
* @param upper the upper bound.
* @return the random integer.
*/
public long nextLong(long lower, long upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@ -194,6 +210,8 @@ public class RandomDataImpl implements RandomData {
* <p>
* TODO: find external reference or provide justification for the claim
* that this yields a cryptographically secure sequence of hex strings.
* @param len the desired string length.
* @return the random string.
*/
public String nextSecureHexString(int len) {
if (len <= 0) {
@ -243,6 +261,14 @@ public class RandomDataImpl implements RandomData {
return outBuffer.toString().substring(0, len);
}
/**
* Generate a random int value uniformly distributed between
* <code>lower</code> and <code>upper</code>, inclusive. This algorithm
* using a secure random number generator for its engine.
* @param lower the lower bound.
* @param upper the upper bound.
* @return the random integer.
*/
public int nextSecureInt(int lower, int upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@ -252,6 +278,14 @@ public class RandomDataImpl implements RandomData {
return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
/**
* Generate a random long value uniformly distributed between
* <code>lower</code> and <code>upper</code>, inclusive. This algorithm
* using a secure random number generator for its engine.
* @param lower the lower bound.
* @param upper the upper bound.
* @return the random integer.
*/
public long nextSecureLong(long lower, long upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@ -267,16 +301,17 @@ public class RandomDataImpl implements RandomData {
* described
* <a href ="http://dmawww.epfl.ch/benarous/Pmmi/interactive/rng7.htm">
* here</a>
*
* @param mean mean of the Poisson distribution.
* @return the random Poisson value.
*/
public long nextPoisson(double mean) {
if (mean <= 0) {
throw new IllegalArgumentException("Poisson mean must be > 0");
}
double p = Math.exp(-mean);
long n = 0;
double r = 1.0d;
Random rand = getRan();
if (mean <= 0) {
throw new IllegalArgumentException("Poisson mean must be > 0");
}
while (true) {
double rnd = rand.nextDouble();
r = r * rnd;
@ -288,6 +323,15 @@ public class RandomDataImpl implements RandomData {
}
}
/**
* Generate a random value from a Normal distribution. This algorithm
* generates random values for the general Normal distribution with the
* given mean, <code>mu</code> and the given standard deviation,
* <code>sigma</code>.
* @param mu the mean of the distribution.
* @param sigma the standard deviation of the distribution.
* @return the random Normal value.
*/
public double nextGaussian(double mu, double sigma) {
if (sigma <= 0) {
throw new IllegalArgumentException("Gaussian std dev must be > 0");
@ -300,6 +344,8 @@ public class RandomDataImpl implements RandomData {
* <strong>Algorithm Description</strong>: Uses the
* <a href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html">
* Inversion Method</a> to generate exponential from uniform deviates.
* @param mean the mean of the distribution.
* @return the random Exponential value.
*/
public double nextExponential(double mean) {
if (mean < 0.0) {
@ -320,6 +366,9 @@ public class RandomDataImpl implements RandomData {
* random double if Random.nextDouble() returns 0).
* This is necessary to provide a symmetric output interval
* (both endpoints excluded).
* @param lower the lower bound.
* @param upper the upper bound.
* @return the random value.
*/
public double nextUniform(double lower, double upper) {
if (lower >= upper) {
@ -327,11 +376,14 @@ public class RandomDataImpl implements RandomData {
("lower bound must be <= upper bound");
}
Random rand = getRan();
double result = lower + rand.nextDouble() * (upper - lower);
while (result == lower) {
result = lower + rand.nextDouble() * (upper - lower);
// insure nextDouble() isn't 0.0
double u = rand.nextDouble();
while(u <= 0.0){
u = rand.nextDouble();
}
return result;
return lower + u * (upper - lower);
}
/**
@ -442,7 +494,9 @@ public class RandomDataImpl implements RandomData {
* Uses a 2-cycle permutation shuffle, as described
* <a href=http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node83.html>
* here</a>
*
* @param n the population size.
* @param k the number to choose.
* @return the random permutation.
*/
public int[] nextPermutation(int n, int k) {
if (k > n) {
@ -472,6 +526,9 @@ public class RandomDataImpl implements RandomData {
* This technique is described, and proven to generate random samples,
* <a href="http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node83.html">
* here</a>
* @param c Collection to sample from.
* @param k sample size.
* @return the random sample.
*/
public Object[] nextSample(Collection c, int k) {
int len = c.size();

View File

@ -62,7 +62,7 @@ import org.apache.commons.math.util.BeanTransformer;
* univariate statistics for a List of Java Beans by property. This
* implementation uses beanutils' PropertyUtils to get a simple, nested,
* indexed, mapped, or combined property from an element of a List.
* @version $Revision: 1.4 $ $Date: 2003/08/09 04:03:41 $
* @version $Revision: 1.5 $ $Date: 2003/09/07 03:12:56 $
*/
public class BeanListUnivariateImpl extends ListUnivariateImpl {
@ -113,11 +113,11 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
*/
public void addValue(double v) {
String msg =
"The BeanListUnivariateImpl does not accept values "
+ "through the addValue method. Because elements of this list "
+ "are JavaBeans, one must be sure to set the 'propertyName' "
+ "property and add new Beans to the underlying list via the "
+ "addBean(Object bean) method";
"The BeanListUnivariateImpl does not accept values " +
"through the addValue method. Because elements of this list " +
"are JavaBeans, one must be sure to set the 'propertyName' " +
"property and add new Beans to the underlying list via the " +
"addBean(Object bean) method";
throw new UnsupportedOperationException(msg);
}

View File

@ -60,7 +60,7 @@ import org.apache.commons.math.util.DefaultTransformer;
import org.apache.commons.math.util.NumberTransformer;
/**
* @version $Revision: 1.4 $ $Date: 2003/07/15 03:45:10 $
* @version $Revision: 1.5 $ $Date: 2003/09/07 03:12:56 $
*/
public class ListUnivariateImpl
extends AbstractStoreUnivariate
@ -88,6 +88,7 @@ public class ListUnivariateImpl
/**
* Construct a ListUnivariate with a specific List.
* @param list The list that will back this Univariate
* @param transformer the number transformer used to convert the list items.
*/
public ListUnivariateImpl(List list, NumberTransformer transformer) {
super();
@ -107,8 +108,9 @@ public class ListUnivariateImpl
// take into account only the last n elements of the list
// as definied by windowSize
if (windowSize != Univariate.INFINITE_WINDOW
&& windowSize < list.size()) {
if (windowSize != Univariate.INFINITE_WINDOW &&
windowSize < list.size())
{
length = list.size() - Math.max(0, list.size() - windowSize);
}
@ -130,8 +132,9 @@ public class ListUnivariateImpl
int calcIndex = index;
if (windowSize != Univariate.INFINITE_WINDOW
&& windowSize < list.size()) {
if (windowSize != Univariate.INFINITE_WINDOW &&
windowSize < list.size())
{
calcIndex = (list.size() - windowSize) + index;
}
@ -198,14 +201,16 @@ public class ListUnivariateImpl
}
/**
* @return
* Access the number transformer.
* @return the number transformer.
*/
public NumberTransformer getTransformer() {
return transformer;
}
/**
* @param transformer
* Modify the number transformer.
* @param transformer the new number transformer.
*/
public void setTransformer(NumberTransformer transformer) {
this.transformer = transformer;

View File

@ -57,7 +57,7 @@ package org.apache.commons.math.stat;
* StatUtils provides easy static implementations of common double[] based
* statistical methods. These return a single result value or in some cases, as
* identified in the javadoc for each method, Double.NaN.
* @version $Revision: 1.15 $ $Date: 2003/08/09 04:03:41 $
* @version $Revision: 1.16 $ $Date: 2003/09/07 03:12:56 $
*/
public final class StatUtils {
@ -255,8 +255,8 @@ public final class StatUtils {
accum2 += (values[i] - mean);
}
variance =
(accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1);
(accum - (Math.pow(accum2, 2) / ((double) length))) /
(double) (length - 1);
}
return variance;
}

View File

@ -57,7 +57,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatistic;
import org.apache.commons.math.util.ContractableDoubleArray;
/**
* @version $Revision: 1.5 $ $Date: 2003/07/15 03:45:10 $
* @version $Revision: 1.6 $ $Date: 2003/09/07 03:12:56 $
*/
public class StoreUnivariateImpl extends AbstractStoreUnivariate {
@ -113,8 +113,8 @@ public class StoreUnivariateImpl extends AbstractStoreUnivariate {
eDA.addElement(v);
} else {
String msg =
"A window Univariate had more element than "
+ "the windowSize. This is an inconsistent state.";
"A window Univariate had more element than " +
"the windowSize. This is an inconsistent state.";
throw new RuntimeException(msg);
}
} else {

View File

@ -58,7 +58,7 @@ package org.apache.commons.math.stat.univariate.moment;
* <a href="http://www.spss.com/tech/stat/Algorithms/11.5/descriptives.pdf">
* recursive strategy
* </a>. Both incremental and evaluation strategies currently use this approach.
* @version $Revision: 1.7 $ $Date: 2003/08/09 04:03:40 $
* @version $Revision: 1.8 $ $Date: 2003/09/07 03:12:56 $
*/
public class FourthMoment extends ThirdMoment {
@ -91,11 +91,8 @@ public class FourthMoment extends ThirdMoment {
n3 = (double) (n - 3);
m4 =
m4
- (4.0 * v * prevM3)
+ (6.0 * v2 * prevM2)
+ ((n0 * n0) - 3 * n1) * (v2 * v2 * n1 * n0);
m4 = m4 - (4.0 * v * prevM3) + (6.0 * v2 * prevM2) +
((n0 * n0) - 3 * n1) * (v2 * v2 * n1 * n0);
}
/**

View File

@ -62,7 +62,7 @@ import org
.AbstractStorelessUnivariateStatistic;
/**
* @version $Revision: 1.7 $ $Date: 2003/08/09 04:03:40 $
* @version $Revision: 1.8 $ $Date: 2003/09/07 03:12:56 $
*/
public class Kurtosis extends AbstractStorelessUnivariateStatistic {
@ -119,13 +119,9 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic {
kurtosis = 0.0;
} else {
kurtosis =
(moment.n0 * (moment.n0 + 1) * moment.m4
- 3 * moment.m2 * moment.m2 * moment.n1)
/ (moment.n1
* moment.n2
* moment.n3
* variance
* variance);
(moment.n0 * (moment.n0 + 1) * moment.m4 -
3 * moment.m2 * moment.m2 * moment.n1) /
(moment.n1 * moment.n2 * moment.n3 * variance * variance);
}
n = moment.n;
}
@ -193,8 +189,8 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic {
double stdDev =
Math.sqrt(
(accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1));
(accum - (Math.pow(accum2, 2) / ((double) length))) /
(double) (length - 1));
// Sum the ^4 of the distance from the mean divided by the
// standard deviation

View File

@ -63,7 +63,7 @@ import org
/**
*
* @version $Revision: 1.7 $ $Date: 2003/08/09 04:03:40 $
* @version $Revision: 1.8 $ $Date: 2003/09/07 03:12:56 $
*/
public class Skewness extends AbstractStorelessUnivariateStatistic {
@ -119,12 +119,8 @@ public class Skewness extends AbstractStorelessUnivariateStatistic {
if (moment.n <= 2 || variance < 10E-20) {
skewness = 0.0;
} else {
skewness =
(moment.n0 * moment.m3)
/ (moment.n1
* moment.n2
* Math.sqrt(variance)
* variance);
skewness = (moment.n0 * moment.m3) /
(moment.n1 * moment.n2 * Math.sqrt(variance) * variance);
}
n = moment.n;
}
@ -191,8 +187,8 @@ public class Skewness extends AbstractStorelessUnivariateStatistic {
}
double stdDev =
Math.sqrt(
(accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1));
(accum - (Math.pow(accum2, 2) / ((double) length))) /
(double) (length - 1));
// Calculate the skew as the sum the cubes of the distance
// from the mean divided by the standard deviation.

View File

@ -57,7 +57,7 @@ import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatis
/**
*
* @version $Revision: 1.8 $ $Date: 2003/08/09 04:03:40 $
* @version $Revision: 1.9 $ $Date: 2003/09/07 03:12:56 $
*/
public class Variance extends AbstractStorelessUnivariateStatistic {
@ -177,9 +177,8 @@ public class Variance extends AbstractStorelessUnivariateStatistic {
accum += Math.pow((values[i] - m), 2.0);
accum2 += (values[i] - m);
}
var =
(accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1);
var = (accum - (Math.pow(accum2, 2) / ((double) length))) /
(double) (length - 1);
}
}
return var;

View File

@ -64,7 +64,7 @@ import org.apache.commons.math.analysis.ConvergenceException;
* <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
* Continued Fraction</a></li>
* </ul>
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:04:12 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*/
public abstract class ContinuedFraction {
/** Maximum allowed numerical error. */
@ -189,8 +189,9 @@ public abstract class ContinuedFraction {
f[1][1] = (a[1][0] * an[0][1]) + (a[1][1] * an[1][1]);
// determine if we're close enough
if (Math.abs((f[0][0] * f[1][1]) - (f[1][0] * f[0][1]))
< Math.abs(epsilon * f[1][0] * f[1][1])) {
if (Math.abs((f[0][0] * f[1][1]) - (f[1][0] * f[0][1])) <
Math.abs(epsilon * f[1][0] * f[1][1]))
{
ret = f[0][0] / f[1][0];
} else {
if (n >= maxIterations) {

View File

@ -88,7 +88,7 @@ import java.io.Serializable;
* internal storage array is swapped.
* </p>
*
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:04:12 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*/
public class ContractableDoubleArray
extends ExpandableDoubleArray
@ -292,27 +292,27 @@ public class ContractableDoubleArray
if (contractionCritera < expansionFactor) {
String msg =
"Contraction criteria can never be smaller than "
+ "the expansion factor. This would lead to a never "
+ "ending loop of expansion and contraction as a newly "
+ "expanded internal storage array would immediately "
+ "satisfy the criteria for contraction";
"Contraction criteria can never be smaller than " +
"the expansion factor. This would lead to a never " +
"ending loop of expansion and contraction as a newly " +
"expanded internal storage array would immediately " +
"satisfy the criteria for contraction";
throw new IllegalArgumentException(msg);
}
if (contractionCriteria <= 1.0) {
String msg =
"The contraction criteria must be a number larger "
+ "than one. If the contractionCriteria is less than or "
+ "equal to one an endless loop of contraction and "
+ "expansion would ensue as an internalArray.length "
+ "== numElements would satisfy the contraction criteria";
"The contraction criteria must be a number larger " +
"than one. If the contractionCriteria is less than or " +
"equal to one an endless loop of contraction and " +
"expansion would ensue as an internalArray.length " +
"== numElements would satisfy the contraction criteria";
throw new IllegalArgumentException(msg);
}
if (expansionFactor < 1.0) {
String msg =
"The expansion factor must be a number greater " + "than 1.0";
"The expansion factor must be a number greater than 1.0";
throw new IllegalArgumentException(msg);
}
}

View File

@ -88,7 +88,7 @@ import java.io.Serializable;
* expand the array 10 times - first from 2 -> 4. then 4 -> 8, 8 -> 16,
* and so on until we reach 4096 which is sufficient to hold 3546 elements.
* </p>
* @version $Revision: 1.4 $ $Date: 2003/07/09 20:04:12 $
* @version $Revision: 1.5 $ $Date: 2003/09/07 03:12:56 $
*/
public class ExpandableDoubleArray implements Serializable, DoubleArray {
@ -199,9 +199,8 @@ public class ExpandableDoubleArray implements Serializable, DoubleArray {
this.initialCapacity = initialCapacity;
} else {
String msg =
"The initial capacity supplied: "
+ initialCapacity
+ "must be a positive integer";
"The initial capacity supplied: " + initialCapacity +
"must be a positive integer";
throw new IllegalArgumentException(msg);
}
}
@ -270,15 +269,14 @@ public class ExpandableDoubleArray implements Serializable, DoubleArray {
double value = Double.NaN;
if (index >= numElements) {
String msg =
"The index specified: "
+ index
+ " is larger than the current number of elements";
"The index specified: " + index +
" is larger than the current number of elements";
throw new ArrayIndexOutOfBoundsException(msg);
} else if (index >= 0) {
value = internalArray[startIndex + index];
} else {
String msg =
"Elements cannot be retrieved from a negative " + "array index";
"Elements cannot be retrieved from a negative array index";
throw new ArrayIndexOutOfBoundsException(msg);
}
return value;
@ -403,9 +401,8 @@ public class ExpandableDoubleArray implements Serializable, DoubleArray {
public synchronized void discardFrontElements(int i) {
if (i > numElements) {
String msg =
"Cannot discard more elements than are"
+ "contained in this array.";
String msg = "Cannot discard more elements than are" +
"contained in this array.";
throw new IllegalArgumentException(msg);
} else if (i < 0) {
String msg = "Cannot discard a negative number of elements.";

View File

@ -82,7 +82,7 @@ package org.apache.commons.math.util;
* "fixed" in memory, this implementation will never allocate, or copy
* the internal storage array to a new array instance.
* </p>
* @version $Revision: 1.5 $ $Date: 2003/07/09 20:04:12 $
* @version $Revision: 1.6 $ $Date: 2003/09/07 03:12:56 $
*/
public class FixedDoubleArray implements DoubleArray {
@ -164,8 +164,8 @@ public class FixedDoubleArray implements DoubleArray {
public double getElement(int index) {
if (index > (size - 1)) {
String msg =
"Attempted to retrieve an element outside of "
+ "the element array";
"Attempted to retrieve an element outside of " +
"the element array";
throw new ArrayIndexOutOfBoundsException(msg);
} else {
// Return the element requested, if the index supplied
@ -235,9 +235,9 @@ public class FixedDoubleArray implements DoubleArray {
// is trying to add an element beyond the boundaries of the
// fixed array.
String msg =
"Attempted to add a value to an array of fixed "
+ "size, please use addElementRolling "
+ "to avoid this exception";
"Attempted to add a value to an array of fixed " +
"size, please use addElementRolling " +
"to avoid this exception";
throw new ArrayIndexOutOfBoundsException(msg);
}
}

View File

@ -344,7 +344,7 @@ public class InterpolatorTest extends TestCase {
try {
double xval[] = { 0.0, 1.0 };
double yval[] = { 0.0, 1.0, 2.0 };
UnivariateRealFunction f = i.interpolate(xval, yval);
i.interpolate(xval, yval);
fail("Failed to detect data set array with different sizes.");
} catch (IllegalArgumentException iae) {
}
@ -352,7 +352,7 @@ public class InterpolatorTest extends TestCase {
try {
double xval[] = { 0.0, 1.0, 0.5 };
double yval[] = { 0.0, 1.0, 2.0 };
UnivariateRealFunction f = i.interpolate(xval, yval);
i.interpolate(xval, yval);
fail("Failed to detect unsorted arguments.");
} catch (IllegalArgumentException iae) {
}