Coverage Report - com.sdmetrics.metrics.MetricProcedureProjection - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
MetricProcedureProjection
100%
25/25
93%
15/16
10
 
 1  124
 /*
 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.model.ModelElement;
 27  
 
 28  
 /**
 29  
  * Calculates a "projection" metric procedure.
 30  
  */
 31  49
 public class MetricProcedureProjection extends MetricProcedure {
 32  
 
 33  
         @Override
 34  
         public Number calculate(ModelElement element, Metric metric)
 35  
                         throws SDMetricsException {
 36  124
                 ProcedureAttributes attributes = metric.getAttributes();
 37  
 
 38  124
                 Variables vars = new Variables(element);
 39  248
                 Collection<ModelElement> rel = getRelationOrSet(element, attributes,
 40  124
                                 vars);
 41  123
                 if (rel == null || rel.isEmpty())
 42  51
                         return MetricTools.ZERO;
 43  
 
 44  
                 // Get the remainder of the projection attributes.
 45  72
                 FilterAttributeProcessor fap = getFilterAttributeProcessor(attributes);
 46  144
                 SummationHelper sum = new SummationHelper(getMetricsEngine(),
 47  72
                                 attributes);
 48  
 
 49  72
                 boolean recurse = attributes.getBooleanValue("recurse", false);
 50  72
                 boolean nesting = attributes.getBooleanValue("nesting", false);
 51  
 
 52  339
                 for (ModelElement projElem : fap.fullIteration(rel, vars)) {
 53  195
                         if (fap.isValid()) {
 54  98
                                 if (nesting) {
 55  2
                                         if (isCompatible(element, metric, projElem)) {
 56  2
                                                 sum.raiseTo(1 + ((Number) getMetricsEngine()
 57  1
                                                                 .getMetricValue(projElem, metric)).floatValue());
 58  1
                                                 continue;
 59  
                                         }
 60  
                                 }
 61  97
                                 sum.add(projElem, vars);
 62  
                         }
 63  
 
 64  
                         // recursively add the measure for compatible type elements in the
 65  
                         // projection
 66  194
                         if (recurse && isCompatible(element, metric, projElem))
 67  54
                                 sum.add(((Number) getMetricsEngine().getMetricValue(projElem,
 68  36
                                                 metric)).floatValue());
 69  
                 }
 70  
 
 71  72
                 return sum.getTotal();
 72  
         }
 73  
 }