001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.bo;
017:
018: import java.util.LinkedHashMap;
019:
020: import org.apache.commons.lang.StringUtils;
021:
022: /**
023: *
024: */
025: public class KualiCodeBase extends PersistableBusinessObjectBase
026: implements KualiCode {
027:
028: protected String code;
029: protected String name;
030: protected boolean active;
031:
032: public KualiCodeBase() {
033: this .active = true;
034: }
035:
036: public KualiCodeBase(String code) {
037: this ();
038: this .code = code;
039: }
040:
041: /**
042: * @return Getter for the Code.
043: */
044: public String getCode() {
045: return code;
046: }
047:
048: /**
049: * @param code - Setter for the Code.
050: */
051: public void setCode(String code) {
052: this .code = code;
053: }
054:
055: /**
056: * @return Getter for the Name.
057: */
058: public String getName() {
059: return name;
060: }
061:
062: /**
063: * @param name - Setter for the name.
064: */
065: public void setName(String name) {
066: this .name = name;
067: }
068:
069: /**
070: * @return Getter for the active field.
071: */
072: public boolean isActive() {
073: return active;
074: }
075:
076: /**
077: * @param name - Setter for the active field.
078: */
079: public void setActive(boolean a) {
080: this .active = a;
081: }
082:
083: /**
084: * @return Returns the code and description in format: xx - xxxxxxxxxxxxxxxx
085: */
086: public String getCodeAndDescription() {
087: String theString = getCode() + " - " + getName();
088: return theString;
089: }
090:
091: /**
092: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
093: */
094: final protected LinkedHashMap toStringMapper() {
095: LinkedHashMap m = new LinkedHashMap();
096:
097: m.put("code", getCode());
098: m.put("name", getName());
099:
100: return m;
101: }
102:
103: /**
104: * Implements equals comparing code to code.
105: *
106: * @see java.lang.Object#equals(java.lang.Object)
107: */
108: public boolean equals(Object obj) {
109: if (obj instanceof KualiCodeBase) {
110: return StringUtils.equals(this .getCode(),
111: ((KualiCodeBase) obj).getCode());
112: }
113: return false;
114: }
115:
116: /**
117: * Overriding equals requires writing a hashCode method.
118: *
119: * @see java.lang.Object#hashCode()
120: */
121: public int hashCode() {
122: int hashCode = 0;
123:
124: if (getCode() != null) {
125: hashCode = getCode().hashCode();
126: }
127:
128: return hashCode;
129: }
130:
131: }
|