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