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  123
 /*
 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  123
                 ProcedureAttributes attributes = metric.getAttributes();
 37  
 
 38  123
                 Variables vars = new Variables(element);
 39  246
                 Collection<ModelElement> rel = getRelationOrSet(element, attributes,
 40  123
                                 vars);
 41  122
                 if (rel == null || rel.isEmpty()) {
 42  50
                         return MetricTools.ZERO;
 43  
                 }
 44  
 
 45  
                 // Get the remainder of the projection attributes.
 46  72
                 FilterAttributeProcessor fap = getFilterAttributeProcessor(attributes);
 47  144
                 SummationHelper sum = new SummationHelper(getMetricsEngine(),
 48  72
                                 attributes);
 49  
 
 50  72
                 boolean recurse = attributes.getBooleanValue("recurse", false);
 51  72
                 boolean nesting = attributes.getBooleanValue("nesting", false);
 52  
 
 53  339
                 for (ModelElement projElem : fap.fullIteration(rel, vars)) {
 54  195
                         if (fap.isValid()) {
 55  98
                                 if (nesting) {
 56  2
                                         if (isCompatible(element, metric, projElem)) {
 57  2
                                                 sum.raiseTo(1 + ((Number) getMetricsEngine()
 58  1
                                                                 .getMetricValue(projElem, metric)).floatValue());
 59  1
                                                 continue;
 60  
                                         }
 61  
                                 }
 62  97
                                 sum.add(projElem, vars);
 63  
                         }
 64  
 
 65  
                         // recursively add the measure for compatible type elements in the
 66  
                         // projection
 67  194
                         if (recurse && isCompatible(element, metric, projElem)) {
 68  54
                                 sum.add(((Number) getMetricsEngine().getMetricValue(projElem,
 69  36
                                                 metric)).floatValue());
 70  
                         }
 71  
                 }
 72  
 
 73  72
                 return sum.getTotal();
 74  
         }
 75  
 }