Prev - Next - Down | SDMetrics - the UML design measurement tool |
packacke com.acme; import java.util.Collection; import com.sdmetrics.math.ExpressionNode; import com.sdmetrics.metrics.*; import com.sdmetrics.model.ModelElement; 01 public class SetProcedureCondition extends SetProcedure { @Override 02 public Collection<?> calculate(ModelElement element, Set set) throws SDMetricsException { 03 ProcedureAttributes attributes = set.getAttributes(); 04 ExpressionNode condexp = attributes.getRequiredExpression("condition"); 05 ExpressionNode setExpr = attributes.getRequiredExpression("set"); 06 ExpressionNode altExpr = attributes.getRequiredExpression("alt"); 07 Variables vars = new Variables(element); 08 boolean condition = evalBooleanExpression(element, condexp, vars); 09 if (condition) return evalSetExpression(element, setExpr, vars); 10 return evalSetExpression(element, altExpr, vars); } }Some of the metrics engine API used here we already know from (Section 9.1.2 "Implementation of the Metric Procedure"), so we focus the discussion of this implementation on new features:
For further examples on how to programmatically manipulate regular and multisets, see Section 9.6 "Set Functions".
To use our new set procedure, we register it with the metrics engine as follows:
<setprocedure name="conditionalset" class="com.acme.SetProcedureCondition" />Again, we deploy the class file of the procedure class in the "bin" folder of our SDMetrics installation (path com/acme/SetProcedureCondition.class). After that, we can write set definitions using the new set procedure. For example:
<set name="InterestingObjects" domain="class"> <conditionalset condition="'DataStore' in StereoTypeNames" set="AttributeSet" alt="OperationSet" /> </set>Note: every set procedure can also be used to define relation matrices (cf. Section 8.4 "Definition of Relation Matrices"). This includes custom set procedures you defined yourself.
Prev | Up | Next |
Section 9.1.3 "Using the New Metric Procedure" | Contents | Section 9.3 "Rule Procedures" |