Coverage Report - com.sdmetrics.metrics.Rule - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
Rule
100%
29/29
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 java.util.Collection;
 25  
 
 26  
 import com.sdmetrics.model.MetaModelElement;
 27  
 
 28  
 /**
 29  
  * Represents a design rule. An instance of this class corresponds to one rule
 30  
  * element in the metrics definition file.
 31  
  */
 32  
 public class Rule extends MetricEntry {
 33  
         /** The element type for which the rule is defined. */
 34  
         private final MetaModelElement type;
 35  
         /** The category the rule belongs to. */
 36  
         private final String cat;
 37  
         /** The final criticality of the rule. */
 38  
         private final String crit;
 39  
         /** Indicates whether the rule is currently enabled. */
 40  
         private final boolean enabled;
 41  
         /** The application areas (development phases) of the rule. */
 42  
         private final Collection<String> applicationAreas;
 43  
 
 44  
         /**
 45  
          * Creates a new rule.
 46  
          * 
 47  
          * @param name Name of the rule.
 48  
          * @param type Metamodel element type of the elements for which this rule is
 49  
          *        defined.
 50  
          * @param category The category of the rule.
 51  
          * @param criticality The criticality of the rule.
 52  
          * @param appAreas The application areas of the rule.
 53  
          * @param enabled Indicates whether or not this rule is enabled and should
 54  
          *        be checked.
 55  
          */
 56  
         public Rule(String name, MetaModelElement type, String category,
 57  
                         String criticality, Collection<String> appAreas, boolean enabled) {
 58  1747
                 super(name);
 59  1747
                 this.type = type;
 60  1747
                 this.cat = category;
 61  1747
                 this.crit = criticality;
 62  1747
                 this.applicationAreas = appAreas;
 63  1747
                 this.enabled = enabled;
 64  1747
         }
 65  
 
 66  
         /**
 67  
          * Creates a copy of a rule definition for another type. 
 68  
          * 
 69  
          * @param original The rule definition to copy.
 70  
          * @param newType Element type for the newly created copy.
 71  
          */
 72  
         Rule(Rule original, MetaModelElement newType) {
 73  66
                 super(original);
 74  66
                 this.type = newType;
 75  66
                 this.cat = original.cat;
 76  66
                 this.crit = original.crit;
 77  66
                 this.applicationAreas = original.applicationAreas;
 78  66
                 this.enabled = original.enabled;
 79  66
         }
 80  
 
 81  
         /**
 82  
          * Gets the category of this rule.
 83  
          * 
 84  
          * @return The category of the rule.
 85  
          */
 86  
         public String getCategory() {
 87  4
                 return cat;
 88  
         }
 89  
 
 90  
         /**
 91  
          * Gets the criticality of this rule.
 92  
          * 
 93  
          * @return The criticality of the rule.
 94  
          */
 95  
         public String getCriticality() {
 96  6
                 return crit;
 97  
         }
 98  
 
 99  
         /**
 100  
          * Gets the element type for which this rule is defined.
 101  
          * 
 102  
          * @return The element type of this rule.
 103  
          */
 104  
         public MetaModelElement getType() {
 105  2
                 return type;
 106  
         }
 107  
 
 108  
         /**
 109  
          * Tests whether this rule is enabled to not. When a rule is disabled, it is
 110  
          * not checked for rule violations.
 111  
          * 
 112  
          * @return <code>true</code> if this rule is enabled.
 113  
          */
 114  
         public boolean isEnabled() {
 115  55
                 return enabled;
 116  
         }
 117  
 
 118  
         /**
 119  
          * Gets the application areas of the rule.
 120  
          * 
 121  
          * @return The application areas of the rule, or <code>null</code> if none
 122  
          *         have been specified.
 123  
          */
 124  
         public Collection<String> getApplicableAreas() {
 125  101
                 return applicationAreas;
 126  
         }
 127  
 
 128  
         /**
 129  
          * Returns a string representation of the rule.
 130  
          * 
 131  
          * @return String with the name of rule, its type, and the line number of
 132  
          *         the definition
 133  
          */
 134  
         @Override
 135  
         public String toString() {
 136  2
                 StringBuilder sb = new StringBuilder();
 137  2
                 sb.append("rule ");
 138  2
                 sb.append(name);
 139  2
                 sb.append(" for elements of type ");
 140  2
                 sb.append(type.getName());
 141  2
                 if (location > 0) {
 142  1
                         sb.append(" (line ");
 143  1
                         sb.append(location);
 144  1
                         sb.append(")");
 145  
                 }
 146  2
                 return sb.toString();
 147  
         }
 148  
 
 149  
 }