Coverage Report - com.sdmetrics.metrics.Metric - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
Metric
100%
24/24
100%
2/2
1,143
 
 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.model.MetaModelElement;
 25  
 
 26  
 /**
 27  
  * Represents the definition of metric in the metric definition file.
 28  
  */
 29  
 public class Metric extends MetricEntry {
 30  
         /** Type of the element for which the metric is defined. */
 31  
         private MetaModelElement type;
 32  
         /** Indicates if the metric is internal, or externally visible. */
 33  
         private boolean internal;
 34  
         /** The category (structural property) measured by the metric. */
 35  
         private String category;
 36  
 
 37  
         /**
 38  
          * Creates a new metric definition.
 39  
          * 
 40  
          * @param name Name of the metric.
 41  
          * @param type Metamodel element type of the elements for which this metric
 42  
          *        is defined.
 43  
          * @param category The structural property measured by the metric.
 44  
          */
 45  
         public Metric(String name, MetaModelElement type, String category) {
 46  4481
                 super(name);
 47  4481
                 this.type = type;
 48  4481
                 this.category = category;
 49  4481
         }
 50  
 
 51  
         /**
 52  
          * Creates a copy of a metric definition for another type.
 53  
          * 
 54  
          * @param original The metric definition to copy.
 55  
          * @param newType Element type for the newly created copy.
 56  
          */
 57  
         Metric(Metric original, MetaModelElement newType) {
 58  183
                 super(original);
 59  183
                 this.type = newType;
 60  183
                 this.internal = original.internal;
 61  183
                 this.category = original.category;
 62  183
         }
 63  
 
 64  
         /**
 65  
          * Retrieves the type of elements for which the metric is defined.
 66  
          * 
 67  
          * @return Element type of this metric.
 68  
          */
 69  
         public MetaModelElement getType() {
 70  5
                 return type;
 71  
         }
 72  
 
 73  
         /**
 74  
          * Gets the category (structural property) measured by the metric.
 75  
          * 
 76  
          * @return This metric's category.
 77  
          */
 78  
         public String getCategory() {
 79  3
                 return category;
 80  
         }
 81  
 
 82  
         /**
 83  
          * Tests if this metric is internal or externally visible in the output.
 84  
          * 
 85  
          * @return <code>true</code> if the metric is internal.
 86  
          */
 87  
         public boolean isInternal() {
 88  3
                 return internal;
 89  
         }
 90  
 
 91  
         /**
 92  
          * Marks this metric as internal or external.
 93  
          * 
 94  
          * @param internal <code>true</code> to make the metric internal,
 95  
          *        <code>false</code> to have it appear in metric data output.
 96  
          */
 97  
         void setInternal(boolean internal) {
 98  4467
                 this.internal = internal;
 99  4467
         }
 100  
 
 101  
         /**
 102  
          * Returns a string representation of the metric.
 103  
          * 
 104  
          * @return String with the name of metric, its type, and the line number of
 105  
          *         the definition
 106  
          */
 107  
         @Override
 108  
         public String toString() {
 109  2
                 StringBuilder sb = new StringBuilder();
 110  2
                 sb.append("metric ");
 111  2
                 sb.append(name);
 112  2
                 sb.append(" for elements of type ");
 113  2
                 sb.append(type.getName());
 114  2
                 if (location > 0) {
 115  1
                         sb.append(" (line ");
 116  1
                         sb.append(location);
 117  1
                         sb.append(")");
 118  
                 }
 119  2
                 return sb.toString();
 120  
         }
 121  
 }