UnivariateStatistic classes should be Serializable

since they are used as fields of the Serializable DescriptiveStatistics class

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@611489 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2008-01-12 21:35:10 +00:00
parent 9ce7a64492
commit c76f6fdc58
4 changed files with 34 additions and 21 deletions

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.math.stat.descriptive;
import java.io.Serializable;
/**
* Base evaluation interface implemented by all statistics.
* <p>
@ -25,7 +27,7 @@ package org.apache.commons.math.stat.descriptive;
*
* @version $Revision$ $Date$
*/
public interface UnivariateStatistic {
public interface UnivariateStatistic extends Serializable {
/**
* Returns the result of evaluating the statistic over the input array.

View File

@ -81,7 +81,9 @@ public final class DescriptiveStatisticsTest extends DescriptiveStatisticsAbstra
/**
* A new way to compute the mean
*/
class deepMean implements UnivariateStatistic {
static class deepMean implements UnivariateStatistic {
private static final long serialVersionUID = 9108665370122541953L;
public double evaluate(double[] values, int begin, int length) {
return 42;
}
@ -94,8 +96,9 @@ public final class DescriptiveStatisticsTest extends DescriptiveStatisticsAbstra
/**
* Test percentile implementation - wraps a Percentile
*/
class goodPercentile implements UnivariateStatistic {
Percentile percentile = new Percentile();
static class goodPercentile implements UnivariateStatistic {
private static final long serialVersionUID = 801005145532790795L;
private Percentile percentile = new Percentile();
public void setQuantile(double quantile) {
percentile.setQuantile(quantile);
}
@ -103,7 +106,7 @@ public final class DescriptiveStatisticsTest extends DescriptiveStatisticsAbstra
return percentile.evaluate(values, begin, length);
}
public double evaluate(double[] values) {
return evaluate(values);
return percentile.evaluate(values);
}
}
@ -111,7 +114,7 @@ public final class DescriptiveStatisticsTest extends DescriptiveStatisticsAbstra
* Test percentile subclass - another "new math" impl
* Always returns currently set quantile
*/
class subPercentile extends Percentile {
static class subPercentile extends Percentile {
public double evaluate(double[] values, int begin, int length) {
return getQuantile();
}
@ -124,13 +127,14 @@ public final class DescriptiveStatisticsTest extends DescriptiveStatisticsAbstra
/**
* "Bad" test percentile implementation - no setQuantile
*/
class badPercentile implements UnivariateStatistic {
Percentile percentile = new Percentile();
static class badPercentile implements UnivariateStatistic {
private static final long serialVersionUID = -707437653388052183L;
private Percentile percentile = new Percentile();
public double evaluate(double[] values, int begin, int length) {
return percentile.evaluate(values, begin, length);
}
public double evaluate(double[] values) {
return evaluate(values);
return percentile.evaluate(values);
}
}
}

View File

@ -52,18 +52,9 @@ public final class MixedListUnivariateImplTest extends TestCase {
super(name);
transformers = new TransformerMap();
transformers.putTransformer(Foo.class, new NumberTransformer() {
public double transform(Object o) {
return Double.parseDouble(((Foo) o).heresFoo());
}
});
transformers.putTransformer(Foo.class, new FooTransformer());
transformers.putTransformer(Bar.class, new NumberTransformer() {
public double transform(Object o) {
return Double.parseDouble(((Bar) o).heresBar());
}
});
transformers.putTransformer(Bar.class, new BarTransformer());
}
@ -196,9 +187,24 @@ public final class MixedListUnivariateImplTest extends TestCase {
}
}
public static final class FooTransformer implements NumberTransformer {
private static final long serialVersionUID = -4252248129291326127L;
public double transform(Object o) {
return Double.parseDouble(((Foo) o).heresFoo());
}
}
public static final class Bar {
public String heresBar() {
return "12.0";
}
}
public static final class BarTransformer implements NumberTransformer {
private static final long serialVersionUID = -1768345377764262043L;
public double transform(Object o) {
return Double.parseDouble(((Bar) o).heresBar());
}
}
}

View File

@ -75,7 +75,8 @@ public final class SummaryStatisticsTest extends SummaryStatisticsAbstractTest {
* Bogus mean implementation to test setter injection.
* Returns the sum instead of the mean.
*/
class sumMean implements StorelessUnivariateStatistic {
static class sumMean implements StorelessUnivariateStatistic {
private static final long serialVersionUID = 6492471391340853423L;
private double sum = 0;
private long n = 0;
public double evaluate(double[] values, int begin, int length) {