Class MetricsUtil

java.lang.Object
net.sourceforge.pmd.lang.metrics.MetricsUtil

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

    • supportsAll

      public static boolean supportsAll(Node node, Metric<?,?>... metrics)
    • computeStatistics

      public static <O extends Node> DoubleSummaryStatistics computeStatistics(Metric<? super O,?> key, Iterable<? extends O> ops)
      Computes statistics for the results of a metric over a sequence of nodes.
      Parameters:
      key - The metric to compute
      ops - List of nodes for which to compute the metric
      Returns:
      Statistics for the value of the metric over all the nodes
    • computeStatistics

      public static <O extends Node> DoubleSummaryStatistics computeStatistics(Metric<? super O,?> key, Iterable<? extends O> ops, MetricOptions options)
      Computes statistics for the results of a metric over a sequence of nodes.
      Parameters:
      key - The metric to compute
      ops - List of nodes for which to compute the metric
      options - The options of the metric
      Returns:
      Statistics for the value of the metric over all the nodes
    • computeMetric

      public static <N extends Node, R extends Number> R computeMetric(Metric<? super N,R> 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
      Throws:
      IllegalArgumentException - If the metric does not support the given node
    • computeMetric

      public static <N extends Node, R extends Number> R computeMetric(Metric<? super N,R> 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, R extends Number> R computeMetric(Metric<? super N,R> 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