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