Coverage Report - com.sdmetrics.metrics.MatrixData - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
MatrixData
100%
13/13
N/A
1
 
 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.List;
 25  
 
 26  
 import com.sdmetrics.math.IntegerMatrix;
 27  
 import com.sdmetrics.model.ModelElement;
 28  
 
 29  
 /**
 30  
  * Data structure to store the data for one matrix.
 31  
  * 
 32  
  * The rows of each matrix are the source model elements from which the relation
 33  
  * of the matrix originates, the columns are the target model elements. The cell
 34  
  * values show the presence or number of relations between the two model
 35  
  * elements of the respective row and column.
 36  
  * */
 37  
 public class MatrixData {
 38  
         /** The definition of the matrix. */
 39  
         private final Matrix definition;
 40  
         /** The list of row model elements of the matrix. */
 41  
         private final List<ModelElement> rowElements;
 42  
         /** The list of column model elements of the matrix. */
 43  
         private final List<ModelElement> colElements;
 44  
         /** Stores the contents of the matrix. */
 45  
         private final IntegerMatrix values;
 46  
 
 47  
         /**
 48  
          * Creates a new relation matrix.
 49  
          * 
 50  
          * @param matrix definition of the matrix
 51  
          * @param rows list of row model elements of the matrix
 52  
          * @param columns list of column model elements of the matrix
 53  
          * @param values the contents of the matrix
 54  
          */
 55  2
         MatrixData(Matrix matrix, List<ModelElement> rows,
 56  
                         List<ModelElement> columns, IntegerMatrix values) {
 57  2
                 this.definition = matrix;
 58  2
                 this.rowElements = rows;
 59  2
                 this.colElements = columns;
 60  2
                 this.values = values;
 61  2
         }
 62  
 
 63  
         /**
 64  
          * Gets the definition of the matrix.
 65  
          * 
 66  
          * @return Definition of the matrix in the metric definition file.
 67  
          */
 68  
         public Matrix getMatrixDefinition() {
 69  1
                 return definition;
 70  
         }
 71  
 
 72  
         /**
 73  
          * Gets the number of rows (source model elements) of this relation matrix.
 74  
          * 
 75  
          * @return The number R of rows of the matrix. Valid row indices run from 0
 76  
          *         to R-1.
 77  
          */
 78  
         public int getNumberOfRows() {
 79  25
                 return rowElements.size();
 80  
         }
 81  
 
 82  
         /**
 83  
          * Gets the number of columns (target model elements) of this relation
 84  
          * matrix.
 85  
          * 
 86  
          * @return The number C of columns of the matrix. Valid column indices run
 87  
          *         from 0 to C-1.
 88  
          */
 89  
         public int getNumberOfColumns() {
 90  22
                 return colElements.size();
 91  
         }
 92  
 
 93  
         /**
 94  
          * Tests if this relation matrix is empty (a null matrix).
 95  
          * 
 96  
          * @return <code>true</code> if all cells of the matrix are zero,
 97  
          *         <code>false</code> if there is at least one non-zero entry.
 98  
          */
 99  
         public boolean isEmpty() {
 100  1
                 return values.isEmpty();
 101  
         }
 102  
 
 103  
         /**
 104  
          * Gets the value of a cell of this relation matrix.
 105  
          * 
 106  
          * @param row Row index of the cell to access.
 107  
          * @param col Column index of the cell to access.
 108  
          * @return Value of the specified cell.
 109  
          */
 110  
         public Integer getValueAt(int row, int col) {
 111  4
                 return values.get(row, col);
 112  
         }
 113  
 
 114  
         /**
 115  
          * Gets the source element in a row of this relation matrix.
 116  
          * 
 117  
          * @param row Row index.
 118  
          * @return The model element at the specified row.
 119  
          */
 120  
         public ModelElement getRowElement(int row) {
 121  22
                 return rowElements.get(row);
 122  
         }
 123  
 
 124  
         /**
 125  
          * Gets the target model element in a column of this relation matrix.
 126  
          * 
 127  
          * @param col Column index.
 128  
          * @return The model element at the specified column.
 129  
          */
 130  
         public ModelElement getColumnElement(int col) {
 131  19
                 return colElements.get(col);
 132  
         }
 133  
 }