Coverage Report - org.kuali.rice.shareddata.api.campus.CampusType
 
Classes in this File Line Coverage Branch Coverage Complexity
CampusType
91%
22/24
N/A
1.167
CampusType$1
N/A
N/A
1.167
CampusType$Builder
100%
32/32
100%
4/4
1.167
CampusType$Constants
50%
1/2
N/A
1.167
CampusType$Elements
0%
0/1
N/A
1.167
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.rice.shareddata.api.campus;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.commons.lang.builder.EqualsBuilder;
 21  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 22  
 import org.apache.commons.lang.builder.ToStringBuilder;
 23  
 import org.kuali.rice.core.api.CoreConstants;
 24  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 25  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 26  
 import org.w3c.dom.Element;
 27  
 
 28  
 import javax.xml.bind.annotation.XmlAccessType;
 29  
 import javax.xml.bind.annotation.XmlAccessorType;
 30  
 import javax.xml.bind.annotation.XmlAnyElement;
 31  
 import javax.xml.bind.annotation.XmlElement;
 32  
 import javax.xml.bind.annotation.XmlRootElement;
 33  
 import javax.xml.bind.annotation.XmlType;
 34  
 import java.io.Serializable;
 35  
 import java.util.Collection;
 36  
 
 37  
 /**
 38  
  * An immutable representation of a {@link CampusTypeContract}.
 39  
  *
 40  
  * <p>To construct an instance of a CampusType, use the {@link CampusType.Builder} class.
 41  
  *
 42  
  * @see CampusTypeContract
 43  
  */
 44  
 @XmlRootElement(name = CampusType.Constants.ROOT_ELEMENT_NAME)
 45  
 @XmlAccessorType(XmlAccessType.NONE)
 46  
 @XmlType(name = CampusType.Constants.TYPE_NAME, propOrder = {
 47  
                 CampusType.Elements.CODE,
 48  
                 CampusType.Elements.NAME,
 49  
                 CampusType.Elements.ACTIVE,
 50  
         CoreConstants.CommonElements.VERSION_NUMBER,
 51  
         CoreConstants.CommonElements.OBJECT_ID,
 52  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 53  
 })
 54  10
 public final class CampusType implements CampusTypeContract, ModelObjectComplete{
 55  
         private static final long serialVersionUID = -6325716665728047946L;
 56  
 
 57  
         @XmlElement(name = Elements.CODE, required=true)
 58  
         private final String code;
 59  
 
 60  
     @XmlElement(name = Elements.NAME, required=false)
 61  
         private final String name;
 62  
 
 63  
         @XmlElement(name = Elements.ACTIVE, required=false)
 64  
         private final boolean active;
 65  
 
 66  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 67  
     private final Long versionNumber;
 68  
 
 69  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 70  
         private final String objectId;
 71  
     
 72  16
         @SuppressWarnings("unused")
 73  
     @XmlAnyElement
 74  
     private final Collection<Element> _futureElements = null;
 75  
         
 76  
          /** 
 77  
      * This constructor should never be called.  It is only present for use during JAXB unmarshalling. 
 78  
      */
 79  6
     private CampusType() {
 80  6
             this.code = null;
 81  6
             this.name = null;
 82  6
             this.active = false;
 83  6
         this.versionNumber = null;
 84  6
         this.objectId = null;
 85  6
     }
 86  
     
 87  
     /**
 88  
          * Constructs a CampusType from the given builder.  This constructor is private and should only
 89  
          * ever be invoked from the builder.
 90  
          * 
 91  
          * @param builder the Builder from which to construct the campus type
 92  
          */
 93  10
     private CampusType(Builder builder) {
 94  10
         this.code = builder.getCode();
 95  10
         this.name = builder.getName();
 96  10
         this.active = builder.isActive();
 97  10
         this.versionNumber = builder.getVersionNumber();
 98  10
         this.objectId = builder.getObjectId();
 99  10
     }
 100  
     
 101  
         @Override
 102  
         public String getCode() {
 103  4
                 return this.code;
 104  
         }
 105  
 
 106  
         @Override
 107  
         public String getName() {
 108  4
                 return this.name;
 109  
         }
 110  
 
 111  
         @Override
 112  
         public boolean isActive() {
 113  4
                 return this.active; 
 114  
         }
 115  
 
 116  
     @Override
 117  
     public Long getVersionNumber() {
 118  4
         return this.versionNumber;
 119  
     }
 120  
     
 121  
     @Override
 122  
         public String getObjectId() {
 123  4
                 return objectId;
 124  
         }
 125  
 
 126  
         /**
 127  
      * This builder is used to construct instances of CampusType.  It enforces the constraints of the {@link CampusTypeContract}.
 128  
      */
 129  8
     public static class Builder implements CampusTypeContract, ModelBuilder, Serializable {
 130  
                 private static final long serialVersionUID = 1807428861457935238L;
 131  
                 
 132  
                 private String code;
 133  
         private String name;
 134  
         private boolean active;
 135  
         private Long versionNumber;
 136  
         private String objectId;
 137  
 
 138  
                 /**
 139  
                  * Private constructor for creating a builder with all of it's required attributes.
 140  
                  */
 141  12
         private Builder(String code) {
 142  12
             setCode(code);
 143  11
                         setActive(true);
 144  11
         }
 145  
 
 146  
         /**
 147  
          * Creates a builder from the given campus type code.
 148  
          * 
 149  
          * @param code the campus type code
 150  
          * @return an instance of the builder with the code already populated
 151  
          * @throws IllegalArgumentException if the code is null or blank
 152  
          */
 153  
         public static Builder create(String code) {
 154  3
             return new Builder(code);
 155  
         }
 156  
 
 157  
         /**
 158  
          * Creates a builder by populating it with data from the given {@link CampusTypeContract}.
 159  
          * 
 160  
          * @param contract the contract from which to populate this builder
 161  
          * @return an instance of the builder populated with data from the contract
 162  
          */
 163  
         public static Builder create(CampusTypeContract contract) {
 164  10
                 if (contract == null) {
 165  1
                 throw new IllegalArgumentException("contract is null");
 166  
             }
 167  9
             Builder builder =  new Builder(contract.getCode());
 168  9
             builder.setName(contract.getName());
 169  9
             builder.setActive(contract.isActive());
 170  9
             builder.setVersionNumber(contract.getVersionNumber());
 171  9
             builder.setObjectId(contract.getObjectId());
 172  9
             return builder;
 173  
         }
 174  
 
 175  
                 /**
 176  
                  * Sets the value of the code on this builder to the given value.
 177  
                  * 
 178  
                  * @param code the code value to set, must not be null or blank
 179  
                  * @throws IllegalArgumentException if the code is null or blank
 180  
                  */
 181  
         public void setCode(String code) {
 182  12
             if (StringUtils.isBlank(code)) {
 183  1
                 throw new IllegalArgumentException("code is blank");
 184  
             }
 185  11
             this.code = code;
 186  11
         }
 187  
 
 188  
                 public void setName(String name) {
 189  9
                         this.name = name;
 190  9
                 }
 191  
 
 192  
                 public void setActive(boolean active) {
 193  20
                         this.active = active;
 194  20
                 }
 195  
 
 196  
         public void setVersionNumber(Long versionNumber) {
 197  9
             this.versionNumber = versionNumber;
 198  9
         }
 199  
         
 200  
         public void setObjectId(String objectId) {
 201  9
                 this.objectId = objectId;
 202  9
         }
 203  
 
 204  
                 @Override
 205  
                 public String getCode() {
 206  11
                         return code;
 207  
                 }
 208  
 
 209  
                 @Override
 210  
                 public String getName() {
 211  11
                         return name;
 212  
                 }
 213  
 
 214  
                 @Override
 215  
                 public boolean isActive() {
 216  11
                         return active;
 217  
                 }
 218  
 
 219  
         @Override
 220  
         public Long getVersionNumber() {
 221  11
             return versionNumber;
 222  
         }
 223  
         
 224  
         @Override
 225  
             public String getObjectId() {
 226  11
                     return objectId;
 227  
             }
 228  
 
 229  
                 /**
 230  
                  * Builds an instance of a CampusType based on the current state of the builder.
 231  
                  * 
 232  
                  * @return the fully-constructed CampusType
 233  
                  */
 234  
         @Override
 235  
         public CampusType build() {
 236  10
             return new CampusType(this);
 237  
         }
 238  
                 
 239  
     }
 240  
         @Override
 241  
         public int hashCode() {
 242  0
                 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 243  
         }
 244  
 
 245  
         @Override
 246  
         public boolean equals(Object obj) {
 247  2
                 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 248  
         }
 249  
 
 250  
         @Override
 251  
         public String toString() {
 252  0
                 return ToStringBuilder.reflectionToString(this);
 253  
         }
 254  
         
 255  
         /**
 256  
          * Defines some internal constants used on this class.
 257  
          */
 258  0
         static class Constants {
 259  
                 final static String ROOT_ELEMENT_NAME = "campusType";
 260  
                 final static String TYPE_NAME = "CampusTypeType";
 261  1
                 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS};
 262  
         }
 263  
         
 264  
         /**
 265  
          * A private class which exposes constants which define the XML element names to use
 266  
          * when this object is marshalled to XML.
 267  
          */
 268  0
         static class Elements {
 269  
                 final static String CODE = "code";
 270  
                 final static String NAME = "name";
 271  
                 final static String ACTIVE = "active";
 272  
         }
 273  
 }