001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.fkmapping.ejb;
023:
024: /**
025: * Primary key for Department.
026: */
027: public class DepartmentPK extends Object implements
028: java.io.Serializable {
029: private int _hashCode = 0;
030: private StringBuffer _toStringValue = null;
031:
032: public String departmentCode;
033: public String departmentCode2;
034:
035: public DepartmentPK() {
036: }
037:
038: public DepartmentPK(String departmentCode, String departmentCode2) {
039: this .departmentCode = departmentCode;
040: this .departmentCode2 = departmentCode2;
041: }
042:
043: public String getDepartmentCode() {
044: return departmentCode;
045: }
046:
047: public String getDepartmentCode2() {
048: return departmentCode2;
049: }
050:
051: public void setDepartmentCode(String departmentCode) {
052: this .departmentCode = departmentCode;
053: _hashCode = 0;
054: }
055:
056: public void setDepartmentCode2(String departmentCode2) {
057: this .departmentCode2 = departmentCode2;
058: _hashCode = 0;
059: }
060:
061: public int hashCode() {
062: if (_hashCode == 0) {
063: if (this .departmentCode != null)
064: _hashCode += this .departmentCode.hashCode();
065: if (this .departmentCode2 != null)
066: _hashCode += this .departmentCode2.hashCode();
067: }
068:
069: return _hashCode;
070: }
071:
072: public boolean equals(Object obj) {
073: if (!(obj instanceof DepartmentPK))
074: return false;
075:
076: DepartmentPK pk = (DepartmentPK) obj;
077: boolean eq = true;
078:
079: if (obj == null) {
080: eq = false;
081: } else {
082: if (this .departmentCode == null
083: && ((DepartmentPK) obj).getDepartmentCode() == null) {
084: eq = true;
085: } else {
086: if (this .departmentCode == null
087: || ((DepartmentPK) obj).getDepartmentCode() == null) {
088: eq = false;
089: } else {
090: eq = eq
091: && this .departmentCode
092: .equals(pk.departmentCode);
093: }
094: }
095: if (this .departmentCode2 == null
096: && ((DepartmentPK) obj).getDepartmentCode2() == null) {
097: eq = true;
098: } else {
099: if (this .departmentCode2 == null
100: || ((DepartmentPK) obj).getDepartmentCode2() == null) {
101: eq = false;
102: } else {
103: eq = eq
104: && this .departmentCode2
105: .equals(pk.departmentCode2);
106: }
107: }
108: }
109:
110: return eq;
111: }
112:
113: /** @return String representation of this pk in the form of [.field1.field2.field3]. */
114: public String toString() {
115: if (_toStringValue == null) {
116: _toStringValue = new StringBuffer("[.");
117: _toStringValue.append(this .departmentCode).append('.');
118: _toStringValue.append(this .departmentCode2).append('.');
119: _toStringValue.append(']');
120: }
121:
122: return _toStringValue.toString();
123: }
124:
125: }
|