Coverage Report - com.sdmetrics.metrics.Matrix - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
Matrix
100%
27/27
100%
2/2
1,125
 
 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.MetaModelElement;
 26  
 
 27  
 /**
 28  
  * Represents the definition of a relation matrix in the metric definition file.
 29  
  * A matrix has a row and a column type, and, optionally row and column filter
 30  
  * expressions.
 31  
  */
 32  
 public class Matrix extends MetricEntry {
 33  
         /** Type of the source elements that make up the rows. */
 34  
         private final MetaModelElement rowType;
 35  
         /** Type of the target elements that make up the columns. */
 36  
         private final MetaModelElement columnType;
 37  
         /** Condition expression for row elements. */
 38  419
         private ExpressionNode rowCondition = null;
 39  
         /** Condition expression for column elements. */
 40  419
         private ExpressionNode columnCondition = null;
 41  
 
 42  
         /**
 43  
          * Creates a new relation matrix definition.
 44  
          * 
 45  
          * @param name Name of the relation matrix.
 46  
          * @param rowType Type of the source elements that make up the rows.
 47  
          * @param columnType Type of the target elements that make up the columns.
 48  
          */
 49  
         public Matrix(String name, MetaModelElement rowType,
 50  
                         MetaModelElement columnType) {
 51  419
                 super(name);
 52  419
                 this.rowType = rowType;
 53  419
                 this.columnType = columnType;
 54  419
         }
 55  
 
 56  
         /**
 57  
          * Retrieves the element type of the source elements (rows).
 58  
          * 
 59  
          * @return Metamodel element type of the row elements.
 60  
          */
 61  
         public MetaModelElement getRowType() {
 62  3
                 return rowType;
 63  
         }
 64  
 
 65  
         /**
 66  
          * Retrieves the element type of the target elements (columns).
 67  
          * 
 68  
          * @return Metamodel element type of the column elements.
 69  
          */
 70  
         public MetaModelElement getColumnType() {
 71  3
                 return columnType;
 72  
         }
 73  
 
 74  
         /**
 75  
          * Gets the condition expression for row elements to be included in the
 76  
          * matrix.
 77  
          * 
 78  
          * @return Root node of the row condition expression operator tree.
 79  
          */
 80  
         public ExpressionNode getRowCondition() {
 81  3
                 return rowCondition;
 82  
         }
 83  
 
 84  
         /**
 85  
          * Gets the condition expression for column elements to be included in the
 86  
          * matrix.
 87  
          * 
 88  
          * @return Root node of the column condition expression operator tree.
 89  
          */
 90  
         public ExpressionNode getColumnCondition() {
 91  3
                 return columnCondition;
 92  
         }
 93  
 
 94  
         /**
 95  
          * Sets the condition for row elements to be included in the matrix.
 96  
          * 
 97  
          * @param conditionExpr Root node of the row condition's operator tree.
 98  
          */
 99  
         void setRowCondition(ExpressionNode conditionExpr) {
 100  417
                 this.rowCondition = conditionExpr;
 101  417
         }
 102  
 
 103  
         /**
 104  
          * Sets the condition for column elements to be included in the matrix.
 105  
          * 
 106  
          * @param conditionExpr Root node of the column condition's operator tree.
 107  
          */
 108  
         void setColumnCondition(ExpressionNode conditionExpr) {
 109  417
                 this.columnCondition = conditionExpr;
 110  417
         }
 111  
 
 112  
         /**
 113  
          * Returns a string representation of the matrix definition.
 114  
          * 
 115  
          * @return String with the name of matrix and the row/column type names, and
 116  
          *         the line number of the definition
 117  
          */
 118  
         @Override
 119  
         public String toString() {
 120  2
                 StringBuilder sb = new StringBuilder();
 121  2
                 sb.append("relation matrix ");
 122  2
                 sb.append(name);
 123  2
                 sb.append(" [");
 124  2
                 sb.append(rowType.getName());
 125  2
                 sb.append(" X ");
 126  2
                 sb.append(columnType.getName());
 127  2
                 sb.append("]");
 128  2
                 if (location > 0) {
 129  1
                         sb.append(" (line ");
 130  1
                         sb.append(location);
 131  1
                         sb.append(")");
 132  
                 }
 133  2
                 return sb.toString();
 134  
         }
 135  
 }