commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <>
Subject [jira] [Updated] (MATH-1205) AbstractStorelessUnivariateStatistic should not extend AbstractUnivariateStatistic
Date Sun, 12 Apr 2015 18:08:12 GMT


Thomas Neidhart updated MATH-1205:
    Attachment: MATH-1205.patch

Attached a patch with the following changes:

 * added class AbstractCachingUnivariateStatistic which extends AbstractUnivariateStatistic
and contains the storedData field and corresponding methods
 * Percentile extends now AbstractCachingUnivariateStatistic
 * fix AbstractStorelessUnivariateStatistic#evaluate(double[], int, int) method to be consistent
with the other implementations: it does not alter the internal state anymore, but instead
creates first a copy of the current statistic and the calls clear() and incrementAll() on
the copy instead.
 * fix AbstractStorelessUnivariateStatistic#equals(Object): the equality check will only succeed
for statistics of the same class. This might be useful, although I am not 100% sure, we might
also just remove the default equals/hashCode.
 * fix Variance#evaluate(...) methods: they altered the internal state by calling clear(),
although the javadoc stated the opposite.

If preferred, I can also make separate issues for the bullets, currently the changes.xml contains
separate entries for all of them, but without a ticket number.

btw. the storedData fields and methods have been introduced in MATH-417 to improve the performance
of the Percentile class, but have not been used for any other class.

> AbstractStorelessUnivariateStatistic should not extend AbstractUnivariateStatistic
> ----------------------------------------------------------------------------------
>                 Key: MATH-1205
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.4.1
>            Reporter: Thomas Neidhart
>         Attachments: MATH-1205.patch
> For a storeless statistic it is wrong to extend AbstractUnivariateStatistic as various
fields and methods are inherited that do not make sense in case of a storeless statistic.
> This means a user can accidentially use a storeless statistic in a wrong way:
> {code}
>         Mean mean = new Mean();
>         mean.increment(1);
>         mean.increment(2);
>         mean.setData(new double[] { 1, 2, 3});
>         System.out.println(mean.getResult());
>         System.out.println(mean.evaluate());
> {code}
> will output
> {noformat}
> 1.5
> 2.0
> {noformat}

This message was sent by Atlassian JIRA

View raw message