Coverage Report - org.kuali.rice.krms.api.repository.category.CategoryDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
CategoryDefinition
100%
21/21
N/A
1.429
CategoryDefinition$1
N/A
N/A
1.429
CategoryDefinition$Builder
96%
30/31
90%
9/10
1.429
CategoryDefinition$Constants
50%
1/2
N/A
1.429
CategoryDefinition$Elements
0%
0/1
N/A
1.429
 
 1  
 package org.kuali.rice.krms.api.repository.category;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.apache.commons.lang.builder.EqualsBuilder;
 5  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 6  
 import org.apache.commons.lang.builder.ToStringBuilder;
 7  
 import org.kuali.rice.core.api.CoreConstants;
 8  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 9  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 10  
 import org.w3c.dom.Element;
 11  
 
 12  
 import javax.xml.bind.annotation.XmlAccessType;
 13  
 import javax.xml.bind.annotation.XmlAccessorType;
 14  
 import javax.xml.bind.annotation.XmlAnyElement;
 15  
 import javax.xml.bind.annotation.XmlElement;
 16  
 import javax.xml.bind.annotation.XmlRootElement;
 17  
 import javax.xml.bind.annotation.XmlType;
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 
 21  
 @XmlRootElement(name = CategoryDefinition.Constants.ROOT_ELEMENT_NAME)
 22  
 @XmlAccessorType(XmlAccessType.NONE)
 23  
 @XmlType(name = CategoryDefinition.Constants.TYPE_NAME, propOrder = {
 24  
                 CategoryDefinition.Elements.ID,
 25  
                 CategoryDefinition.Elements.NAME,
 26  
                 CategoryDefinition.Elements.NAMESPACE,
 27  
         CoreConstants.CommonElements.VERSION_NUMBER,
 28  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 29  
 })
 30  10
 public class CategoryDefinition implements CategoryDefinitionContract, ModelObjectComplete {
 31  
 
 32  
     private static final long serialVersionUID = -4748818967880857017L;
 33  
 
 34  
     @XmlElement(name = Elements.ID, required=true)
 35  
     private String id;
 36  
     @XmlElement(name = Elements.NAME, required=true)
 37  
     private String name;
 38  
     @XmlElement(name = Elements.NAMESPACE, required=true)
 39  
     private String namespace;
 40  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 41  
     private final Long versionNumber;
 42  
 
 43  16
     @SuppressWarnings("unused")
 44  
     @XmlAnyElement
 45  
     private final Collection<Element> _futureElements = null;
 46  
 
 47  
     /**
 48  
     * This constructor should never be called.  It is only present for use during JAXB unmarshalling.
 49  
     */
 50  6
    private CategoryDefinition() {
 51  6
        this.id = null;
 52  6
        this.name = null;
 53  6
        this.namespace = null;
 54  6
        this.versionNumber = null;
 55  6
    }
 56  
 
 57  
     /**
 58  
          * Constructs a CategoryDefinition from the given builder.  This constructor is private and should only
 59  
          * ever be invoked from the builder.
 60  
          *
 61  
          * @param builder the Builder from which to construct the CategoryDefinition
 62  
          */
 63  10
     private CategoryDefinition(Builder builder) {
 64  10
         this.id = builder.getId();
 65  10
         this.name = builder.getName();
 66  10
         this.namespace = builder.getNamespace();
 67  10
         this.versionNumber = builder.getVersionNumber();
 68  10
     }
 69  
 
 70  
         public String getId() {
 71  4
                 return this.id;
 72  
         }
 73  
 
 74  
         public String getName() {
 75  4
                 return this.name;
 76  
         }
 77  
 
 78  
         public String getNamespace() {
 79  4
                 return this.namespace;
 80  
         }
 81  
 
 82  
     @Override
 83  
     public Long getVersionNumber() {
 84  2
         return versionNumber;
 85  
     }
 86  
 
 87  
     /**
 88  
      * This builder is used to construct instances of CategoryDefinition.  It enforces the constraints of the {@link org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract}.
 89  
      */
 90  4
     public static class Builder implements CategoryDefinitionContract, ModelBuilder, Serializable {
 91  
 
 92  
         private static final long serialVersionUID = -5775478956373560840L;
 93  
 
 94  
         private String id;
 95  
         private String name;
 96  
         private String namespace;
 97  
         private Long versionNumber;
 98  
 
 99  
         /**
 100  
          * Private constructor for creating a builder with all of it's required attributes.
 101  
          */
 102  20
         private Builder(String id, String name, String namespace) {
 103  20
             setId(id);
 104  19
             setName(name);
 105  17
             setNamespace(namespace);
 106  16
         }
 107  
 
 108  
         /**
 109  
          * Creates a builder from the given parameters.
 110  
          *
 111  
          * @param id the CategoryDefinition id
 112  
          * @param name the CategoryDefinition name
 113  
          * @param namespace the CategoryDefinition namespace
 114  
          * @return an instance of the builder with the fields already populated
 115  
          * @throws IllegalArgumentException if the either the id, name or namespace is null or blank
 116  
          */
 117  
         public static Builder create(String id, String name, String namespace) {
 118  6
             return new Builder(id, name, namespace);
 119  
         }
 120  
 
 121  
         /**
 122  
          * Creates a builder by populating it with data from the given {@link CategoryDefinition}.
 123  
          *
 124  
          * @param category the category from which to populate this builder
 125  
          * @return an instance of the builder populated with data from the contract
 126  
          */
 127  
         public static Builder create(CategoryDefinitionContract category) {
 128  14
             if (category == null) {
 129  0
                 throw new IllegalArgumentException("contract is null");
 130  
             }
 131  14
             Builder builder =  new Builder(category.getId(), category.getName(), category.getNamespace());
 132  14
             builder.setVersionNumber(category.getVersionNumber());
 133  14
             return builder;
 134  
         }
 135  
 
 136  
         /**
 137  
          * Sets the value of the id on this builder to the given value.
 138  
          *
 139  
          * @param id the id value to set, must be null or non-blank
 140  
          * @throws IllegalArgumentException if the id is non-null and blank
 141  
          */
 142  
         public void setId(String id) {
 143  20
             if (null != id && StringUtils.isBlank(id)) {
 144  1
                 throw new IllegalArgumentException("id must be null or non-blank");
 145  
             }
 146  19
             this.id = id;
 147  19
         }
 148  
 
 149  
         /**
 150  
          * Sets the name for the category definition that will be returned by this builder.
 151  
          * The name must not be null or blank.
 152  
          *
 153  
          * @param name the name to set on this builder, must not be null or blank
 154  
          *
 155  
          * @throws IllegalArgumentException if the given name is null or blank
 156  
          */
 157  
         public void setName(String name) {
 158  19
             if (StringUtils.isBlank(name)) {
 159  2
                 throw new IllegalArgumentException("name is blank");
 160  
             }
 161  17
             this.name = name;
 162  17
         }
 163  
 
 164  
         /**
 165  
          * Sets the namespace code for the category definition that will be returned by this builder.
 166  
          * The namespace must not be null or blank.
 167  
          *
 168  
          * @param namespace the namespace code to set on this builder, must not be null or blank
 169  
          *
 170  
          * @throws IllegalArgumentException if the given namespace is null or blank
 171  
          */
 172  
         public void setNamespace(String namespace) {
 173  17
             if (StringUtils.isBlank(namespace)) {
 174  1
                 throw new IllegalArgumentException("namespace is blank");
 175  
             }
 176  16
             this.namespace = namespace;
 177  16
         }
 178  
 
 179  
         public void setVersionNumber(Long versionNumber){
 180  14
             this.versionNumber = versionNumber;
 181  14
         }
 182  
 
 183  
         @Override
 184  
         public String getId() {
 185  16
             return this.id;
 186  
         }
 187  
 
 188  
         @Override
 189  
         public String getName() {
 190  16
             return this.name;
 191  
         }
 192  
 
 193  
         @Override
 194  
         public String getNamespace() {
 195  16
             return this.namespace;
 196  
         }
 197  
 
 198  
         @Override
 199  
         public Long getVersionNumber() {
 200  16
             return this.versionNumber;
 201  
         }
 202  
 
 203  
         /**
 204  
          * Builds an instance of a CategoryDefinition based on the current state of the builder.
 205  
          *
 206  
          * @return the fully-constructed CampusType
 207  
          */
 208  
         @Override
 209  
         public CategoryDefinition build() {
 210  10
             return new CategoryDefinition(this);
 211  
         }
 212  
 
 213  
     }
 214  
     @Override
 215  
     public int hashCode() {
 216  21
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 217  
     }
 218  
 
 219  
     @Override
 220  
     public boolean equals(Object obj) {
 221  6
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 222  
     }
 223  
 
 224  
     @Override
 225  
     public String toString() {
 226  3
         return ToStringBuilder.reflectionToString(this);
 227  
     }
 228  
 
 229  
     /**
 230  
      * Defines some internal constants used on this class.
 231  
      */
 232  0
     static class Constants {
 233  
         final static String ROOT_ELEMENT_NAME = "category";
 234  
         final static String TYPE_NAME = "CategoryType";
 235  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 236  
     }
 237  
 
 238  
     /**
 239  
      * A private class which exposes constants which define the XML element names to use
 240  
      * when this object is marshalled to XML.
 241  
      */
 242  0
     public static class Elements {
 243  
         final static String ID = "id";
 244  
         final static String NAME = "name";
 245  
         final static String NAMESPACE = "namespace";
 246  
     }
 247  
 }
 248  
 
 249