www.sdmetrics.com

com.sdmetrics.metrics
Class MetricsEngine

java.lang.Object
  extended by com.sdmetrics.metrics.MetricsEngine

public class MetricsEngine
extends java.lang.Object

Calculates metrics and sets. The metrics engine offers methods to retrieve a metric value ( 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 Summary
MetricsEngine(MetricStore metrics, Model model)
          Initializes a new metrics engine.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetricsEngine

public MetricsEngine(MetricStore metrics,
                     Model model)
Initializes a new metrics engine.

Parameters:
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.
Method Detail

getMetaModel

public MetaModel getMetaModel()
Retrieves the metamodel on which this metrics engine is based.

Returns:
Metamodel of this engine.

getMetricStore

public MetricStore getMetricStore()
Retrieves the metric definitions used by this metrics engine.

Returns:
Metric definitions of this engine.

getModel

public Model getModel()
Retrieves the model on which this metrics engine operates.

Returns:
Model of this engine.

getMetricValue

public java.lang.Object getMetricValue(ModelElement element,
                                       Metric metric)
                                throws SDMetricsException
Retrieves the value of a metric for a model element.

Returns the cached value if the metric has been calculated before for the element. Otherwise, the value is calculated and cached.

Parameters:
element - Model element to retrieve the metric value for.
metric - The metric to retrieve. Must be taken from the metric store of this engine.
Returns:
Value of the metric for the specified element.
Throws:
SDMetricsException - An error occurred during the metric calculation.

getSet

public java.util.Collection<?> getSet(ModelElement element,
                                      Set set)
                               throws SDMetricsException
Retrieves the contents of a set for a model element.

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.

Parameters:
element - Model element to retrieve the set for.
set - The set to retrieve. Must be taken from the metric store of this engine.
Returns:
Contents of the set for the specified element.
Throws:
SDMetricsException - An error occurred during the metric calculation.

www.sdmetrics.com