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