Coverage Report - com.sdmetrics.metrics.MetricProcedureCompound - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
MetricProcedureCompound
100%
20/20
92%
13/14
9
 
 1  
 /*
 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 com.sdmetrics.math.ExpressionNode;
 25  
 import com.sdmetrics.model.ModelElement;
 26  
 
 27  
 /**
 28  
  * Calculates a "compound" metric procedure.
 29  
  */
 30  13
 public class MetricProcedureCompound extends MetricProcedure {
 31  
 
 32  
         @Override
 33  
         public Object calculate(ModelElement element, Metric metric)
 34  
                         throws SDMetricsException {
 35  19
                 ProcedureAttributes attributes = metric.getAttributes();
 36  19
                 String expressionToUse = "term";
 37  19
                 Integer defaultValue = MetricTools.ONE;
 38  
 
 39  19
                 ExpressionNode condition = attributes.getExpression("condition");
 40  19
                 if (condition != null) {
 41  6
                         if (!evalBooleanExpression(element, condition, null)) {
 42  3
                                 expressionToUse = "alt";
 43  3
                                 defaultValue = MetricTools.ZERO;
 44  
                         }
 45  
                 }
 46  
 
 47  19
                 ExpressionNode expr = attributes.getExpression(expressionToUse);
 48  19
                 if (expr == null)
 49  4
                         return defaultValue;
 50  
 
 51  15
                 Object result = evalExpression(element, expr, null);
 52  15
                 if (result instanceof Float) {
 53  2
                         Float f = (Float) result;
 54  2
                         if (f.isNaN() || f.isInfinite()) {
 55  2
                                 ExpressionNode fallBack = attributes.getExpression("fallback");
 56  2
                                 if (fallBack != null)
 57  1
                                         result = evalExpression(element, fallBack, null);
 58  
                         }
 59  
                 }
 60  15
                 return result;
 61  
         }
 62  
 }