public class MetricsEngine
extends java.lang.Object
getMetricValue()
) or set (getSet()
)
for a particular model element.
The engine uses a "lazy calculation" strategy: if a set or metric for a model element is requested for the first time, the set or metric is calculated, stored in a cache, and returned to the caller. On subsequent requests for the same set or metric, the value is simply retrieved from the cache.
Constructor and Description |
---|
MetricsEngine(MetricStore metrics,
Model model)
Initializes a new metrics engine.
|
Modifier and Type | Method and Description |
---|---|
MetaModel |
getMetaModel()
Retrieves the metamodel on which this metrics engine is based.
|
MetricStore |
getMetricStore()
Retrieves the metric definitions used by this metrics engine.
|
java.lang.Object |
getMetricValue(ModelElement element,
Metric metric)
Retrieves the value of a metric for a model element.
|
Model |
getModel()
Retrieves the model on which this metrics engine operates.
|
java.util.Collection<?> |
getSet(ModelElement element,
Set set)
Retrieves the contents of a set for a model element.
|
public MetricsEngine(MetricStore metrics, Model model)
metrics
- The definitions of the sets and metrics to calculate.model
- The model on which to operate. Must use the same metamodel
as the metric definitions.public MetaModel getMetaModel()
public MetricStore getMetricStore()
public Model getModel()
public java.lang.Object getMetricValue(ModelElement element, Metric metric) throws SDMetricsException
Returns the cached value if the metric has been calculated before for the element. Otherwise, the value is calculated and cached.
element
- Model element to retrieve the metric value for.metric
- The metric to retrieve. Must be taken from the metric store
of this engine.SDMetricsException
- An error occurred during the metric
calculation.public java.util.Collection<?> getSet(ModelElement element, Set set) throws SDMetricsException
Returns the cached set if the set has been calculated before for the element. Otherwise, the set is calculated and cached.
Sets typically contain either model elements, numbers (mix of instances of Integer and Float), or strings.
element
- Model element to retrieve the set for.set
- The set to retrieve. Must be taken from the metric store of
this engine.SDMetricsException
- An error occurred during the metric
calculation.