1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.bo;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
20
21 import javax.persistence.Column;
22 import javax.persistence.Convert;
23 import javax.persistence.Embeddable;
24 import javax.persistence.Id;
25 import javax.persistence.MappedSuperclass;
26
27 @MappedSuperclass
28 public class KualiCodeBase extends PersistableBusinessObjectBase implements KualiCode {
29
30 private static final long serialVersionUID = 1194744068788100482L;
31
32
33
34
35
36 @Embeddable
37 private static final class WeaveMe extends KualiCodeBase {}
38
39
40 @Id
41 @Column(name = "CODE", length=10)
42 protected String code;
43 @Column(name = "NM", length=40)
44 protected String name;
45
46 @Column(name = "ACTV_IND")
47 @Convert(converter = BooleanYNConverter.class)
48 protected Boolean active;
49
50 public KualiCodeBase() {
51 this.active = true;
52 }
53
54 public KualiCodeBase(String code) {
55 this();
56 this.code = code;
57 }
58
59
60
61
62 @Override
63 public String getCode() {
64 return code;
65 }
66
67
68
69
70 @Override
71 public void setCode(String code) {
72 this.code = code;
73 }
74
75
76
77
78
79 @Override
80 public String getName() {
81 return name;
82 }
83
84
85
86
87
88 @Override
89 public void setName(String name) {
90 this.name = name;
91 }
92
93
94
95
96
97 @Override
98 public boolean isActive() {
99 return active;
100 }
101
102
103
104
105
106 @Override
107 public void setActive(boolean a) {
108 this.active = a;
109 }
110
111
112
113
114 public String getCodeAndDescription() {
115 return KualiCodeBase.getCodeAndDescription(getCode(), getName());
116 }
117
118
119
120
121
122 public static String getCodeAndDescription(String code, String desc) {
123 if (code != null) {
124 if (desc == null) {
125 return code;
126 } else {
127 return code + " - " + desc;
128 }
129 }
130 return "";
131 }
132
133
134
135
136
137
138 @Override
139 public boolean equals(Object obj) {
140 if (obj instanceof KualiCodeBase) {
141 return StringUtils.equals(this.getCode(), ((KualiCodeBase) obj).getCode());
142 }
143 return false;
144 }
145
146
147
148
149
150
151 @Override
152 public int hashCode() {
153 int hashCode = 0;
154
155 if (getCode() != null) {
156 hashCode = getCode().hashCode();
157 }
158
159 return hashCode;
160 }
161 }