From 4e50bbcb90a44c3921dbe9cfea32fde4a83399a2 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 18 May 2008 19:37:23 +0000 Subject: [PATCH] Replaced Raw types by Parameterized types where appropriate. The various ArrayList, HashSet and HashMap used in math have be restricted to the content they are intended for. This removes lots of warnings that have appeared after the switch to Java 5, and improves safety (for example the categories used by OneWayAnova are guaranteed to be double arrays at compile time). Two difficult cases where not handled here: the Frequency class and the Fitness interface. The first one mixes types and needs to be studied before any change is attempted. The second one generates some side effects on the overall package which is still under development. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@657612 13f79535-47bb-0310-9956-ffa450edef68 --- .../estimation/SimpleEstimationProblem.java | 14 +++---- .../commons/math/fraction/Fraction.java | 9 ++--- .../math/ode/AdaptiveStepsizeIntegrator.java | 4 +- .../math/ode/ContinuousOutputModel.java | 40 ++++++++----------- .../math/ode/FirstOrderIntegrator.java | 2 +- .../math/ode/RungeKuttaIntegrator.java | 4 +- .../math/ode/SwitchingFunctionsHandler.java | 34 ++++++++-------- .../optimization/DirectSearchOptimizer.java | 9 ++--- .../math/random/EmpiricalDistribution.java | 3 +- .../random/EmpiricalDistributionImpl.java | 24 +++++------ .../commons/math/random/RandomData.java | 2 +- .../commons/math/random/RandomDataImpl.java | 2 +- .../math/stat/inference/OneWayAnova.java | 6 +-- .../math/stat/inference/OneWayAnovaImpl.java | 30 +++++--------- .../math/stat/inference/TestUtils.java | 6 +-- .../commons/math/util/TransformerMap.java | 22 +++++----- .../estimation/GaussNewtonEstimatorTest.java | 33 +++++++-------- .../LevenbergMarquardtEstimatorTest.java | 35 +++++++--------- .../random/EmpiricalDistributionTest.java | 13 +++--- .../commons/math/random/RandomDataTest.java | 15 +++---- .../stat/data/CertifiedDataAbstractTest.java | 14 +++---- .../stat/descriptive/ListUnivariateImpl.java | 8 ++-- .../descriptive/ListUnivariateImplTest.java | 6 +-- .../MixedListUnivariateImplTest.java | 8 ++-- .../math/stat/inference/OneWayAnovaTest.java | 28 ++++--------- .../math/stat/inference/TestUtilsTest.java | 2 +- 26 files changed, 160 insertions(+), 213 deletions(-) diff --git a/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java b/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java index 304203e21..1f32600f3 100644 --- a/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java +++ b/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java @@ -18,7 +18,6 @@ package org.apache.commons.math.estimation; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -46,8 +45,8 @@ public class SimpleEstimationProblem implements EstimationProblem { * Build an empty instance without parameters nor measurements. */ public SimpleEstimationProblem() { - parameters = new ArrayList(); - measurements = new ArrayList(); + parameters = new ArrayList(); + measurements = new ArrayList(); } /** @@ -65,9 +64,8 @@ public class SimpleEstimationProblem implements EstimationProblem { public EstimatedParameter[] getUnboundParameters() { // filter the unbound parameters - List unbound = new ArrayList(parameters.size()); - for (Iterator iterator = parameters.iterator(); iterator.hasNext();) { - EstimatedParameter p = (EstimatedParameter) iterator.next(); + List unbound = new ArrayList(parameters.size()); + for (EstimatedParameter p : parameters) { if (! p.isBound()) { unbound.add(p); } @@ -102,9 +100,9 @@ public class SimpleEstimationProblem implements EstimationProblem { } /** Estimated parameters. */ - private final List parameters; + private final List parameters; /** Measurements. */ - private final List measurements; + private final List measurements; } diff --git a/src/java/org/apache/commons/math/fraction/Fraction.java b/src/java/org/apache/commons/math/fraction/Fraction.java index 4f9015cd9..678d9de50 100644 --- a/src/java/org/apache/commons/math/fraction/Fraction.java +++ b/src/java/org/apache/commons/math/fraction/Fraction.java @@ -25,7 +25,7 @@ import org.apache.commons.math.util.MathUtils; * @since 1.1 * @version $Revision$ $Date$ */ -public class Fraction extends Number implements Comparable { +public class Fraction extends Number implements Comparable { /** A fraction representing "1 / 1". */ public static final Fraction ONE = new Fraction(1, 1); @@ -34,7 +34,7 @@ public class Fraction extends Number implements Comparable { public static final Fraction ZERO = new Fraction(0, 1); /** Serializable version identifier */ - private static final long serialVersionUID = -8958519416450949235L; + private static final long serialVersionUID = -5731055832688548463L; /** The denominator. */ private final int denominator; @@ -246,13 +246,12 @@ public class Fraction extends Number implements Comparable { * @return -1 if this is less than object, +1 if this is greater * than object, 0 if they are equal. */ - public int compareTo(Object object) { + public int compareTo(Fraction object) { int ret = 0; if (this != object) { - Fraction other = (Fraction)object; double first = doubleValue(); - double second = other.doubleValue(); + double second = object.doubleValue(); if (first < second) { ret = -1; diff --git a/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java b/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java index 2f42334d0..ca2aa0f4d 100644 --- a/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java +++ b/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java @@ -163,7 +163,7 @@ public abstract class AdaptiveStepsizeIntegrator double maxCheckInterval, double convergence, int maxIterationCount) { - switchesHandler.add(function, maxCheckInterval, convergence, maxIterationCount); + switchesHandler.addSwitchingFunction(function, maxCheckInterval, convergence, maxIterationCount); } /** Get all the switching functions that have been added to the integrator. @@ -171,7 +171,7 @@ public abstract class AdaptiveStepsizeIntegrator * @see #addSwitchingFunction(SwitchingFunction, double, double, int) * @see #clearSwitchingFunctions() */ - public Collection getSwitchingFunctions() { + public Collection getSwitchingFunctions() { return switchesHandler.getSwitchingFunctions(); } diff --git a/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java b/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java index 7fa22fec4..d1bb7d7ab 100644 --- a/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java +++ b/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java @@ -18,7 +18,6 @@ package org.apache.commons.math.ode; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.io.Serializable; @@ -45,14 +44,14 @@ import java.io.Serializable; * get the model value at any time or to navigate through the * data).

* - *

If problem modelization is done with several separate + *

If problem modeling is done with several separate * integration phases for contiguous intervals, the same * ContinuousOutputModel can be used as step handler for all * integration phases as long as they are performed in order and in * the same direction. As an example, one can extrapolate the * trajectory of a satellite with one model (i.e. one set of * differential equations) up to the beginning of a maneuver, use - * another more complex model including thrusters modelization and + * another more complex model including thrusters modeling and * accurate attitude control during the maneuver, and revert to the * first model after the end of the maneuver. If the same continuous * output model handles the steps of all integration phases, the user @@ -86,7 +85,7 @@ public class ContinuousOutputModel * Build an empty continuous output model. */ public ContinuousOutputModel() { - steps = new ArrayList(); + steps = new ArrayList(); reset(); } @@ -129,8 +128,8 @@ public class ContinuousOutputModel } - for (Iterator iter = model.steps.iterator(); iter.hasNext(); ) { - steps.add(((AbstractStepInterpolator) iter.next()).copy()); + for (StepInterpolator interpolator : model.steps) { + steps.add(interpolator.copy()); } index = steps.size() - 1; @@ -171,17 +170,15 @@ public class ContinuousOutputModel public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { - AbstractStepInterpolator ai = (AbstractStepInterpolator) interpolator; - if (steps.size() == 0) { initialTime = interpolator.getPreviousTime(); forward = interpolator.isForward(); } - steps.add(ai.copy()); + steps.add(interpolator.copy()); if (isLast) { - finalTime = ai.getCurrentTime(); + finalTime = interpolator.getCurrentTime(); index = steps.size() - 1; } @@ -210,7 +207,7 @@ public class ContinuousOutputModel * @return interpolation point time */ public double getInterpolatedTime() { - return ((StepInterpolator) steps.get(index)).getInterpolatedTime(); + return steps.get(index).getInterpolatedTime(); } /** Set the time of the interpolated point. @@ -230,11 +227,11 @@ public class ContinuousOutputModel try { // initialize the search with the complete steps table int iMin = 0; - StepInterpolator sMin = (StepInterpolator) steps.get(iMin); + StepInterpolator sMin = steps.get(iMin); double tMin = 0.5 * (sMin.getPreviousTime() + sMin.getCurrentTime()); int iMax = steps.size() - 1; - StepInterpolator sMax = (StepInterpolator) steps.get(iMax); + StepInterpolator sMax = steps.get(iMax); double tMax = 0.5 * (sMax.getPreviousTime() + sMax.getCurrentTime()); // handle points outside of the integration interval @@ -254,7 +251,7 @@ public class ContinuousOutputModel while (iMax - iMin > 5) { // use the last estimated index as the splitting index - StepInterpolator si = (StepInterpolator) steps.get(index); + StepInterpolator si = steps.get(index); int location = locatePoint(time, si); if (location < 0) { iMax = index; @@ -270,7 +267,7 @@ public class ContinuousOutputModel // compute a new estimate of the index in the reduced table slice int iMed = (iMin + iMax) / 2; - StepInterpolator sMed = (StepInterpolator) steps.get(iMed); + StepInterpolator sMed = steps.get(iMed); double tMed = 0.5 * (sMed.getPreviousTime() + sMed.getCurrentTime()); if ((Math.abs(tMed - tMin) < 1e-6) || (Math.abs(tMax - tMed) < 1e-6)) { @@ -306,14 +303,11 @@ public class ContinuousOutputModel // now the table slice is very small, we perform an iterative search index = iMin; - while ((index <= iMax) && - (locatePoint(time, (StepInterpolator) steps.get(index)) > 0)) { + while ((index <= iMax) && (locatePoint(time, steps.get(index)) > 0)) { ++index; } - StepInterpolator si = (StepInterpolator) steps.get(index); - - si.setInterpolatedTime(time); + steps.get(index).setInterpolatedTime(time); } catch (DerivativeException de) { throw new RuntimeException("unexpected DerivativeException caught: " + @@ -327,7 +321,7 @@ public class ContinuousOutputModel * @return state vector at time {@link #getInterpolatedTime} */ public double[] getInterpolatedState() { - return ((StepInterpolator) steps.get(index)).getInterpolatedState(); + return steps.get(index).getInterpolatedState(); } /** Compare a step interval and a double. @@ -369,9 +363,9 @@ public class ContinuousOutputModel private int index; /** Steps table. */ - private List steps; + private List steps; /** Serializable version identifier */ - private static final long serialVersionUID = 2259286184268533249L; + private static final long serialVersionUID = -1417964919405031606L; } diff --git a/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java b/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java index 2124d031b..5feb98f38 100644 --- a/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java +++ b/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java @@ -74,7 +74,7 @@ public interface FirstOrderIntegrator { * @see #addSwitchingFunction(SwitchingFunction, double, double, int) * @see #clearSwitchingFunctions() */ - public Collection getSwitchingFunctions(); + public Collection getSwitchingFunctions(); /** Remove all the switching functions that have been added to the integrator. * @see #addSwitchingFunction(SwitchingFunction, double, double, int) diff --git a/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java b/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java index a4e365b0b..521e329b3 100644 --- a/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java +++ b/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java @@ -105,7 +105,7 @@ public abstract class RungeKuttaIntegrator double maxCheckInterval, double convergence, int maxIterationCount) { - switchesHandler.add(function, maxCheckInterval, convergence, maxIterationCount); + switchesHandler.addSwitchingFunction(function, maxCheckInterval, convergence, maxIterationCount); } /** Get all the switching functions that have been added to the integrator. @@ -113,7 +113,7 @@ public abstract class RungeKuttaIntegrator * @see #addSwitchingFunction(SwitchingFunction, double, double, int) * @see #clearSwitchingFunctions() */ - public Collection getSwitchingFunctions() { + public Collection getSwitchingFunctions() { return switchesHandler.getSwitchingFunctions(); } diff --git a/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java b/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java index fc37f680a..32ea09113 100644 --- a/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java +++ b/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java @@ -20,7 +20,6 @@ package org.apache.commons.math.ode; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.apache.commons.math.ConvergenceException; @@ -39,7 +38,7 @@ public class SwitchingFunctionsHandler { * Create an empty handler */ public SwitchingFunctionsHandler() { - functions = new ArrayList(); + functions = new ArrayList(); first = null; initialized = false; } @@ -55,23 +54,23 @@ public class SwitchingFunctionsHandler { * @see #getSwitchingFunctions() * @see #clearSwitchingFunctions() */ - public void add(SwitchingFunction function, double maxCheckInterval, - double convergence, int maxIterationCount) { + public void addSwitchingFunction(SwitchingFunction function, double maxCheckInterval, + double convergence, int maxIterationCount) { functions.add(new SwitchState(function, maxCheckInterval, convergence, maxIterationCount)); } /** Get all the switching functions that have been added to the handler. * @return an unmodifiable collection of the added switching functions - * @see #add(SwitchingFunction, double, double, int) + * @see #addSwitchingFunction(SwitchingFunction, double, double, int) * @see #clearSwitchingFunctions() */ - public Collection getSwitchingFunctions() { + public Collection getSwitchingFunctions() { return Collections.unmodifiableCollection(functions); } /** Remove all the switching functions that have been added to the handler. - * @see #add(SwitchingFunction, double, double, int) + * @see #addSwitchingFunction(SwitchingFunction, double, double, int) * @see #getSwitchingFunctions() */ public void clearSwitchingFunctions() { @@ -114,8 +113,8 @@ public class SwitchingFunctionsHandler { double t0 = interpolator.getPreviousTime(); interpolator.setInterpolatedTime(t0); double [] y = interpolator.getInterpolatedState(); - for (Iterator iter = functions.iterator(); iter.hasNext();) { - ((SwitchState) iter.next()).reinitializeBegin(t0, y); + for (SwitchState state : functions) { + state.reinitializeBegin(t0, y); } initialized = true; @@ -123,9 +122,8 @@ public class SwitchingFunctionsHandler { } // check events occurrence - for (Iterator iter = functions.iterator(); iter.hasNext();) { + for (SwitchState state : functions) { - SwitchState state = (SwitchState) iter.next(); if (state.evaluateStep(interpolator)) { if (first == null) { first = state; @@ -176,8 +174,8 @@ public class SwitchingFunctionsHandler { public void stepAccepted(double t, double[] y) throws IntegratorException { try { - for (Iterator iter = functions.iterator(); iter.hasNext();) { - ((SwitchState) iter.next()).stepAccepted(t, y); + for (SwitchState state : functions) { + state.stepAccepted(t, y); } } catch (SwitchException se) { throw new IntegratorException(se); @@ -189,8 +187,8 @@ public class SwitchingFunctionsHandler { * @return true if the integration should be stopped */ public boolean stop() { - for (Iterator iter = functions.iterator(); iter.hasNext();) { - if (((SwitchState) iter.next()).stop()) { + for (SwitchState state : functions) { + if (state.stop()) { return true; } } @@ -209,8 +207,8 @@ public class SwitchingFunctionsHandler { public boolean reset(double t, double[] y) throws IntegratorException { try { boolean resetDerivatives = false; - for (Iterator iter = functions.iterator(); iter.hasNext();) { - if (((SwitchState) iter.next()).reset(t, y)) { + for (SwitchState state : functions) { + if (state.reset(t, y)) { resetDerivatives = true; } } @@ -221,7 +219,7 @@ public class SwitchingFunctionsHandler { } /** Switching functions. */ - private List functions; + private List functions; /** First active switching function. */ private SwitchState first; diff --git a/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java b/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java index 1316d6e9e..aedeab30a 100644 --- a/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java @@ -571,16 +571,15 @@ public abstract class DirectSearchOptimizer { } /** Comparator for {@link PointCostPair PointCostPair} objects. */ - private static Comparator pointCostPairComparator = new Comparator() { - public int compare(Object o1, Object o2) { + private static Comparator pointCostPairComparator = + new Comparator() { + public int compare(PointCostPair o1, PointCostPair o2) { if (o1 == null) { return (o2 == null) ? 0 : +1; } else if (o2 == null) { return -1; } - double cost1 = ((PointCostPair) o1).getCost(); - double cost2 = ((PointCostPair) o2).getCost(); - return (cost1 < cost2) ? -1 : ((o1 == o2) ? 0 : +1); + return (o1.getCost() < o2.getCost()) ? -1 : ((o1 == o2) ? 0 : +1); } }; diff --git a/src/java/org/apache/commons/math/random/EmpiricalDistribution.java b/src/java/org/apache/commons/math/random/EmpiricalDistribution.java index 60696fed3..94bdbdb2a 100644 --- a/src/java/org/apache/commons/math/random/EmpiricalDistribution.java +++ b/src/java/org/apache/commons/math/random/EmpiricalDistribution.java @@ -23,6 +23,7 @@ import java.net.URL; import java.util.List; import org.apache.commons.math.stat.descriptive.StatisticalSummary; +import org.apache.commons.math.stat.descriptive.SummaryStatistics; /** * Represents an @@ -118,7 +119,7 @@ public interface EmpiricalDistribution { * * @return List of bin statistics */ - List getBinStats(); + List getBinStats(); /** * Returns the array of upper bounds for the bins. Bins are:
diff --git a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index 909fcc35b..0fbc60454 100644 --- a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -61,10 +61,10 @@ import org.apache.commons.math.stat.descriptive.StatisticalSummary; public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistribution { /** Serializable version identifier */ - private static final long serialVersionUID = -6773236347582113490L; + private static final long serialVersionUID = 5729073523949762654L; /** List of SummaryStatistics objects characterizing the bins */ - private List binStats = null; + private List binStats = null; /** Sample statistics */ private SummaryStatistics sampleStats = null; @@ -85,7 +85,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * Creates a new EmpiricalDistribution with the default bin count. */ public EmpiricalDistributionImpl() { - binStats = new ArrayList(); + binStats = new ArrayList(); } /** @@ -95,7 +95,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib */ public EmpiricalDistributionImpl(int binCount) { this.binCount = binCount; - binStats = new ArrayList(); + binStats = new ArrayList(); } /** @@ -254,8 +254,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib double val = 0.0d; while ((str = inputStream.readLine()) != null) { val = Double.parseDouble(str); - SummaryStatistics stats = - (SummaryStatistics) binStats.get(findBin(min, val, delta)); + SummaryStatistics stats = binStats.get(findBin(min, val, delta)); stats.addValue(val); } @@ -319,8 +318,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib throws IOException { for (int i = 0; i < inputArray.length; i++) { SummaryStatistics stats = - (SummaryStatistics) binStats.get( - findBin(min, inputArray[i], delta)); + binStats.get(findBin(min, inputArray[i], delta)); stats.addValue(inputArray[i]); } } @@ -369,12 +367,10 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib // Assign upperBounds based on bin counts upperBounds = new double[binCount]; upperBounds[0] = - ((double)((SummaryStatistics)binStats.get(0)).getN())/ - (double)sampleStats.getN(); + ((double) binStats.get(0).getN()) / (double) sampleStats.getN(); for (int i = 1; i < binCount-1; i++) { upperBounds[i] = upperBounds[i-1] + - ((double)((SummaryStatistics)binStats.get(i)).getN())/ - (double)sampleStats.getN(); + ((double) binStats.get(i).getN()) / (double) sampleStats.getN(); } upperBounds[binCount-1] = 1.0d; } @@ -411,7 +407,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib // Use this to select the bin and generate a Gaussian within the bin for (int i = 0; i < binCount; i++) { if (x <= upperBounds[i]) { - SummaryStatistics stats = (SummaryStatistics)binStats.get(i); + SummaryStatistics stats = binStats.get(i); if (stats.getN() > 0) { if (stats.getStandardDeviation() > 0) { // more than one obs return randomData.nextGaussian @@ -453,7 +449,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * * @return List of bin statistics. */ - public List getBinStats() { + public List getBinStats() { return binStats; } diff --git a/src/java/org/apache/commons/math/random/RandomData.java b/src/java/org/apache/commons/math/random/RandomData.java index 53f8f4ca0..842c83fdb 100644 --- a/src/java/org/apache/commons/math/random/RandomData.java +++ b/src/java/org/apache/commons/math/random/RandomData.java @@ -268,5 +268,5 @@ public interface RandomData { * @param k size of the sample * @return random sample of k elements from c */ - Object[] nextSample(Collection c, int k); + Object[] nextSample(Collection c, int k); } diff --git a/src/java/org/apache/commons/math/random/RandomDataImpl.java b/src/java/org/apache/commons/math/random/RandomDataImpl.java index 8d2e7ae5d..4e65d4ad9 100644 --- a/src/java/org/apache/commons/math/random/RandomDataImpl.java +++ b/src/java/org/apache/commons/math/random/RandomDataImpl.java @@ -545,7 +545,7 @@ public class RandomDataImpl implements RandomData, Serializable { * @param k sample size. * @return the random sample. */ - public Object[] nextSample(Collection c, int k) { + public Object[] nextSample(Collection c, int k) { int len = c.size(); if (k > len) { throw new IllegalArgumentException diff --git a/src/java/org/apache/commons/math/stat/inference/OneWayAnova.java b/src/java/org/apache/commons/math/stat/inference/OneWayAnova.java index bce9a1603..becaf21ef 100644 --- a/src/java/org/apache/commons/math/stat/inference/OneWayAnova.java +++ b/src/java/org/apache/commons/math/stat/inference/OneWayAnova.java @@ -50,7 +50,7 @@ public interface OneWayAnova { * @throws MathException if the statistic can not be computed do to a * convergence or other numerical error. */ - public double anovaFValue(Collection categoryData) + public double anovaFValue(Collection categoryData) throws IllegalArgumentException, MathException; /** @@ -71,7 +71,7 @@ public interface OneWayAnova { * @throws MathException if the statistic can not be computed do to a * convergence or other numerical error. */ - public double anovaPValue(Collection categoryData) + public double anovaPValue(Collection categoryData) throws IllegalArgumentException, MathException; /** @@ -96,7 +96,7 @@ public interface OneWayAnova { * @throws MathException if the statistic can not be computed do to a * convergence or other numerical error. */ - public boolean anovaTest(Collection categoryData, double alpha) + public boolean anovaTest(Collection categoryData, double alpha) throws IllegalArgumentException, MathException; } \ No newline at end of file diff --git a/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java b/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java index 10849fb68..22e5edb0a 100644 --- a/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java +++ b/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java @@ -16,15 +16,13 @@ */ package org.apache.commons.math.stat.inference; -import org.apache.commons.math.MathException; -import org.apache.commons.math.stat.descriptive.summary.Sum; -import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; +import java.util.Collection; +import org.apache.commons.math.MathException; import org.apache.commons.math.distribution.FDistribution; import org.apache.commons.math.distribution.FDistributionImpl; - -import java.util.Collection; -import java.util.Iterator; +import org.apache.commons.math.stat.descriptive.summary.Sum; +import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; /** @@ -65,7 +63,7 @@ public class OneWayAnovaImpl implements OneWayAnova { * are as defined
* here

*/ - public double anovaFValue(Collection categoryData) + public double anovaFValue(Collection categoryData) throws IllegalArgumentException, MathException { AnovaStats a = anovaStats(categoryData); return a.F; @@ -81,7 +79,7 @@ public class OneWayAnovaImpl implements OneWayAnova { * where F is the F value and cumulativeProbability * is the commons-math implementation of the F distribution.

*/ - public double anovaPValue(Collection categoryData) + public double anovaPValue(Collection categoryData) throws IllegalArgumentException, MathException { AnovaStats a = anovaStats(categoryData); FDistribution fdist = new FDistributionImpl(a.dfbg, a.dfwg); @@ -99,7 +97,7 @@ public class OneWayAnovaImpl implements OneWayAnova { * is the commons-math implementation of the F distribution.

*

True is returned iff the estimated p-value is less than alpha.

*/ - public boolean anovaTest(Collection categoryData, double alpha) + public boolean anovaTest(Collection categoryData, double alpha) throws IllegalArgumentException, MathException { if ((alpha <= 0) || (alpha > 0.5)) { throw new IllegalArgumentException("bad significance level: " + alpha); @@ -118,7 +116,7 @@ public class OneWayAnovaImpl implements OneWayAnova { * preconditions specified in the interface definition * @throws MathException if an error occurs computing the Anova stats */ - private AnovaStats anovaStats(Collection categoryData) + private AnovaStats anovaStats(Collection categoryData) throws IllegalArgumentException, MathException { // check if we have enough categories @@ -128,14 +126,7 @@ public class OneWayAnovaImpl implements OneWayAnova { } // check if each category has enough data and all is double[] - for (Iterator iterator = categoryData.iterator(); iterator.hasNext();) { - double[] array; - try { - array = (double[])iterator.next(); - } catch (ClassCastException ex) { - throw new IllegalArgumentException( - "ANOVA: categoryData contains non-double[] elements."); - } + for (double[] array : categoryData) { if (array.length <= 1) { throw new IllegalArgumentException( "ANOVA: one element of categoryData has fewer than 2 values."); @@ -148,8 +139,7 @@ public class OneWayAnovaImpl implements OneWayAnova { SumOfSquares totsumsq = new SumOfSquares(); int totnum = 0; - for (Iterator iterator = categoryData.iterator(); iterator.hasNext();) { - double[] data = (double[])iterator.next(); + for (double[] data : categoryData) { Sum sum = new Sum(); SumOfSquares sumsq = new SumOfSquares(); diff --git a/src/java/org/apache/commons/math/stat/inference/TestUtils.java b/src/java/org/apache/commons/math/stat/inference/TestUtils.java index 18a900156..e5178095f 100644 --- a/src/java/org/apache/commons/math/stat/inference/TestUtils.java +++ b/src/java/org/apache/commons/math/stat/inference/TestUtils.java @@ -382,7 +382,7 @@ public class TestUtils { * * @since 1.2 */ - public static double oneWayAnovaFValue(Collection categoryData) + public static double oneWayAnovaFValue(Collection categoryData) throws IllegalArgumentException, MathException { return oneWayAnova.anovaFValue(categoryData); } @@ -392,7 +392,7 @@ public class TestUtils { * * @since 1.2 */ - public static double oneWayAnovaPValue(Collection categoryData) + public static double oneWayAnovaPValue(Collection categoryData) throws IllegalArgumentException, MathException { return oneWayAnova.anovaPValue(categoryData); } @@ -402,7 +402,7 @@ public class TestUtils { * * @since 1.2 */ - public static boolean oneWayAnovaTest(Collection categoryData, double alpha) + public static boolean oneWayAnovaTest(Collection categoryData, double alpha) throws IllegalArgumentException, MathException { return oneWayAnova.anovaTest(categoryData, alpha); } diff --git a/src/java/org/apache/commons/math/util/TransformerMap.java b/src/java/org/apache/commons/math/util/TransformerMap.java index c28fee3f3..2c8ea5371 100644 --- a/src/java/org/apache/commons/math/util/TransformerMap.java +++ b/src/java/org/apache/commons/math/util/TransformerMap.java @@ -34,8 +34,8 @@ import org.apache.commons.math.MathException; public class TransformerMap implements NumberTransformer, Serializable { /** Serializable version identifier */ - private static final long serialVersionUID = -942772950698439883L; - + private static final long serialVersionUID = 4605318041528645258L; + /** * A default Number Transformer for Numbers and numeric Strings. */ @@ -44,13 +44,13 @@ public class TransformerMap implements NumberTransformer, Serializable { /** * The internal Map. */ - private Map map = null; + private Map, NumberTransformer> map = null; /** - * + * Build a map containing only the default transformer. */ public TransformerMap() { - map = new HashMap(); + map = new HashMap, NumberTransformer>(); defaultTransformer = new DefaultTransformer(); } @@ -59,7 +59,7 @@ public class TransformerMap implements NumberTransformer, Serializable { * @param key Class to check * @return true|false */ - public boolean containsClass(Class key) { + public boolean containsClass(Class key) { return map.containsKey(key); } @@ -78,7 +78,7 @@ public class TransformerMap implements NumberTransformer, Serializable { * @param key The Class of the object * @return the mapped NumberTransformer or null. */ - public NumberTransformer getTransformer(Class key) { + public NumberTransformer getTransformer(Class key) { return (NumberTransformer) map.get(key); } @@ -90,7 +90,7 @@ public class TransformerMap implements NumberTransformer, Serializable { * @param transformer The NumberTransformer * @return the replaced transformer if one is present */ - public Object putTransformer(Class key, NumberTransformer transformer) { + public NumberTransformer putTransformer(Class key, NumberTransformer transformer) { return map.put(key, transformer); } @@ -100,7 +100,7 @@ public class TransformerMap implements NumberTransformer, Serializable { * @return the removed transformer if one is present or * null if none was present. */ - public Object removeTransformer(Class key) { + public NumberTransformer removeTransformer(Class key) { return map.remove(key); } @@ -115,7 +115,7 @@ public class TransformerMap implements NumberTransformer, Serializable { * Returns the Set of Classes used as keys in the map. * @return Set of Classes */ - public Set classes() { + public Set> classes() { return map.keySet(); } @@ -124,7 +124,7 @@ public class TransformerMap implements NumberTransformer, Serializable { * in the map. * @return Set of NumberTransformers */ - public Collection transformers() { + public Collection transformers() { return map.values(); } diff --git a/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java b/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java index 24f0f507b..9442bcddc 100644 --- a/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java +++ b/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java @@ -19,15 +19,10 @@ package org.apache.commons.math.estimation; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; -import org.apache.commons.math.estimation.EstimatedParameter; -import org.apache.commons.math.estimation.EstimationException; -import org.apache.commons.math.estimation.EstimationProblem; -import org.apache.commons.math.estimation.GaussNewtonEstimator; -import org.apache.commons.math.estimation.WeightedMeasurement; - -import junit.framework.*; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** *

Some of the unit tests are re-implementations of the MINPACK set = new HashSet(); for (int i = 0; i < measurements.length; ++i) { addMeasurement(measurements[i]); EstimatedParameter[] parameters = measurements[i].getParameters(); @@ -578,8 +573,8 @@ public class GaussNewtonEstimatorTest set.add(parameters[j]); } } - for (Iterator iterator = set.iterator(); iterator.hasNext();) { - addParameter((EstimatedParameter) iterator.next()); + for (EstimatedParameter p : set) { + addParameter(p); } } @@ -627,7 +622,7 @@ public class GaussNewtonEstimatorTest public Circle(double cx, double cy) { this.cx = new EstimatedParameter("cx", cx); this.cy = new EstimatedParameter(new EstimatedParameter("cy", cy)); - points = new ArrayList(); + points = new ArrayList(); } public void addPoint(double px, double py) { @@ -652,24 +647,24 @@ public class GaussNewtonEstimatorTest public double getPartialRadiusX() { double dRdX = 0; - for (Iterator iterator = points.iterator(); iterator.hasNext();) { - dRdX += ((PointModel) iterator.next()).getPartialDiX(); + for (PointModel point : points) { + dRdX += point.getPartialDiX(); } return dRdX / points.size(); } public double getPartialRadiusY() { double dRdY = 0; - for (Iterator iterator = points.iterator(); iterator.hasNext();) { - dRdY += ((PointModel) iterator.next()).getPartialDiY(); + for (PointModel point : points) { + dRdY += point.getPartialDiY(); } return dRdY / points.size(); } public double getRadius() { double r = 0; - for (Iterator iterator = points.iterator(); iterator.hasNext();) { - r += ((PointModel) iterator.next()).getCenterDistance(); + for (PointModel point : points) { + r += point.getCenterDistance(); } return r / points.size(); } @@ -725,7 +720,7 @@ public class GaussNewtonEstimatorTest private EstimatedParameter cx; private EstimatedParameter cy; - private ArrayList points; + private ArrayList points; } diff --git a/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java b/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java index ff7bf98b5..47c9954eb 100644 --- a/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java +++ b/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java @@ -18,17 +18,11 @@ package org.apache.commons.math.estimation; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; +import java.util.HashSet; -import org.apache.commons.math.estimation.EstimatedParameter; -import org.apache.commons.math.estimation.EstimationException; -import org.apache.commons.math.estimation.EstimationProblem; -import org.apache.commons.math.estimation.LevenbergMarquardtEstimator; -import org.apache.commons.math.estimation.WeightedMeasurement; - -import junit.framework.*; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** *

Some of the unit tests are re-implementations of the MINPACK set = new HashSet(); for (int i = 0; i < measurements.length; ++i) { EstimatedParameter[] parameters = measurements[i].getParameters(); for (int j = 0; j < parameters.length; ++j) { - map.put(parameters[j], null); + set.add(parameters[j]); } } - Set set = map.keySet(); return (EstimatedParameter[]) set.toArray(new EstimatedParameter[set.size()]); } @@ -674,7 +667,7 @@ public class LevenbergMarquardtEstimatorTest public Circle(double cx, double cy) { this.cx = new EstimatedParameter("cx", cx); this.cy = new EstimatedParameter("cy", cy); - points = new ArrayList(); + points = new ArrayList(); } public void addPoint(double px, double py) { @@ -699,24 +692,24 @@ public class LevenbergMarquardtEstimatorTest public double getPartialRadiusX() { double dRdX = 0; - for (Iterator iterator = points.iterator(); iterator.hasNext();) { - dRdX += ((PointModel) iterator.next()).getPartialDiX(); + for (PointModel point : points) { + dRdX += point.getPartialDiX(); } return dRdX / points.size(); } public double getPartialRadiusY() { double dRdY = 0; - for (Iterator iterator = points.iterator(); iterator.hasNext();) { - dRdY += ((PointModel) iterator.next()).getPartialDiY(); + for (PointModel point : points) { + dRdY += point.getPartialDiY(); } return dRdY / points.size(); } public double getRadius() { double r = 0; - for (Iterator iterator = points.iterator(); iterator.hasNext();) { - r += ((PointModel) iterator.next()).getCenterDistance(); + for (PointModel point : points) { + r += point.getCenterDistance(); } return r / points.size(); } @@ -772,7 +765,7 @@ public class LevenbergMarquardtEstimatorTest private EstimatedParameter cx; private EstimatedParameter cy; - private ArrayList points; + private ArrayList points; } diff --git a/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java b/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java index c10d3e20b..d2d9532b1 100644 --- a/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java +++ b/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java @@ -16,16 +16,15 @@ */ package org.apache.commons.math.random; -import junit.framework.Test; -import junit.framework.TestSuite; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; -import java.util.Iterator; + +import junit.framework.Test; +import junit.framework.TestSuite; import org.apache.commons.math.RetryTestCase; import org.apache.commons.math.TestUtils; @@ -58,7 +57,7 @@ public final class EmpiricalDistributionTest extends RetryTestCase { new BufferedReader(new InputStreamReader( url.openStream())); String str = null; - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList(); while ((str = in.readLine()) != null) { list.add(Double.valueOf(str)); } @@ -67,8 +66,8 @@ public final class EmpiricalDistributionTest extends RetryTestCase { dataArray = new double[list.size()]; int i = 0; - for (Iterator iter = list.iterator(); iter.hasNext();) { - dataArray[i] = ((Double)iter.next()).doubleValue(); + for (Double data : list) { + dataArray[i] = data.doubleValue(); i++; } } diff --git a/src/test/org/apache/commons/math/random/RandomDataTest.java b/src/test/org/apache/commons/math/random/RandomDataTest.java index 2147cdcdd..ef40af134 100644 --- a/src/test/org/apache/commons/math/random/RandomDataTest.java +++ b/src/test/org/apache/commons/math/random/RandomDataTest.java @@ -486,14 +486,14 @@ public class RandomDataTest extends RetryTestCase { long[] observed = {0,0,0,0,0,0,0,0,0,0}; double[] expected = {100,100,100,100,100,100,100,100,100,100}; - HashSet cPop = new HashSet(); //{0,1,2,3,4} + HashSet cPop = new HashSet(); //{0,1,2,3,4} for (int i = 0; i < 5; i++) { cPop.add(Integer.toString(i)); } Object[] sets = new Object[10]; // 2-sets from 5 for (int i = 0; i < 10; i ++) { - HashSet hs = new HashSet(); + HashSet hs = new HashSet(); hs.add(c[i][0]); hs.add(c[i][1]); sets[i] = hs; @@ -511,7 +511,7 @@ public class RandomDataTest extends RetryTestCase { testStatistic.chiSquare(expected,observed) < 27.88); // Make sure sample of size = size of collection returns same collection - HashSet hs = new HashSet(); + HashSet hs = new HashSet(); hs.add("one"); Object[] one = randomData.nextSample(hs,1); String oneString = (String) one[0]; @@ -529,18 +529,19 @@ public class RandomDataTest extends RetryTestCase { // Make sure we fail for empty collection try { - hs = new HashSet(); + hs = new HashSet(); one = randomData.nextSample(hs,0); fail("n = k = 0, expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { ; } } - + + @SuppressWarnings("unchecked") private int findSample(Object[] u, Object[] samp) { for (int i = 0; i < u.length; i++) { - HashSet set = (HashSet) u[i]; - HashSet sampSet = new HashSet(); + HashSet set = (HashSet) u[i]; + HashSet sampSet = new HashSet(); for (int j = 0; j < samp.length; j++) { sampSet.add(samp[j]); } diff --git a/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java b/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java index c0564c6cf..77af4d7e0 100644 --- a/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java +++ b/src/test/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java @@ -24,15 +24,14 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import junit.framework.TestCase; + import org.apache.commons.math.TestUtils; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.apache.commons.math.stat.descriptive.SummaryStatistics; -import junit.framework.TestCase; - /** * @version $Revision$ $Date$ */ @@ -42,12 +41,12 @@ public abstract class CertifiedDataAbstractTest extends TestCase { private SummaryStatistics summaries; - private Map certifiedValues; + private Map certifiedValues; protected void setUp() throws Exception { descriptives = new DescriptiveStatistics(); summaries = new SummaryStatistics(); - certifiedValues = new HashMap(); + certifiedValues = new HashMap(); loadData(); } @@ -110,10 +109,7 @@ public abstract class CertifiedDataAbstractTest extends TestCase { } public void testCertifiedValues() { - Iterator iter = certifiedValues.keySet().iterator(); - - while (iter.hasNext()) { - String name = iter.next().toString(); + for (String name : certifiedValues.keySet()) { Double expectedValue = (Double)certifiedValues.get(name); Double summariesValue = getProperty(summaries, name); diff --git a/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java b/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java index 348c1f056..c0d9eb037 100644 --- a/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java +++ b/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java @@ -38,7 +38,7 @@ public class ListUnivariateImpl extends DescriptiveStatistics implements Seriali * Holds a reference to a list - GENERICs are going to make * our lives easier here as we could only accept List */ - protected List list; + protected List list; /** Number Transformer maps Objects to Number for us. */ protected NumberTransformer transformer; @@ -47,14 +47,14 @@ public class ListUnivariateImpl extends DescriptiveStatistics implements Seriali * No argument Constructor */ public ListUnivariateImpl(){ - this(new ArrayList()); + this(new ArrayList()); } /** * Construct a ListUnivariate with a specific List. * @param list The list that will back this DescriptiveStatistics */ - public ListUnivariateImpl(List list) { + public ListUnivariateImpl(List list) { this(list, new DefaultTransformer()); } @@ -63,7 +63,7 @@ public class ListUnivariateImpl extends DescriptiveStatistics implements Seriali * @param list The list that will back this DescriptiveStatistics * @param transformer the number transformer used to convert the list items. */ - public ListUnivariateImpl(List list, NumberTransformer transformer) { + public ListUnivariateImpl(List list, NumberTransformer transformer) { super(); this.list = list; this.transformer = transformer; diff --git a/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java b/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java index f7f6c198e..2a5c93ed0 100644 --- a/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java +++ b/src/test/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java @@ -62,7 +62,7 @@ public final class ListUnivariateImplTest extends TestCase { /** test stats */ public void testStats() { - List externalList = new ArrayList(); + List externalList = new ArrayList(); DescriptiveStatistics u = new ListUnivariateImpl( externalList ); @@ -84,7 +84,7 @@ public final class ListUnivariateImplTest extends TestCase { } public void testN0andN1Conditions() throws Exception { - List list = new ArrayList(); + List list = new ArrayList(); DescriptiveStatistics u = new ListUnivariateImpl( list ); @@ -115,7 +115,7 @@ public final class ListUnivariateImplTest extends TestCase { } public void testProductAndGeometricMean() throws Exception { - ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList()); + ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList()); u.setWindowSize(10); u.addValue( 1.0 ); diff --git a/src/test/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java b/src/test/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java index 7e5d9a769..210d2a461 100644 --- a/src/test/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java +++ b/src/test/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java @@ -69,7 +69,7 @@ public final class MixedListUnivariateImplTest extends TestCase { /** test stats */ public void testStats() { - List externalList = new ArrayList(); + List externalList = new ArrayList(); DescriptiveStatistics u = new ListUnivariateImpl(externalList,transformers); @@ -91,7 +91,7 @@ public final class MixedListUnivariateImplTest extends TestCase { } public void testN0andN1Conditions() throws Exception { - DescriptiveStatistics u = new ListUnivariateImpl(new ArrayList(),transformers); + DescriptiveStatistics u = new ListUnivariateImpl(new ArrayList(),transformers); assertTrue( "Mean of n = 0 set should be NaN", @@ -120,7 +120,7 @@ public final class MixedListUnivariateImplTest extends TestCase { public void testSkewAndKurtosis() { ListUnivariateImpl u = - new ListUnivariateImpl(new ArrayList(), transformers); + new ListUnivariateImpl(new ArrayList(), transformers); u.addObject("12.5"); u.addObject(new Integer(12)); @@ -153,7 +153,7 @@ public final class MixedListUnivariateImplTest extends TestCase { } public void testProductAndGeometricMean() throws Exception { - ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList(),transformers); + ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList(),transformers); u.setWindowSize(10); u.addValue(1.0); diff --git a/src/test/org/apache/commons/math/stat/inference/OneWayAnovaTest.java b/src/test/org/apache/commons/math/stat/inference/OneWayAnovaTest.java index e71d8c1f4..5011e9f9b 100644 --- a/src/test/org/apache/commons/math/stat/inference/OneWayAnovaTest.java +++ b/src/test/org/apache/commons/math/stat/inference/OneWayAnovaTest.java @@ -33,7 +33,6 @@ public class OneWayAnovaTest extends TestCase { protected OneWayAnova testStatistic = new OneWayAnovaImpl(); - private char[] wrongArray = { 'a', 'b', 'c' }; private double[] emptyArray = {}; private double[] classA = @@ -58,7 +57,7 @@ public class OneWayAnovaTest extends TestCase { public void testAnovaFValue() throws Exception { // Target comparison values computed using R version 2.6.0 (Linux version) - List threeClasses = new ArrayList(); + List threeClasses = new ArrayList(); threeClasses.add(classA); threeClasses.add(classB); threeClasses.add(classC); @@ -66,25 +65,14 @@ public class OneWayAnovaTest extends TestCase { assertEquals("ANOVA F-value", 24.67361709460624, testStatistic.anovaFValue(threeClasses), 1E-12); - List twoClasses = new ArrayList(); + List twoClasses = new ArrayList(); twoClasses.add(classA); twoClasses.add(classB); assertEquals("ANOVA F-value", 0.0150579150579, testStatistic.anovaFValue(twoClasses), 1E-12); - // now try some input hashes which should fail - List wrongContents = new ArrayList(); - wrongContents.add(classC); - wrongContents.add(wrongArray); - try { - testStatistic.anovaFValue(wrongContents); - fail("non double[] hash value for key classX, IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - // expected - } - - List emptyContents = new ArrayList(); + List emptyContents = new ArrayList(); emptyContents.add(emptyArray); emptyContents.add(classC); try { @@ -94,7 +82,7 @@ public class OneWayAnovaTest extends TestCase { // expected } - List tooFew = new ArrayList(); + List tooFew = new ArrayList(); tooFew.add(classA); try { testStatistic.anovaFValue(tooFew); @@ -107,7 +95,7 @@ public class OneWayAnovaTest extends TestCase { public void testAnovaPValue() throws Exception { // Target comparison values computed using R version 2.6.0 (Linux version) - List threeClasses = new ArrayList(); + List threeClasses = new ArrayList(); threeClasses.add(classA); threeClasses.add(classB); threeClasses.add(classC); @@ -115,7 +103,7 @@ public class OneWayAnovaTest extends TestCase { assertEquals("ANOVA P-value", 6.959446E-06, testStatistic.anovaPValue(threeClasses), 1E-12); - List twoClasses = new ArrayList(); + List twoClasses = new ArrayList(); twoClasses.add(classA); twoClasses.add(classB); @@ -126,14 +114,14 @@ public class OneWayAnovaTest extends TestCase { public void testAnovaTest() throws Exception { // Target comparison values computed using R version 2.3.1 (Linux version) - List threeClasses = new ArrayList(); + List threeClasses = new ArrayList(); threeClasses.add(classA); threeClasses.add(classB); threeClasses.add(classC); assertTrue("ANOVA Test P<0.01", testStatistic.anovaTest(threeClasses, 0.01)); - List twoClasses = new ArrayList(); + List twoClasses = new ArrayList(); twoClasses.add(classA); twoClasses.add(classB); diff --git a/src/test/org/apache/commons/math/stat/inference/TestUtilsTest.java b/src/test/org/apache/commons/math/stat/inference/TestUtilsTest.java index 5fd0b70fd..cb2ebff1c 100644 --- a/src/test/org/apache/commons/math/stat/inference/TestUtilsTest.java +++ b/src/test/org/apache/commons/math/stat/inference/TestUtilsTest.java @@ -451,7 +451,7 @@ public class TestUtilsTest extends TestCase { private double[] classC = {110.0, 115.0, 111.0, 117.0, 128.0}; - private List classes = new ArrayList(); + private List classes = new ArrayList(); private OneWayAnova oneWayAnova = new OneWayAnovaImpl(); public void testOneWayAnovaUtils() throws Exception {