Package net.sourceforge.pmd.lang.metrics
Class MetricsUtil
java.lang.Object
net.sourceforge.pmd.lang.metrics.MetricsUtil
Utilities to use
Metric instances.-
Method Summary
Modifier and TypeMethodDescriptioncomputeMetric(Metric<? super N, R> key, N node) Computes a metric identified by its code on a node, with the default options.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 theoptionsparameter.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 theoptionsparameter.static <O extends Node>
DoubleSummaryStatisticscomputeStatistics(Metric<? super O, ?> key, Iterable<? extends O> ops) Computes statistics for the results of a metric over a sequence of nodes.static <O extends Node>
DoubleSummaryStatisticscomputeStatistics(Metric<? super O, ?> key, Iterable<? extends O> ops, MetricOptions options) Computes statistics for the results of a metric over a sequence of nodes.static booleansupportsAll(Node node, Metric<?, ?>... metrics)
-
Method Details
-
supportsAll
-
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 computeops- 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 computeops- List of nodes for which to compute the metricoptions- The options of the metric- Returns:
- Statistics for the value of the metric over all the nodes
-
computeMetric
Computes a metric identified by its code on a node, with the default options.- Parameters:
key- The key identifying the metric to be computednode- The node on which to compute the metric- Returns:
- The value of the metric, or
Double.NaNif 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 theoptionsparameter.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 computednode- The node on which to compute the metricoptions- 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 theoptionsparameter.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 computednode- The node on which to compute the metricoptions- The options of the metricforceRecompute- Force recomputation of the result- Returns:
- The value of the metric
- Throws:
IllegalArgumentException- If the metric does not support the given node
-