Coverage Report - com.sdmetrics.metrics.MetricProcedureFilterValue - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
MetricProcedureFilterValue
100%
15/15
87%
7/8
8
 
 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 java.util.Collection;
 25  
 import java.util.Iterator;
 26  
 
 27  
 import com.sdmetrics.math.ExpressionNode;
 28  
 import com.sdmetrics.model.ModelElement;
 29  
 
 30  
 /**
 31  
  * Calculates a "filtervalue" metric procedure.
 32  
  */
 33  1
 public class MetricProcedureFilterValue extends MetricProcedure {
 34  
 
 35  
         @Override
 36  
         public Object calculate(ModelElement element, Metric m)
 37  
                         throws SDMetricsException {
 38  4
                 ProcedureAttributes attributes = m.getAttributes();
 39  
 
 40  4
                 Variables vars = new Variables(element);
 41  8
                 Collection<ModelElement> set = getRelationOrSet(element, attributes,
 42  4
                                 vars);
 43  4
                 if (set == null || set.isEmpty())
 44  1
                         return "";
 45  
 
 46  3
                 FilterAttributeProcessor fa = getFilterAttributeProcessor(attributes);
 47  3
                 ExpressionNode valueExp = attributes.getExpression("value");
 48  
 
 49  
                 // Return the first element produced by the filter attributes
 50  3
                 Iterator<ModelElement> it = fa.validIteration(set, vars).iterator();
 51  3
                 if (it.hasNext()) {
 52  2
                         if (valueExp != null) {
 53  1
                                 return evalExpression(it.next(), valueExp, vars);
 54  
                         }
 55  1
                         return it.next();
 56  
                 }
 57  
 
 58  1
                 return "";
 59  
         }
 60  
 }