Coverage Report - org.kuali.rice.shareddata.api.state.State
 
Classes in this File Line Coverage Branch Coverage Complexity
State
70%
17/24
N/A
1.25
State$1
N/A
N/A
1.25
State$Builder
100%
35/35
100%
6/6
1.25
State$Constants
50%
1/2
N/A
1.25
State$Elements
0%
0/1
N/A
1.25
 
 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.state;
 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  
  * POJO implementation of CountryContract that is immutable. Instances of State can be (un)marshalled to and from XML.
 39  
  *
 40  
  * @see StateContract
 41  
  */
 42  
 @XmlRootElement(name = State.Constants.ROOT_ELEMENT_NAME)
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = State.Constants.TYPE_NAME, propOrder = {
 45  
         State.Elements.CODE,
 46  
         State.Elements.NAME,
 47  
         State.Elements.COUNTRY_CODE,
 48  
         State.Elements.ACTIVE,
 49  
         CoreConstants.CommonElements.VERSION_NUMBER,
 50  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 51  
 })
 52  
 
 53  3
 public final class State implements StateContract, ModelObjectComplete {
 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.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  5
     @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  2
     private State() {
 81  2
         this.code = null;
 82  2
         this.name = null;
 83  2
         this.countryCode = null;
 84  2
         this.active = false;
 85  2
         this.versionNumber = null;
 86  2
     }
 87  
 
 88  3
     private State(Builder builder) {
 89  3
         code = builder.getCode();
 90  3
         name = builder.getName();
 91  3
         countryCode = builder.getCountryCode();
 92  3
         active = builder.isActive();
 93  3
         versionNumber = builder.getVersionNumber();
 94  3
     }
 95  
 
 96  
     @Override
 97  
     public String getCode() {
 98  0
         return code;
 99  
     }
 100  
 
 101  
     @Override
 102  
     public String getName() {
 103  0
         return name;
 104  
     }
 105  
 
 106  
     @Override
 107  
     public String getCountryCode() {
 108  0
         return countryCode;
 109  
     }
 110  
 
 111  
     @Override
 112  
     public boolean isActive() {
 113  0
         return active;
 114  
     }
 115  
 
 116  
     @Override
 117  
     public Long getVersionNumber() {
 118  0
         return versionNumber;
 119  
     }
 120  
 
 121  
     /**
 122  
      * This builder constructs a State enforcing the constraints of the {@link StateContract}.
 123  
      */
 124  3
     public static class Builder implements StateContract, ModelBuilder, Serializable {
 125  
 
 126  
         private static final long serialVersionUID = 7077484401017765844L;
 127  
 
 128  
         private String code;
 129  
 
 130  
         private String name;
 131  
 
 132  
         private String countryCode;
 133  
 
 134  
         private boolean active;
 135  
 
 136  
         private Long versionNumber;
 137  
 
 138  14
         private Builder(String code, String name, String countryCode) {
 139  14
             setCode(code);
 140  10
             setName(name);
 141  7
             setCountryCode(countryCode);
 142  4
         }
 143  
 
 144  
         /**
 145  
          * creates a State with the required fields.
 146  
          * @param code represents code for the State being built
 147  
          * @param name represents full name for the State being built
 148  
          * @param countryCode code for the Country this State is associated with
 149  
          * @return a bootstrapped Builder defaulted with the passed in code, name, and countryCode.
 150  
          */
 151  
         public static Builder create(String code, String name, String countryCode) {
 152  12
             final Builder builder = new Builder(code, name, countryCode);
 153  2
             builder.setActive(true);
 154  2
             return builder;
 155  
         }
 156  
 
 157  
         /**
 158  
          * creates a Parameter from an existing {@link StateContract}.
 159  
          */
 160  
         public static Builder create(StateContract contract) {
 161  2
             final Builder builder = new Builder(contract.getCode(), contract.getName(), contract.getCountryCode());
 162  2
             builder.setActive(contract.isActive());
 163  2
             builder.setVersionNumber(contract.getVersionNumber());
 164  2
             return builder;
 165  
         }
 166  
 
 167  
         @Override
 168  
         public String getCode() {
 169  4
             return code;
 170  
         }
 171  
 
 172  
         /**
 173  
          * Sets the code to be used for the State created from this Builder.
 174  
          * @param code String code for a State.
 175  
          * @throws IllegalArgumentException if the passed in code is null or a blank String.
 176  
          */
 177  
         public void setCode(String code) {
 178  14
             if (StringUtils.isBlank(code)) {
 179  4
                 throw new IllegalArgumentException("code is blank");
 180  
             }
 181  
 
 182  10
             this.code = code;
 183  10
         }
 184  
 
 185  
         @Override
 186  
         public String getName() {
 187  4
             return name;
 188  
         }
 189  
 
 190  
         /**
 191  
          * Sets the full name of the State created from this Builder.
 192  
          * @param name String representing the full name for the State
 193  
          * @throws IllegalArgumentException if the passed in name is null or a blank String.
 194  
          */
 195  
         public void setName(String name) {
 196  10
             if (StringUtils.isBlank(name)) {
 197  3
                 throw new IllegalArgumentException("name is blank");
 198  
             }
 199  
 
 200  7
             this.name = name;
 201  7
         }
 202  
 
 203  
         @Override
 204  
         public String getCountryCode() {
 205  4
             return countryCode;
 206  
         }
 207  
 
 208  
         /**
 209  
          * Sets the Country code to be associated with the State created from this Builder.
 210  
          * @param countryCode String representing the Country Code
 211  
          * @throws IllegalArgumentException if the passed in countryCode is null or a blank String.
 212  
          */
 213  
         public void setCountryCode(String countryCode) {
 214  7
             if (StringUtils.isBlank(countryCode)) {
 215  3
                 throw new IllegalArgumentException("countryCode is blank");
 216  
             }
 217  
 
 218  4
             this.countryCode = countryCode;
 219  4
         }
 220  
 
 221  
         @Override
 222  
         public boolean isActive() {
 223  4
             return active;
 224  
         }
 225  
 
 226  
         public void setActive(boolean active) {
 227  4
             this.active = active;
 228  4
         }
 229  
 
 230  
         @Override
 231  
         public Long getVersionNumber() {
 232  4
             return versionNumber;
 233  
         }
 234  
 
 235  
         public void setVersionNumber(Long versionNumber) {
 236  2
             this.versionNumber = versionNumber;
 237  2
         }
 238  
 
 239  
         @Override
 240  
         public State build() {
 241  3
             return new State(this);
 242  
         }
 243  
     }
 244  
 
 245  
     @Override
 246  
     public int hashCode() {
 247  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 248  
     }
 249  
 
 250  
     @Override
 251  
     public boolean equals(Object obj) {
 252  1
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 253  
     }
 254  
 
 255  
     @Override
 256  
     public String toString() {
 257  0
         return ToStringBuilder.reflectionToString(this);
 258  
     }
 259  
 
 260  
     /**
 261  
      * Defines some internal constants used on this class.
 262  
      */
 263  0
     static class Constants {
 264  
         final static String ROOT_ELEMENT_NAME = "state";
 265  
         final static String TYPE_NAME = "StateType";
 266  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 267  
     }
 268  
 
 269  
     /**
 270  
      * A private class which exposes constants which define the XML element names to use
 271  
      * when this object is marshalled to XML.
 272  
      */
 273  0
     static class Elements {
 274  
         final static String CODE = "code";
 275  
         final static String NAME = "name";
 276  
         final static String COUNTRY_CODE = "countryCode";
 277  
         final static String ACTIVE = "active";
 278  
     }
 279  
 
 280  
 }