Coverage Report - com.sdmetrics.metrics.ElementGraph - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
ElementGraph
100%
10/10
N/A
1
 
 1  76
 /*
 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.math.ExpressionNode;
 27  
 import com.sdmetrics.model.ModelElement;
 28  
 
 29  
 /**
 30  
  * A graph consisting of model elements.
 31  
  * <p>
 32  
  * The edges of the graph are defined by a set expression, which yields, for a
 33  
  * model element <code>e</code>, the set of neighbor elements to which there is
 34  
  * an outgoing edge from <code>e</code>.
 35  
  */
 36  
 public class ElementGraph implements
 37  
                 StronglyConnectedComponents.Graph<ModelElement> {
 38  
 
 39  
         /** Metrics engine to calculate the neighbors of a model element. */
 40  
         private final MetricsEngine me;
 41  
         /**
 42  
          * The model elements that constitute the nodes of the graph.
 43  
          */
 44  
         private final Collection<ModelElement> nodes;
 45  
         /** Set expression that defines the neighbors of a mode element. */
 46  
         private final ExpressionNode neighborExpression;
 47  
         /** Variables for the calculation of the neighbor nodes. */
 48  
         private final Variables variables;
 49  
 
 50  
         /**
 51  
          * @param engine Metrics engine to calculate the neighbors of a model
 52  
          *        element.
 53  
          * @param nodes The model elements that constitute the nodes of the graph.
 54  
          * @param neighbors Set expression that yields the set of neighbors of a
 55  
          *        model element.
 56  
          * @param vars Variables for the expression evaluation
 57  
          */
 58  6
         public ElementGraph(MetricsEngine engine, Collection<ModelElement> nodes,
 59  
                         ExpressionNode neighbors, Variables vars) {
 60  6
                 this.me = engine;
 61  6
                 this.neighborExpression = neighbors;
 62  6
                 this.nodes = nodes;
 63  6
                 this.variables = vars;
 64  6
         }
 65  
 
 66  
         @Override
 67  
         public Collection<ModelElement> getNodes() {
 68  6
                 return nodes;
 69  
         }
 70  
 
 71  
         @SuppressWarnings("unchecked")
 72  
         @Override
 73  
         public Collection<ModelElement> getNeighbors(ModelElement element)
 74  
                         throws SDMetricsException {
 75  152
                 return (Collection<ModelElement>) me.evalSetExpression(element,
 76  76
                                 neighborExpression, variables);
 77  
         }
 78  
 }