Coverage Report - com.sdmetrics.metrics.SetProcedureSubelements - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
SetProcedureSubelements
100%
16/16
100%
6/6
3
 
 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  
 
 26  
 import com.sdmetrics.model.ModelElement;
 27  
 
 28  
 /**
 29  
  * Calculates the "subelements" set procedure.
 30  
  */
 31  1
 public class SetProcedureSubelements extends SetProcedure {
 32  
 
 33  
         @Override
 34  
         public Collection<?> calculate(ModelElement element, Set set)
 35  
                         throws SDMetricsException {
 36  2
                 ProcedureAttributes attributes = set.getAttributes();
 37  2
                 FilterAttributeProcessor fa = getFilterAttributeProcessor(attributes);
 38  4
                 SetSummationHelper summer = new SetSummationHelper(getMetricsEngine(),
 39  2
                                 set, "set");
 40  2
                 Variables vars = new Variables(element);
 41  2
                 gatherSubelementSet(element, fa, summer, vars);
 42  2
                 return summer.getResultSet();
 43  
         }
 44  
 
 45  
         /*
 46  
          * Recursively collect the owned elements that satisfy the filter
 47  
          * attributes.
 48  
          */
 49  
         private void gatherSubelementSet(ModelElement element,
 50  
                         FilterAttributeProcessor fap, SetSummationHelper summer,
 51  
                         Variables vars) throws SDMetricsException {
 52  
 
 53  6
                 Collection<ModelElement> ownedElements = element.getOwnedElements();
 54  6
                 if (ownedElements == null)
 55  4
                         return;
 56  8
                 for (ModelElement child : fap.fullIteration(ownedElements, vars)) {
 57  4
                         if (fap.isValid())
 58  3
                                 summer.add(child, vars);
 59  
 
 60  4
                         gatherSubelementSet(child, fap, summer, vars);
 61  
                 }
 62  2
         }
 63  
 }