Coverage Report - org.kuali.rice.shareddata.api.county.County
 
Classes in this File Line Coverage Branch Coverage Complexity
County
75%
18/24
N/A
1.333
County$1
N/A
N/A
1.333
County$Builder
100%
42/42
100%
8/8
1.333
County$Constants
0%
0/1
N/A
1.333
County$Elements
0%
0/1
N/A
1.333
 
 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.county;
 18  
 
 19  
 import java.io.Serializable;
 20  
 import java.util.Collection;
 21  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlAnyElement;
 25  
 import javax.xml.bind.annotation.XmlElement;
 26  
 import javax.xml.bind.annotation.XmlRootElement;
 27  
 import javax.xml.bind.annotation.XmlType;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 import org.kuali.rice.core.api.CoreConstants;
 31  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 32  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 33  
 import org.w3c.dom.Element;
 34  
 
 35  
 /**
 36  
  * An immutable representation of a {@link CountyContract}.
 37  
  *
 38  
  * <p>To construct an instance of a County, use the {@link County.Builder} class.
 39  
  *
 40  
  * @see CountyContract
 41  
  */
 42  
 @XmlRootElement(name = County.Constants.ROOT_ELEMENT_NAME)
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = County.Constants.TYPE_NAME, propOrder = {
 45  
         County.Elements.CODE,
 46  
         County.Elements.NAME,
 47  
         County.Elements.COUNTRY_CODE,
 48  
         County.Elements.STATE_CODE,
 49  
         County.Elements.ACTIVE,
 50  
         CoreConstants.CommonElements.VERSION_NUMBER,
 51  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 52  
 })
 53  3
 public final class County extends AbstractDataTransferObject implements CountyContract {
 54  
 
 55  
     private static final long serialVersionUID = 6097498602725305353L;
 56  
 
 57  
     @XmlElement(name = Elements.CODE, required = true)
 58  
     private final String code;
 59  
 
 60  
     @XmlElement(name = Elements.NAME, required = true)
 61  
     private final String name;
 62  
 
 63  
     @XmlElement(name = Elements.COUNTRY_CODE, required = true)
 64  
     private final String countryCode;
 65  
 
 66  
     @XmlElement(name = Elements.STATE_CODE, required = true)
 67  
     private final String stateCode;
 68  
 
 69  
     @XmlElement(name = Elements.ACTIVE, required = true)
 70  
     private final boolean active;
 71  
 
 72  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 73  
     private final Long versionNumber;
 74  
 
 75  5
     @SuppressWarnings("unused")
 76  
     @XmlAnyElement
 77  
     private final Collection<Element> _futureElements = null;
 78  
 
 79  
     /**
 80  
      * This constructor should never be called except during JAXB unmarshalling.
 81  
      */
 82  
     @SuppressWarnings("unused")
 83  2
     private County() {
 84  2
         this.code = null;
 85  2
         this.name = null;
 86  2
         this.countryCode = null;
 87  2
         this.stateCode = null;
 88  2
         this.active = false;
 89  2
         this.versionNumber = null;
 90  2
     }
 91  
 
 92  3
     private County(Builder builder) {
 93  3
         code = builder.getCode();
 94  3
         name = builder.getName();
 95  3
         countryCode = builder.getCountryCode();
 96  3
         stateCode = builder.getStateCode();
 97  3
         active = builder.isActive();
 98  3
         versionNumber = builder.getVersionNumber();
 99  3
     }
 100  
 
 101  
     @Override
 102  
     public String getCode() {
 103  0
         return code;
 104  
     }
 105  
 
 106  
     @Override
 107  
     public String getName() {
 108  0
         return name;
 109  
     }
 110  
 
 111  
     @Override
 112  
     public String getCountryCode() {
 113  0
         return countryCode;
 114  
     }
 115  
 
 116  
     @Override
 117  
     public String getStateCode() {
 118  0
         return stateCode;
 119  
     }
 120  
 
 121  
     @Override
 122  
     public boolean isActive() {
 123  0
         return active;
 124  
     }
 125  
 
 126  
     @Override
 127  
     public Long getVersionNumber() {
 128  0
         return versionNumber;
 129  
     }
 130  
 
 131  
     /**
 132  
      * This builder constructs an County enforcing the constraints of the {@link CountyContract}.
 133  
      */
 134  3
     public static class Builder implements CountyContract, ModelBuilder, Serializable {
 135  
 
 136  
         private static final long serialVersionUID = 7077484401017765844L;
 137  
 
 138  
         private String code;
 139  
         private String name;
 140  
         private String countryCode;
 141  
         private String stateCode;
 142  
         private boolean active;
 143  
         private Long versionNumber;
 144  
 
 145  17
         private Builder(String code, String name, String countryCode, String stateCode) {
 146  17
             setCode(code);
 147  13
             setName(name);
 148  10
             setCountryCode(countryCode);
 149  7
             setStateCode(stateCode);
 150  4
             setVersionNumber(versionNumber);
 151  4
         }
 152  
 
 153  
         /**
 154  
          * creates a County Builder with the required fields.
 155  
          */
 156  
         public static Builder create(String code, String name, String countryCode, String stateCode) {
 157  15
             final Builder builder = new Builder(code, name, countryCode, stateCode);
 158  2
             builder.setActive(true);
 159  2
             return builder;
 160  
         }
 161  
 
 162  
         /**
 163  
          * creates a County Builder from an existing {@link CountyContract}.
 164  
          */
 165  
         public static Builder create(CountyContract contract) {
 166  2
             final Builder builder = new Builder(contract.getCode(), contract.getName(), contract.getCountryCode(), contract.getStateCode());
 167  2
             builder.setActive(contract.isActive());
 168  2
             builder.setVersionNumber(contract.getVersionNumber());
 169  2
             return builder;
 170  
         }
 171  
 
 172  
         @Override
 173  
         public String getCode() {
 174  4
             return code;
 175  
         }
 176  
 
 177  
         /**
 178  
          * Sets the code to be used for the County created from this Builder.
 179  
          * @param code String code for a County
 180  
          * @throws IllegalArgumentException if the passed in code is null or a blank String.
 181  
          */
 182  
         public void setCode(String code) {
 183  17
             if (StringUtils.isBlank(code)) {
 184  4
                 throw new IllegalArgumentException("code is blank");
 185  
             }
 186  
 
 187  13
             this.code = code;
 188  13
         }
 189  
 
 190  
         @Override
 191  
         public String getName() {
 192  4
             return name;
 193  
         }
 194  
 
 195  
         /**
 196  
          * Sets the full name of the County created from this Builder.
 197  
          * @param name String representing the full name for the County
 198  
          * @throws IllegalArgumentException if the passed in name is null or a blank String.
 199  
          */
 200  
         public void setName(String name) {
 201  13
             if (StringUtils.isBlank(name)) {
 202  3
                 throw new IllegalArgumentException("name is blank");
 203  
             }
 204  
 
 205  10
             this.name = name;
 206  10
         }
 207  
 
 208  
         @Override
 209  
         public String getCountryCode() {
 210  4
             return countryCode;
 211  
         }
 212  
 
 213  
         /**
 214  
          * Sets the Country code to be associated with the County created from this Builder.
 215  
          * @param countryCode String representing the Country Code
 216  
          * @throws IllegalArgumentException if the passed in countryCode is null or a blank String.
 217  
          * @see org.kuali.rice.shareddata.api.country.CountryContract
 218  
          */
 219  
         public void setCountryCode(String countryCode) {
 220  10
             if (StringUtils.isBlank(countryCode)) {
 221  3
                 throw new IllegalArgumentException("countryCode is blank");
 222  
             }
 223  
 
 224  7
             this.countryCode = countryCode;
 225  7
         }
 226  
 
 227  
         @Override
 228  
         public String getStateCode() {
 229  4
             return stateCode;
 230  
         }
 231  
 
 232  
         /**
 233  
          * Sets the State code to be associated with the County created from this Builder.
 234  
          * @param stateCode String representing the State code
 235  
          * @throws  IllegalArgumentException if the passed in statecode is null or a blank String.
 236  
          * @see org.kuali.rice.shareddata.api.state.StateContract
 237  
          */
 238  
         public void setStateCode(String stateCode) {
 239  7
             if (StringUtils.isBlank(stateCode)) {
 240  3
                 throw new IllegalArgumentException("stateCode is blank");
 241  
             }
 242  
 
 243  4
             this.stateCode = stateCode;
 244  4
         }
 245  
 
 246  
         @Override
 247  
         public boolean isActive() {
 248  4
             return active;
 249  
         }
 250  
 
 251  
         /**
 252  
          * Sets the active flag for the County created from this Builder.
 253  
          * @param active
 254  
          */
 255  
         public void setActive(boolean active) {
 256  4
             this.active = active;
 257  4
         }
 258  
 
 259  
         @Override
 260  
         public Long getVersionNumber() {
 261  4
             return versionNumber;
 262  
         }
 263  
 
 264  
         public void setVersionNumber(Long versionNumber) {
 265  6
             this.versionNumber = versionNumber;
 266  6
         }
 267  
 
 268  
         @Override
 269  
         public County build() {
 270  3
             return new County(this);
 271  
         }
 272  
     }
 273  
 
 274  
     /**
 275  
      * Defines some internal constants used on this class.
 276  
      */
 277  0
     static class Constants {
 278  
         final static String ROOT_ELEMENT_NAME = "county";
 279  
         final static String TYPE_NAME = "CountyType";
 280  
     }
 281  
 
 282  
     /**
 283  
      * A private class which exposes constants which define the XML element names to use
 284  
      * when this object is marshalled to XML.
 285  
      */
 286  0
     static class Elements {
 287  
         final static String CODE = "code";
 288  
         final static String NAME = "name";
 289  
         final static String COUNTRY_CODE = "countryCode";
 290  
         final static String STATE_CODE = "stateCode";
 291  
         final static String ACTIVE = "active";
 292  
     }
 293  
 }