Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1522

The generic parameter of ClusterRanking can move onto method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Done
    • None
    • 4.0
    • None
    • None

    Description

      The generic parameter on class "ClusterRanking" is unnecessary,
      it is redundancy when define a variable, and hard to reuse(it could be):

      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
      

      The generic parameter of ClusterRanking can be move onto method:

      @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);
      }
      

      Then we can define a ClusterRanking easier and reuse it globally:

      // 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.
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chentao106 Chen Tao
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m