Coverage Report - org.kuali.rice.location.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$Cache
0%
0/1
N/A
1.333
County$Constants
0%
0/1
N/A
1.333
County$Elements
0%
0/1
N/A
1.333
 
 1  
 /**
 2  
  * Copyright 2005-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  
 package org.kuali.rice.location.api.county;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.CoreConstants;
 20  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 21  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 22  
 import org.kuali.rice.location.api.LocationConstants;
 23  
 import org.w3c.dom.Element;
 24  
 
 25  
 import javax.xml.bind.annotation.XmlAccessType;
 26  
 import javax.xml.bind.annotation.XmlAccessorType;
 27  
 import javax.xml.bind.annotation.XmlAnyElement;
 28  
 import javax.xml.bind.annotation.XmlElement;
 29  
 import javax.xml.bind.annotation.XmlRootElement;
 30  
 import javax.xml.bind.annotation.XmlType;
 31  
 import java.io.Serializable;
 32  
 import java.util.Collection;
 33  
 
 34  
 /**
 35  
  * An immutable representation of a {@link CountyContract}.
 36  
  *
 37  
  * <p>To construct an instance of a County, use the {@link County.Builder} class.
 38  
  *
 39  
  * @see CountyContract
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
     /** {@inheritDoc} */
 102  
     @Override
 103  
     public String getCode() {
 104  0
         return code;
 105  
     }
 106  
 
 107  
     /** {@inheritDoc} */
 108  
     @Override
 109  
     public String getName() {
 110  0
         return name;
 111  
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     @Override
 115  
     public String getCountryCode() {
 116  0
         return countryCode;
 117  
     }
 118  
 
 119  
     /** {@inheritDoc} */
 120  
     @Override
 121  
     public String getStateCode() {
 122  0
         return stateCode;
 123  
     }
 124  
 
 125  
     /** {@inheritDoc} */
 126  
     @Override
 127  
     public boolean isActive() {
 128  0
         return active;
 129  
     }
 130  
 
 131  
     /** {@inheritDoc} */
 132  
     @Override
 133  
     public Long getVersionNumber() {
 134  0
         return versionNumber;
 135  
     }
 136  
 
 137  
     /**
 138  
      * This builder constructs an County enforcing the constraints of the {@link CountyContract}.
 139  
      */
 140  3
     public static class Builder implements CountyContract, ModelBuilder, Serializable {
 141  
 
 142  
         private static final long serialVersionUID = 7077484401017765844L;
 143  
 
 144  
         private String code;
 145  
         private String name;
 146  
         private String countryCode;
 147  
         private String stateCode;
 148  
         private boolean active;
 149  
         private Long versionNumber;
 150  
 
 151  17
         private Builder(String code, String name, String countryCode, String stateCode) {
 152  17
             setCode(code);
 153  13
             setName(name);
 154  10
             setCountryCode(countryCode);
 155  7
             setStateCode(stateCode);
 156  4
             setVersionNumber(versionNumber);
 157  4
         }
 158  
 
 159  
         /**
 160  
          * creates a County Builder with the required fields.
 161  
          */
 162  
         public static Builder create(String code, String name, String countryCode, String stateCode) {
 163  15
             final Builder builder = new Builder(code, name, countryCode, stateCode);
 164  2
             builder.setActive(true);
 165  2
             return builder;
 166  
         }
 167  
 
 168  
         /**
 169  
          * creates a County Builder from an existing {@link CountyContract}.
 170  
          */
 171  
         public static Builder create(CountyContract contract) {
 172  2
             final Builder builder = new Builder(contract.getCode(), contract.getName(), contract.getCountryCode(), contract.getStateCode());
 173  2
             builder.setActive(contract.isActive());
 174  2
             builder.setVersionNumber(contract.getVersionNumber());
 175  2
             return builder;
 176  
         }
 177  
 
 178  
         @Override
 179  
         public String getCode() {
 180  4
             return code;
 181  
         }
 182  
 
 183  
         /**
 184  
          * Sets the code to be used for the County created from this Builder.
 185  
          * @param code String code for a County
 186  
          * @throws IllegalArgumentException if the passed in code is null or a blank String.
 187  
          */
 188  
         public void setCode(String code) {
 189  17
             if (StringUtils.isBlank(code)) {
 190  4
                 throw new IllegalArgumentException("code is blank");
 191  
             }
 192  
 
 193  13
             this.code = code;
 194  13
         }
 195  
 
 196  
         @Override
 197  
         public String getName() {
 198  4
             return name;
 199  
         }
 200  
 
 201  
         /**
 202  
          * Sets the full name of the County created from this Builder.
 203  
          * @param name String representing the full name for the County
 204  
          * @throws IllegalArgumentException if the passed in name is null or a blank String.
 205  
          */
 206  
         public void setName(String name) {
 207  13
             if (StringUtils.isBlank(name)) {
 208  3
                 throw new IllegalArgumentException("name is blank");
 209  
             }
 210  
 
 211  10
             this.name = name;
 212  10
         }
 213  
 
 214  
         @Override
 215  
         public String getCountryCode() {
 216  4
             return countryCode;
 217  
         }
 218  
 
 219  
         /**
 220  
          * Sets the Country code to be associated with the County created from this Builder.
 221  
          * @param countryCode String representing the Country Code
 222  
          * @throws IllegalArgumentException if the passed in countryCode is null or a blank String.
 223  
          * @see org.kuali.rice.location.api.country.CountryContract
 224  
          */
 225  
         public void setCountryCode(String countryCode) {
 226  10
             if (StringUtils.isBlank(countryCode)) {
 227  3
                 throw new IllegalArgumentException("countryCode is blank");
 228  
             }
 229  
 
 230  7
             this.countryCode = countryCode;
 231  7
         }
 232  
 
 233  
         @Override
 234  
         public String getStateCode() {
 235  4
             return stateCode;
 236  
         }
 237  
 
 238  
         /**
 239  
          * Sets the State code to be associated with the County created from this Builder.
 240  
          * @param stateCode String representing the State code
 241  
          * @throws  IllegalArgumentException if the passed in statecode is null or a blank String.
 242  
          * @see org.kuali.rice.location.api.state.StateContract
 243  
          */
 244  
         public void setStateCode(String stateCode) {
 245  7
             if (StringUtils.isBlank(stateCode)) {
 246  3
                 throw new IllegalArgumentException("stateCode is blank");
 247  
             }
 248  
 
 249  4
             this.stateCode = stateCode;
 250  4
         }
 251  
 
 252  
         @Override
 253  
         public boolean isActive() {
 254  4
             return active;
 255  
         }
 256  
 
 257  
         /**
 258  
          * Sets the active flag for the County created from this Builder.
 259  
          * @param active
 260  
          */
 261  
         public void setActive(boolean active) {
 262  4
             this.active = active;
 263  4
         }
 264  
 
 265  
         @Override
 266  
         public Long getVersionNumber() {
 267  4
             return versionNumber;
 268  
         }
 269  
 
 270  
         public void setVersionNumber(Long versionNumber) {
 271  6
             this.versionNumber = versionNumber;
 272  6
         }
 273  
 
 274  
         @Override
 275  
         public County build() {
 276  3
             return new County(this);
 277  
         }
 278  
     }
 279  
 
 280  
     /**
 281  
      * Defines some internal constants used on this class.
 282  
      */
 283  0
     static class Constants {
 284  
         final static String ROOT_ELEMENT_NAME = "county";
 285  
         final static String TYPE_NAME = "CountyType";
 286  
     }
 287  
 
 288  
     /**
 289  
      * A private class which exposes constants which define the XML element names to use
 290  
      * when this object is marshalled to XML.
 291  
      */
 292  0
     static class Elements {
 293  
         final static String CODE = "code";
 294  
         final static String NAME = "name";
 295  
         final static String COUNTRY_CODE = "countryCode";
 296  
         final static String STATE_CODE = "stateCode";
 297  
         final static String ACTIVE = "active";
 298  
     }
 299  
 
 300  0
     public static class Cache {
 301  
         public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + County.Constants.TYPE_NAME;
 302  
     }
 303  
 }