Coverage Report - com.sdmetrics.metrics.MetricEntry - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
MetricEntry
100%
33/33
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  
 /**
 25  
  * Base class for entries in the metric definition file (metrics, sets, rules,
 26  
  * or matrices). An entry has a name, a brief informal description, a full
 27  
  * description, a location (line number), and a calculation procedure that
 28  
  * defines the entry.
 29  
  */
 30  
 public abstract class MetricEntry {
 31  
         /** Name of the entry in the metric definition file. */
 32  
         protected String name;
 33  
         /** Entry ID number (array index for efficient storage). */
 34  
         protected int id;
 35  
         /** Description of the entry. */
 36  8972
         protected Description description = new Description();
 37  
         /** Name of the calculation procedure for the entry. */
 38  
         protected String procedureName;
 39  
         /** Attributes of the calculation procedure for the entry. */
 40  8972
         protected ProcedureAttributes attributes = null;
 41  
         /** Line number of the entry in the metric definition file. */
 42  
         protected int location;
 43  
         /** Indicates if this entry can be inherited. */
 44  8972
         private boolean inheritable = false;
 45  
 
 46  
         /**
 47  
          * Constructor.
 48  
          * 
 49  
          * @param name Name of the entry.
 50  
          */
 51  8972
         public MetricEntry(String name) {
 52  8972
                 this.name = name;
 53  8972
         }
 54  
 
 55  
         /**
 56  
          * Creates a copy of the metric entry. The copy shares the description and
 57  
          * procedure definition attributes by reference.
 58  
          * 
 59  
          * @param original The metric entry to copy.
 60  
          */
 61  
         MetricEntry(MetricEntry original) {
 62  315
                 this(original.name);
 63  315
                 this.description = original.description;
 64  315
                 this.procedureName = original.procedureName;
 65  315
                 this.attributes = original.attributes;
 66  315
                 this.location = original.location;
 67  315
                 this.inheritable = original.inheritable;
 68  315
         }
 69  
 
 70  
         /**
 71  
          * Retrieves the name of the entry.
 72  
          * 
 73  
          * @return name of the entry
 74  
          */
 75  
         public String getName() {
 76  8499
                 return name;
 77  
         }
 78  
 
 79  
         /**
 80  
          * Adds text to the description for this entry.
 81  
          * 
 82  
          * @param str Character array with the text to add
 83  
          * @param offset Index of the first character to add
 84  
          * @param len length of the text to add to this entry's description.
 85  
          */
 86  
         void addDescription(char[] str, int offset, int len) {
 87  1219
                 description.add(str, offset, len);
 88  1219
         }
 89  
 
 90  
         /**
 91  
          * Gets the brief description for this entry.
 92  
          * 
 93  
          * @return One-liner informally describing the entry.
 94  
          */
 95  
         public String getBriefDescription() {
 96  10
                 return description.getBriefDescription();
 97  
         }
 98  
 
 99  
         /**
 100  
          * Gets the full description for this entry.
 101  
          * 
 102  
          * @return Full, detailed description for the entry.
 103  
          */
 104  
         public String getFullDescription() {
 105  8
                 return description.getDescription();
 106  
         }
 107  
 
 108  
         /**
 109  
          * Gets the calculation procedure attributes for this entry.
 110  
          * 
 111  
          * @return Calculation procedure attributes for this entry
 112  
          */
 113  
         public ProcedureAttributes getAttributes() {
 114  17512
                 return attributes;
 115  
         }
 116  
 
 117  
         /**
 118  
          * Gets the name of the calculation procedure.
 119  
          * 
 120  
          * @return Name of the calculation procedure (projection, compoundmetric,
 121  
          *         etc)
 122  
          */
 123  
         public String getProcedureName() {
 124  439
                 return procedureName;
 125  
         }
 126  
 
 127  
         /**
 128  
          * Gets the line number of this entry in the metric definition file.
 129  
          * 
 130  
          * @return Line number of the entry, or <code>0</code> if the location is
 131  
          *         not known.
 132  
          */
 133  
         public int getLocation() {
 134  6
                 return location;
 135  
         }
 136  
 
 137  
         /**
 138  
          * Sets the name of the calculation procedure. To maintain backwards
 139  
          * compatibility it can be useful to replace an old/deprecated name by its
 140  
          * new name.
 141  
          * 
 142  
          * @param newName New name for the calculation procedure.
 143  
          */
 144  
         void setProcedureName(String newName) {
 145  8463
                 procedureName = newName;
 146  8463
         }
 147  
 
 148  
         /**
 149  
          * Sets the calculation procedure attributes for this entry.
 150  
          * 
 151  
          * @param model calculation procedure attributes for this entry.
 152  
          */
 153  
         void setAttributes(ProcedureAttributes model) {
 154  8495
                 this.attributes = model;
 155  8495
         }
 156  
 
 157  
         /**
 158  
          * Sets the line number of this entry's definition in the XML file.
 159  
          * 
 160  
          * @param line Line number of the definition.
 161  
          */
 162  
         void setLocation(int line) {
 163  8461
                 location = line;
 164  8461
         }
 165  
 
 166  
         /**
 167  
          * Sets the integer ID for this entry. IDs are unique for each model element
 168  
          * type, and provide an array index for the metric.
 169  
          * 
 170  
          * @param id The ID for the entry.
 171  
          */
 172  
         void setId(int id) {
 173  8775
                 this.id = id;
 174  8775
         }
 175  
 
 176  
         /**
 177  
          * Retrieves the integer ID for this entry.
 178  
          * 
 179  
          * @return Integer ID of the entry.
 180  
          */
 181  
         int getID() {
 182  799
                 return id;
 183  
         }
 184  
 
 185  
         /**
 186  
          * Checks if this entry can be inherited.
 187  
          * 
 188  
          * @return <code>true</code> if the entry should be passed on to descendant
 189  
          *         types
 190  
          */
 191  
         boolean isInheritable() {
 192  1998
                 return inheritable;
 193  
         }
 194  
 
 195  
         /**
 196  
          * Sets the inheritability of this entry.
 197  
          * 
 198  
          * @param value <code>true</code> if the entry should be passed on to
 199  
          *        descendant types, else <code>false</code>
 200  
          */
 201  
         void setInheritable(boolean value) {
 202  8043
                 inheritable = value;
 203  8043
         }
 204  
 }