Coverage Report - org.kuali.rice.krad.bo.KualiCodeBase
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiCodeBase
0%
0/28
0%
0/8
1.583
 
 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.krad.bo;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.hibernate.annotations.Type;
 20  
 
 21  
 import javax.persistence.Column;
 22  
 import javax.persistence.Id;
 23  
 import javax.persistence.MappedSuperclass;
 24  
 
 25  
 @MappedSuperclass
 26  
 public class KualiCodeBase extends PersistableBusinessObjectBase implements KualiCode {
 27  
 
 28  
     private static final long serialVersionUID = 1194744068788100482L;
 29  
         // Code and Name will be overridden by Column annotations in their children classes
 30  
     @Id
 31  
     @Column(name="CODE")
 32  
     protected String code;
 33  
     @Column(name="NM")
 34  
     protected String name;
 35  
     @Type(type="yes_no")
 36  
     @Column(name="ACTV_IND")
 37  
     protected boolean active;
 38  
 
 39  0
     public KualiCodeBase() {
 40  0
         this.active = true;
 41  0
     }
 42  
 
 43  
     public KualiCodeBase(String code) {
 44  0
         this();
 45  0
         this.code = code;
 46  0
     }
 47  
 
 48  
     /**
 49  
      * @return Getter for the Code.
 50  
      */
 51  
     public String getCode() {
 52  0
         return code;
 53  
     }
 54  
 
 55  
     /**
 56  
      * @param code - Setter for the Code.
 57  
      */
 58  
     public void setCode(String code) {
 59  0
         this.code = code;
 60  0
     }
 61  
 
 62  
 
 63  
     /**
 64  
      * @return Getter for the Name.
 65  
      */
 66  
     public String getName() {
 67  0
         return name;
 68  
     }
 69  
 
 70  
 
 71  
     /**
 72  
      * @param name - Setter for the name.
 73  
      */
 74  
     public void setName(String name) {
 75  0
         this.name = name;
 76  0
     }
 77  
 
 78  
 
 79  
     /**
 80  
      * @return Getter for the active field.
 81  
      */
 82  
     public boolean isActive() {
 83  0
         return active;
 84  
     }
 85  
 
 86  
 
 87  
     /**
 88  
      * @param name - Setter for the active field.
 89  
      */
 90  
     public void setActive(boolean a) {
 91  0
         this.active = a;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * @return Returns the code and description in format: xx - xxxxxxxxxxxxxxxx
 96  
      */
 97  
     public String getCodeAndDescription() { 
 98  0
             return KualiCodeBase.getCodeAndDescription(getCode(), getName()); 
 99  
     } 
 100  
 
 101  
     /**
 102  
      * Static helper method to allow other classes to provide consistent "code and description"
 103  
      * behavior, even if not extending from this class.
 104  
      */
 105  
         public static String getCodeAndDescription(String code, String desc) {
 106  0
                 if (code != null) {
 107  0
                         if (desc == null) {
 108  0
                                 return code;
 109  
                         } else {
 110  0
                                 return code + " - " + desc;
 111  
                         }
 112  
                 }
 113  0
                 return "";
 114  
         }
 115  
 
 116  
     /**
 117  
      * Implements equals comparing code to code.
 118  
      * 
 119  
      * @see java.lang.Object#equals(java.lang.Object)
 120  
      */
 121  
     public boolean equals(Object obj) {
 122  0
         if (obj instanceof KualiCodeBase) {
 123  0
             return StringUtils.equals(this.getCode(), ((KualiCodeBase) obj).getCode());
 124  
         }
 125  0
         return false;
 126  
     }
 127  
 
 128  
     /**
 129  
      * Overriding equals requires writing a hashCode method.
 130  
      * 
 131  
      * @see java.lang.Object#hashCode()
 132  
      */
 133  
     public int hashCode() {
 134  0
         int hashCode = 0;
 135  
 
 136  0
         if (getCode() != null) {
 137  0
             hashCode = getCode().hashCode();
 138  
         }
 139  
 
 140  0
         return hashCode;
 141  
     }
 142  
 }