Coverage Report - com.sdmetrics.metrics.MetricProcedureCount - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
MetricProcedureCount
100%
21/21
100%
6/6
6
 
 1  6
 /*
 2  
  * SDMetrics Open Core for UML design measurement
 3  
  * Copyright (c) Juergen Wuest
 4  
  * To contact the author, see <http://www.sdmetrics.com/Contact.html>.
 5  
  * 
 6  
  * This file is part of the SDMetrics Open Core.
 7  
  * 
 8  
  * SDMetrics Open Core is free software: you can redistribute it and/or modify
 9  
  * it under the terms of the GNU Affero General Public License as
 10  
  * published by the Free Software Foundation, either version 3 of the
 11  
  * License, or (at your option) any later version.
 12  
     
 13  
  * SDMetrics Open Core is distributed in the hope that it will be useful,
 14  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  
  * GNU Affero General Public License for more details.
 17  
  *
 18  
  * You should have received a copy of the GNU Affero General Public License
 19  
  * along with SDMetrics Open Core.  If not, see <http://www.gnu.org/licenses/>.
 20  
  *
 21  
  */
 22  
 package com.sdmetrics.metrics;
 23  
 
 24  
 import java.util.Collection;
 25  
 
 26  
 import com.sdmetrics.math.ExpressionNode;
 27  
 import com.sdmetrics.model.ModelElement;
 28  
 
 29  
 /**
 30  
  * Calculates the deprecated "count" metric procedure.
 31  
  * <p>
 32  
  * Counts are now just a special case of projections, using the principal
 33  
  * element in the condition expression.
 34  
  */
 35  2
 public class MetricProcedureCount extends MetricProcedure {
 36  
 
 37  
         @Override
 38  
         public Integer calculate(ModelElement element, Metric metric)
 39  
                         throws SDMetricsException {
 40  6
                 ProcedureAttributes attributes = metric.getAttributes();
 41  6
                 Variables vars = new Variables(element);
 42  11
                 Object term = evalExpression(element,
 43  6
                                 attributes.getRequiredExpression("term"), vars);
 44  5
                 vars.setVariable("term", term);
 45  10
                 Collection<ModelElement> set = evalElementSetExpression(element,
 46  5
                                 attributes.getRequiredExpression("set"), vars);
 47  5
                 if (set.isEmpty())
 48  2
                         return MetricTools.ZERO;
 49  
 
 50  3
                 FilterAttributeProcessor fap = getFilterAttributeProcessor(attributes);
 51  3
                 ExpressionNode relset = attributes.getExpression("relset");
 52  3
                 if (relset == null)
 53  1
                         return Integer.valueOf(MetricTools.elementCount(set, term));
 54  2
                 int result = 0;
 55  2
                 vars.setVariable("set", set);
 56  
 
 57  
                 // Iterate elements in the result set
 58  5
                 for (ModelElement elem : fap.validIteration(set, vars)) {
 59  1
                         Collection<?> c = evalSetExpression(elem, relset, vars);
 60  1
                         result += MetricTools.elementCount(c, term);
 61  
                 }
 62  2
                 return Integer.valueOf(result);
 63  
         }
 64  
 }