[
https://issues.apache.org/jira/browse/MATH-1522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17056124#comment-17056124
]
Chen Tao edited comment on MATH-1522 at 3/10/20, 4:53 PM:
----------------------------------------------------------
{quote}I only see that we'd loose type-checking.{quote}
Why there should be a generic parameter type-checking?
IMHO the type-checking of below code is robust enough:
{code:java}
double compute(List<? extends Cluster<? extends Clusterable>> clusters);
{code}
A generic parameter only make the declaration code longer, but cannot avoid any
bug.
{code:java}
public class SumOfClusterVariancesTest {
// Why the evaluator should be declared with a <DoublePoint>
// If there are 2 types of test data, I have to create 2 evaluator
private ClusterEvaluator<DoublePoint> evaluator;
@Before
public void setUp() {
evaluator = new SumOfClusterVariances<>(new EuclideanDistance());
}
{code}
As far as reuse, it is a potential benefit, imagine if we have a Ranking
Application, why should we create new instance of ClusterRanking for every kind
of data?
Or if we have a NamedDoublePoint extends DoublePoint, why should the
ClusterRanking<DoublePoint>.compute cannot be applied on
List<Cluster<NamedDoublePoint>>?
was (Author: chentao106):
{quote}I only see that we'd loose type-checking.{quote}
Why there should be a generic parameter type-checking?
IMHO the type-checking of below code is robust enough:
{code:java}
double compute(List<? extends Cluster<? extends Clusterable>> clusters);
{code}
A generic parameter only make the declaration code longger, but cannot avoid
any bug.
{code:java}
public class SumOfClusterVariancesTest {
// Why the evaluator should be declared with a <DoublePoint>
// If there are 2 types of test data, I have to create 2 evaluator
private ClusterEvaluator<DoublePoint> evaluator;
@Before
public void setUp() {
evaluator = new SumOfClusterVariances<>(new EuclideanDistance());
}
{code}
As far as reuse, it is a potential benefit, imagine if we have a Ranking
Application, why should we create new instance of ClusterRanking for every kind
of data?
Or if we have a NamedDoublePoint extends DoublePoint, why should the
ClusterRanking<DoublePoint>.compute cannot be applied on
List<Cluster<NamedDoublePoint>>?
> 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: Minor
> Time Spent: 10m
> Remaining Estimate: 0h
>
> 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)