commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hugo Ferrira (JIRA)" <>
Subject [jira] [Commented] (MATH-1046) math3.stat.Frequency: Allow Null keys (comparable objects)
Date Thu, 24 Oct 2013 15:42:01 GMT


Hugo Ferrira commented on MATH-1046:

> Thanks for sharing your solution, I think we should update the class Frequency to allow
> plain Objects as input if a Comparator is specified that can be used to compare them.

I suppose one would need to add a new member/parameter Comparator. 
I think that is doable.  Such a Comparator could deal with the null issue. 

> This would be more flexible and allow you to use, e.g. the guava Optional wrapper.

I have no experienced in its use. I just used it as a basis for the solution I presented.

Please note that the JDK8 will also have such a class. However that class does not
ensure that the generic parameter is a comparable nor does it seem to have a compareTo.
To top it off, it is a final class which may make it nonviable to use in this context (dealing
with nulls).

> There is also a feature request to provide a generic version of Frequency.

I don't think this will solve the "null" issue unless you stipulate a class/interface
to handle this issue (make it an Optional<T>?) 

> math3.stat.Frequency: Allow Null keys (comparable objects)
> ----------------------------------------------------------
>                 Key: MATH-1046
>                 URL:
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.2
>         Environment: Linux, JDK 7
>            Reporter: Hugo Ferrira
>            Priority: Trivial
>              Labels: features
>             Fix For: 3.2
> The class {{math3.stat.Frequency}} uses a {{TreeMap}} which does not allow
> for the use of null keys ({{public void addValue(Comparable<?> v)}} with {{v =
null}}). I am analyzing data (matrix) whose values may 
> contain nulls. I need to get the counts for elements in a given column.
> This includes knowing how many are null. This information will be used
> for data cleaning/pre-processing.
>  A simple change would be substituting {{TreeMap}} with {{java.util.HashMap<K,V>}}.

This message was sent by Atlassian JIRA

View raw message