Contents > 8 Defining Custom Design Metrics and Rules > 8.1 Definition of Metrics > 8.1.5 Count

8.1.5 Count

The count procedure iterates over a set of sets, counting how often an element or value occurs in the sets. In the following example, we assume that
<metric name="Redefining" domain="attribute" internal="true">
  <description>The number of ancestor classes having an attribute 
               with the same name as this one.</description>
  <count term="name" set="context.AncSet" target="class" 
         relset="AttrNameSet" />
</metric>
Evaluation of the count procedure is as follows:
  1. First, the term expression is evaluated for the model element.
    In our example, this yields the name of the attribute.
  2. Next, the set expression is evaluated for the model element. This must be an element set. Each element in the set can be subjected to the usual filters (target, element, eltype, condition, targetcondition, scope). We denote the resulting set as S.
    In our example, S is the set of ancestor classes of the owner of the attribute.
  3. For each element in S, evaluate the relset expression. Count how often the result of the term expression from step 1 occurs in the relset.
    In our example, relset yields the set of attribute names of the ancestor classes. We count how often the attribute's name occurs in each ancestor class.
  4. Add up the number of occurrences in step 3. This is the result of the metric.
    We have counted the number of attributes in ancestor classes having the same name as the current attribute.
For the count procedure, attributes term, set, and relset are required. The filter attributes (target, element, eltype, condition, targetcondition, and scope) are, as usual, optional, and only applied to elements of the set expression.