Coverage Report - com.sdmetrics.metrics.Set - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
Set
100%
12/12
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 com.sdmetrics.model.MetaModelElement;
 25  
 
 26  
 /**
 27  
  * Represents the definition of a set in the metric definition file.
 28  
  */
 29  
 public class Set extends MetricEntry {
 30  
         /** Type of the element for which the set is defined. */
 31  
         private MetaModelElement type;
 32  
         /** Indicates if this is a multiset or a regular set. */
 33  
         private boolean multiset;
 34  
 
 35  
         /**
 36  
          * Creates a new set definition
 37  
          * 
 38  
          * @param name Name of the set.
 39  
          * @param type Metamodel element type of the elements for which this set is
 40  
          *        defined.
 41  
          */
 42  
         public Set(String name, MetaModelElement type) {
 43  1875
                 super(name);
 44  1875
                 this.type = type;
 45  1875
         }
 46  
 
 47  
         /**
 48  
          * Creates a copy of a set definition for another type. 
 49  
          * 
 50  
          * @param original The set definition to copy.
 51  
          * @param newType Element type for the newly created copy.
 52  
          */
 53  
         Set(Set original, MetaModelElement newType) {
 54  66
                 super(original);
 55  66
                 this.type = newType;
 56  66
                 this.multiset = original.multiset;
 57  66
         }
 58  
 
 59  
         /**
 60  
          * Retrieves the type of elements for which the set is defined.
 61  
          * 
 62  
          * @return Element type of this set.
 63  
          */
 64  
         public MetaModelElement getType() {
 65  2
                 return type;
 66  
         }
 67  
 
 68  
         /**
 69  
          * Checks if this entry defines a regular set or a multiset. Regular sets
 70  
          * contain at most one occurrence of any element, multisets can contain more
 71  
          * than one occurrence of the same element.
 72  
          * 
 73  
          * @return <code>true</code> if set defines a multiset.
 74  
          */
 75  
         public boolean isMultiSet() {
 76  341
                 return multiset;
 77  
         }
 78  
 
 79  
         /**
 80  
          * Makes this set a multiset.
 81  
          * 
 82  
          * @param multi <code>true</code> if this set is to be a multiset, else
 83  
          *        <code>false</code>.
 84  
          */
 85  
         void setMultiSet(boolean multi) {
 86  1861
                 multiset = multi;
 87  1861
         }
 88  
 
 89  
         /**
 90  
          * Returns a string representation of the set.
 91  
          * 
 92  
          * @return String with the name of the set and its type
 93  
          */
 94  
         @Override
 95  
         public String toString() {
 96  1
                 return "set " + name + " for elements of type " + type.getName();
 97  
         }
 98  
 }