Class MetricsUtil


  • public final class MetricsUtil
    extends Object
    Utilities to use Metric instances.
    • Method Detail

      • supportsAll

        public static <N extends Node> boolean supportsAll​(N node,
                                                           MetricKey<N>... metrics)
      • computeAggregate

        public static <O extends Node> double computeAggregate​(MetricKey<? super O> key,
                                                               Iterable<? extends O> ops,
                                                               MetricOptions options,
                                                               ResultOption resultOption)
        Computes an aggregate result for a metric, identified with a ResultOption.
        Parameters:
        key - The metric to compute
        ops - List of nodes for which to aggregate the metric
        options - The options of the metric
        resultOption - The type of aggregation to perform
        Returns:
        The result of the computation, or Double.NaN if it couldn't be performed
      • computeMetric

        public static <N extends Node> double computeMetric​(MetricKey<? super N> key,
                                                            N node)
        Computes a metric identified by its code on a node, with the default options.
        Parameters:
        key - The key identifying the metric to be computed
        node - The node on which to compute the metric
        Returns:
        The value of the metric, or Double.NaN if the value couldn't be computed
      • computeMetricOrNaN

        @Deprecated
        public static <N extends Node> double computeMetricOrNaN​(MetricKey<? super N> key,
                                                                 N node,
                                                                 MetricOptions options)
        Deprecated.
        This is provided for compatibility with pre 6.21.0 behavior. Users of a metric should always check beforehand if the metric supports the argument.
        Computes a metric identified by its code on a node, possibly selecting a variant with the options parameter.
        Parameters:
        key - The key identifying the metric to be computed
        node - The node on which to compute the metric
        options - The options of the metric
        Returns:
        The value of the metric, or Double.NaN if the value couldn't be computed
      • computeMetric

        public static <N extends Node> double computeMetric​(MetricKey<? super N> key,
                                                            N node,
                                                            MetricOptions options)
        Computes a metric identified by its code on a node, possibly selecting a variant with the options parameter.

        Note that contrary to the previous behaviour, this method throws an exception if the metric does not support the node.

        Parameters:
        key - The key identifying the metric to be computed
        node - The node on which to compute the metric
        options - The options of the metric
        Returns:
        The value of the metric
        Throws:
        IllegalArgumentException - If the metric does not support the given node
      • computeMetric

        public static <N extends Node> double computeMetric​(MetricKey<? super N> key,
                                                            N node,
                                                            MetricOptions options,
                                                            boolean forceRecompute)
        Computes a metric identified by its code on a node, possibly selecting a variant with the options parameter.

        Note that contrary to the previous behaviour, this method throws an exception if the metric does not support the node.

        Parameters:
        key - The key identifying the metric to be computed
        node - The node on which to compute the metric
        options - The options of the metric
        forceRecompute - Force recomputation of the result
        Returns:
        The value of the metric
        Throws:
        IllegalArgumentException - If the metric does not support the given node