[ 
https://issues.apache.org/jira/browse/MATH-1522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17055537#comment-17055537
 ] 

Chen Tao edited comment on MATH-1522 at 3/10/20, 3:08 AM:
----------------------------------------------------------

{code:java}
With the new ClusterEvaluator interface in place (cf. MATH-1523), compilation 
fails if the generic type is removed from the class declaration (error caused 
by the ranking(ClusterEvaluator) adaptor method.
{code}

The generic type error can be fix like this(Please ignore the "extends 
ClusterRanking"):

https://github.com/chentao106/commons-math/commit/3465655177f8811a5078f42bee3e6f314d91bc1c


was (Author: chentao106):
{code:java}
With the new ClusterEvaluator interface in place (cf. MATH-1523), compilation 
fails if the generic type is removed from the class declaration (error caused 
by the ranking(ClusterEvaluator) adaptor method.
{code}

The generic type error can be fix like this:

https://github.com/chentao106/commons-math/commit/3465655177f8811a5078f42bee3e6f314d91bc1c

> The generic parameter of ClusterRanking can move onto method
> ------------------------------------------------------------
>
>                 Key: MATH-1522
>                 URL: https://issues.apache.org/jira/browse/MATH-1522
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Chen Tao
>            Priority: Major
>
> The generic parameter on class "ClusterRanking" is unnecessary, 
> it is redundancy when define a variable, and hard to reuse(it could be):
> {code:java}
> ClusterRanking<DoublePoint> evaluator = new SumOfClusterVariances<>();
> List<Cluster<DoublePoint>> clusters1 = ...
> evaluator.compute(clusters1); // It is OK.
> ...
> // It could be reused globally, but now trigger a compile error
> List<Cluster<MyClusterable>> clusters2 = ...
> evaluator.compute(clusters2); // Compile error
> {code}
> The generic parameter of ClusterRanking can be move onto method: 
> {code:java}
> @FunctionalInterface
> public interface ClusterRanking {
>     /**
>      * Computes the rank (higher is better).
>      *
>      * @param clusters Clusters to be evaluated.
>      * @return the rank of the provided {@code clusters}.
>      */
>     <T extends Clusterable> double compute(List<? extends Cluster<T>> 
> clusters);
> }
> {code}
> Then we can define a ClusterRanking easier and reuse it globally:
> {code:java}
> // The variable define is simple now.
> ClusterRanking evaluator = new SumOfClusterVariances();
> ...
> List<Cluster<DoublePoint>> clusters1 = ...
> double score1 = evaluator.compute(clusters1); // OK.
> ...
> // It can be reused globally now.
> List<Cluster<MyClusterable>> clusters2 = ...
> double score2 = evaluator.compute(clusters2); // OK.
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to