Coverage Report - org.kuali.rice.shareddata.api.country.Country
 
Classes in this File Line Coverage Branch Coverage Complexity
Country
87%
21/24
N/A
1.08
Country$1
N/A
N/A
1.08
Country$Builder
100%
34/34
100%
2/2
1.08
Country$Constants
0%
0/1
N/A
1.08
Country$Elements
0%
0/1
N/A
1.08
 
 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.country;
 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  
  * POJO implementation of CountryContract that is immutable. Instances of Country can be (un)marshalled to and from XML.
 37  
  *
 38  
  * @see CountryContract
 39  
  */
 40  
 @XmlRootElement(name = Country.Constants.ROOT_ELEMENT_NAME)
 41  
 @XmlAccessorType(XmlAccessType.NONE)
 42  
 @XmlType(name = Country.Constants.TYPE_NAME, propOrder = {
 43  
         Country.Elements.CODE,
 44  
         Country.Elements.ALTERNATE_CODE,
 45  
         Country.Elements.NAME,
 46  
         Country.Elements.RESTRICTED,
 47  
         Country.Elements.ACTIVE,
 48  
         CoreConstants.CommonElements.VERSION_NUMBER,
 49  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 50  
 })
 51  5
 public final class Country extends AbstractDataTransferObject implements CountryContract {
 52  
     private static final long serialVersionUID = -8975392777320033940L;
 53  
 
 54  
     @XmlElement(name = Elements.CODE, required = true)
 55  
     private final String code;
 56  
 
 57  
     @XmlElement(name = Elements.ALTERNATE_CODE, required = false)
 58  
     private final String alternateCode;
 59  
 
 60  
     @XmlElement(name = Elements.NAME, required = false)
 61  
     private final String name;
 62  
 
 63  
     @XmlElement(name = Elements.RESTRICTED, required = true)
 64  
     private final boolean restricted;
 65  
 
 66  
     @XmlElement(name = Elements.ACTIVE, required = true)
 67  
     private final boolean active;
 68  
 
 69  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 70  
     private final Long versionNumber;
 71  
 
 72  8
     @SuppressWarnings("unused")
 73  
     @XmlAnyElement
 74  
     private final Collection<Element> _futureElements = null;
 75  
 
 76  
     /**
 77  
      * This constructor should never be called except during JAXB unmarshalling.
 78  
      */
 79  
     @SuppressWarnings("unused")
 80  3
     private Country() {
 81  3
         this.code = null;
 82  3
         this.alternateCode = null;
 83  3
         this.name = null;
 84  3
         this.restricted = false;
 85  3
         this.active = false;
 86  3
         this.versionNumber = null;
 87  3
     }
 88  
 
 89  5
     private Country(Builder builder) {
 90  5
         this.code = builder.getCode();
 91  5
         this.alternateCode = builder.getAlternateCode();
 92  5
         this.name = builder.getName();
 93  5
         this.restricted = builder.isRestricted();
 94  5
         this.active = builder.isActive();
 95  5
         this.versionNumber = builder.getVersionNumber();
 96  5
     }
 97  
 
 98  
     @Override
 99  
     public String getCode() {
 100  1
         return this.code;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public String getAlternateCode() {
 105  1
         return this.alternateCode;
 106  
     }
 107  
 
 108  
     @Override
 109  
     public String getName() {
 110  1
         return this.name;
 111  
     }
 112  
 
 113  
     @Override
 114  
     public boolean isActive() {
 115  0
         return this.active;
 116  
     }
 117  
 
 118  
     @Override
 119  
     public boolean isRestricted() {
 120  0
         return this.restricted;
 121  
     }
 122  
 
 123  
     @Override
 124  
     public Long getVersionNumber() {
 125  0
         return this.versionNumber;
 126  
     }
 127  
 
 128  
     /**
 129  
      * Builder for immutable Country objects.
 130  
      */
 131  5
     public static class Builder implements CountryContract, ModelBuilder, Serializable {
 132  
         private static final long serialVersionUID = -4786917485397379322L;
 133  
 
 134  
         private String code;
 135  
         private String alternateCode;
 136  
         private String name;
 137  
         private boolean restricted;
 138  
         private boolean active;
 139  
         private Long versionNumber;
 140  
 
 141  
         private Builder(String code, String alternateCode, String name,
 142  9
                         boolean restricted, boolean active) {
 143  9
             this.setCode(code);
 144  7
             this.setAlternateCode(alternateCode);
 145  7
             this.setName(name);
 146  7
             this.setRestricted(restricted);
 147  7
             this.setActive(active);
 148  7
         }
 149  
 
 150  
         public static Builder create(String code, String name) {
 151  1
             return new Builder(code, null, name, false, true);
 152  
         }
 153  
 
 154  
         public static Builder create(String code, String alternatePostalCode, String name,
 155  
                                      boolean restricted, boolean active) {
 156  5
             return new Builder(code, alternatePostalCode, name, restricted, active);
 157  
         }
 158  
 
 159  
         public static Builder create(CountryContract cc) {
 160  3
             Builder builder = new Builder(cc.getCode(), cc.getAlternateCode(),
 161  
                     cc.getName(), cc.isRestricted(), cc.isActive());
 162  3
             builder.setVersionNumber(cc.getVersionNumber());
 163  3
             return builder;
 164  
         }
 165  
 
 166  
         @Override
 167  
         public Country build() {
 168  5
             return new Country(this);
 169  
         }
 170  
 
 171  
         /**
 172  
          * Sets code property.
 173  
          *
 174  
          * @param code required to be not null and not empty.
 175  
          */
 176  
         public void setCode(String code) {
 177  9
             if (StringUtils.isBlank(code)) {
 178  2
                 throw new IllegalArgumentException("code cannot be blank or null");
 179  
             }
 180  7
             this.code = code;
 181  7
         }
 182  
 
 183  
         @Override
 184  
         public String getCode() {
 185  7
             return this.code;
 186  
         }
 187  
 
 188  
         /**
 189  
          * Sets the optional alternatePostalCode property
 190  
          *
 191  
          * @param alternatePostalCode
 192  
          */
 193  
         public void setAlternateCode(String alternatePostalCode) {
 194  7
             this.alternateCode = alternatePostalCode;
 195  7
         }
 196  
 
 197  
         @Override
 198  
         public String getAlternateCode() {
 199  7
             return this.alternateCode;
 200  
         }
 201  
 
 202  
         /**
 203  
          * Sets the optional name property.
 204  
          *
 205  
          * @param name
 206  
          */
 207  
         public void setName(String name) {
 208  7
             this.name = name;
 209  7
         }
 210  
 
 211  
         @Override
 212  
         public String getName() {
 213  7
             return this.name;
 214  
         }
 215  
 
 216  
         /**
 217  
          * Sets the active property.
 218  
          *
 219  
          * @param active
 220  
          */
 221  
         public void setActive(boolean active) {
 222  7
             this.active = active;
 223  7
         }
 224  
 
 225  
         @Override
 226  
         public boolean isActive() {
 227  7
             return this.active;
 228  
         }
 229  
 
 230  
         /**
 231  
          * Sets the versionNumber property.
 232  
          *
 233  
          * @param versionNumber
 234  
          */
 235  
         public void setVersionNumber(Long versionNumber) {
 236  4
             this.versionNumber = versionNumber;
 237  4
         }
 238  
 
 239  
         @Override
 240  
         public Long getVersionNumber() {
 241  7
             return this.versionNumber;
 242  
         }
 243  
 
 244  
         /**
 245  
          * Sets the restrictedProperty
 246  
          *
 247  
          * @param restricted
 248  
          */
 249  
         public void setRestricted(boolean restricted) {
 250  7
             this.restricted = restricted;
 251  7
         }
 252  
 
 253  
         @Override
 254  
         public boolean isRestricted() {
 255  7
             return this.restricted;
 256  
         }
 257  
     }
 258  
 
 259  
     /**
 260  
      * A private class which exposes constants which define the XML element names to use
 261  
      * when this object is marshalled to XML.
 262  
      */
 263  0
     static class Elements {
 264  
         final static String CODE = "code";
 265  
         final static String ALTERNATE_CODE = "alternateCode";
 266  
         final static String NAME = "name";
 267  
         final static String RESTRICTED = "restricted";
 268  
         final static String ACTIVE = "active";
 269  
     }
 270  
 
 271  
     /**
 272  
      * Defines some internal constants used on this class.
 273  
      */
 274  0
     static class Constants {
 275  
         final static String ROOT_ELEMENT_NAME = "country";
 276  
         final static String TYPE_NAME = "CountryType";
 277  
     }
 278  
 }