metrics: move `sum` up to interface `Metric`
[nit.git] / src / metrics / metrics_base.nit
index c51e656..080ceec 100644 (file)
@@ -197,6 +197,9 @@ interface Metric
                end
        end
 
+       # The sum of all the values.
+       fun sum: VAL is abstract
+
        # The values standard derivation
        fun std_dev: Float is abstract
 
@@ -211,6 +214,11 @@ interface Metric
 
        # The set of element above the threshold
        fun above_threshold: Set[ELM] is abstract
+
+       # Sort the metric keys by values
+       fun sort: Array[ELM] do
+               return values.keys_sorted_by_values(default_reverse_comparator)
+       end
 end
 
 # A Metric that collects integer data
@@ -227,7 +235,7 @@ class IntMetric
 
        redef fun clear do values_cache.clear
 
-       fun sum: Int do return values_cache.sum
+       redef fun sum do return values_cache.sum
 
        redef fun max do
                assert not values_cache.is_empty
@@ -276,7 +284,8 @@ class FloatMetric
 
        redef fun clear do values_cache.clear
 
-       fun sum: Float do
+
+       redef fun sum do
                var sum = 0.0
                for v in values.values do sum += v
                return sum
@@ -338,7 +347,6 @@ class FloatMetric
                        print "{"\t" * indent}  sum: {sum}"
                end
        end
-
 end
 
 # A MetricSet is a metric holder